This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_suite_test.dart
65 lines (58 loc) · 1.9 KB
/
test_suite_test.dart
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'dart:core';
import 'dart:io';
import 'package:certlogic_dart/certlogic_dart.dart';
import 'package:test/test.dart';
import 'models.dart';
void main() {
const dirPath = '../specification/testSuite';
late final Directory dataDir;
setUp(() async {
dataDir = Directory(dirPath);
});
test('run test suite', () async {
final entries = dataDir.listSync(recursive: true).toList();
final files = entries
.where((element) => element.path.endsWith('.json'))
.map((element) => File(element.path));
final failedNames = [];
var success = 0;
for (final file in files) {
final jsonString = await file.readAsString();
final testSuite = TestSuite.fromJson(jsonString);
if (testSuite.directive == TestDirective.SKIP) continue;
testSuite.cases.forEach((testCase) {
if (testCase.directive == TestDirective.SKIP) return;
testCase.assertions.forEach((assertion) {
if (assertion.directive == TestDirective.SKIP) return;
var result;
try {
try {
result = CertLogic.evaluate(
assertion.certLogicExpression ?? testCase.certLogicExpression,
assertion.data);
} catch (e) {
if (e is CertLogicException) {
result = null;
} else {
rethrow;
}
}
expect(result, assertion.expected);
success++;
} catch (e) {
failedNames.add(
'${testCase.name} - ${assertion.message}, (${assertion.expected} != ${result})');
}
});
});
}
if (failedNames.isNotEmpty) {
print('failed: [\n${failedNames.join('\n')}\n]');
}
print('$success succeeded and ${failedNames.length} failed');
expect(failedNames.length, 0);
});
}
void printDebug(dynamic value) {
print(value); // ignore: avoid_print
}