File size: 1,553 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Validate explicit case reports without treating missing output as a failure case."""


def parse_contract_cases(stdout, expected_count, returncode):
    import json
    rows, summaries, issues = [], [], []
    try:
        for line in stdout.splitlines():
            if line.startswith('CONTRACT_CASE '):
                rows.append(json.loads(line[len('CONTRACT_CASE '):]))
            elif line.startswith('CONTRACT_SUMMARY '):
                summaries.append(json.loads(line[len('CONTRACT_SUMMARY '):]))
    except (ValueError, TypeError):
        return rows, ['Malformed native case JSON']
    ids = [r.get('id', r.get('name')) for r in rows]
    if len(rows) != expected_count or any(not x for x in ids) or len(ids) != len(set(ids)):
        issues.append('Native case inventory incomplete or duplicated')
    if any(type(r.get('passed')) is not bool for r in rows):
        issues.append('Missing boolean case outcome')
    if len(summaries) != 1:
        issues.append('Missing or duplicate native summary')
    else:
        s = summaries[0]
        if s.get('tests', s.get('total')) != expected_count or s.get('skipped', 0):
            issues.append('Native summary coverage mismatch')
        if 'passed' in s and s['passed'] != sum(r.get('passed') is True for r in rows):
            issues.append('Native summary outcome mismatch')
    expected_exit = int(any(r.get('passed') is False for r in rows))
    if returncode != expected_exit:
        issues.append('Native exit status disagrees with case outcomes')
    return rows, issues