OLD | NEW |
1 dart_library.library('unittest/unittest', null, /* Imports */[ | 1 dart_library.library('unittest', null, /* Imports */[ |
2 'dart/_runtime', | 2 'dart_sdk', |
3 'matcher/matcher', | 3 'matcher' |
4 'dom/dom', | 4 ], function(exports, dart_sdk, matcher) { |
5 'dart/core', | |
6 'dart/async', | |
7 'matcher/src/interfaces', | |
8 'matcher/src/util', | |
9 'matcher/src/description' | |
10 ], /* Lazy imports */[ | |
11 ], function(exports, dart, matcher, dom, core, async, interfaces, util, descript
ion$) { | |
12 'use strict'; | 5 'use strict'; |
13 let dartx = dart.dartx; | 6 const core = dart_sdk.core; |
14 dart.export(exports, matcher); | 7 const js = dart_sdk.js; |
15 function group(name, body) { | 8 const async = dart_sdk.async; |
16 return dart.dsend(dom.window, 'suite', name, body); | 9 const dart = dart_sdk.dart; |
17 } | 10 const dartx = dart_sdk.dartx; |
18 dart.fn(group, dart.void, [core.String, dart.functionType(dart.void, [])]); | 11 const interfaces = matcher.interfaces; |
19 function test(name, body, opts) { | 12 const util = matcher.util; |
| 13 const description$ = matcher.description; |
| 14 const numeric_matchers = matcher.numeric_matchers; |
| 15 const error_matchers = matcher.error_matchers; |
| 16 const core_matchers = matcher.core_matchers; |
| 17 const iterable_matchers = matcher.iterable_matchers; |
| 18 const string_matchers = matcher.string_matchers; |
| 19 const operator_matchers = matcher.operator_matchers; |
| 20 const map_matchers = matcher.map_matchers; |
| 21 const unittest = Object.create(null); |
| 22 unittest.group = function(name, body) { |
| 23 return js.context.callMethod('suite', dart.list([name, body], core.Object)); |
| 24 }; |
| 25 dart.fn(unittest.group, dart.void, [core.String, dart.functionType(dart.void,
[])]); |
| 26 unittest.test = function(name, body, opts) { |
20 let skip = opts && 'skip' in opts ? opts.skip : null; | 27 let skip = opts && 'skip' in opts ? opts.skip : null; |
21 if (skip != null) { | 28 if (skip != null) { |
22 core.print(`SKIP ${name}: ${skip}`); | 29 core.print(`SKIP ${name}: ${skip}`); |
23 return; | 30 return; |
24 } | 31 } |
25 dart.dsend(dom.window, 'test', name, dart.fn(done => { | 32 let result = dart.as(js.context.callMethod('test', dart.list([name, dart.fn(
done => { |
26 function _finishTest(f) { | 33 function _finishTest(f) { |
27 if (dart.is(f, async.Future)) { | 34 if (dart.is(f, async.Future)) { |
28 f.then(_finishTest); | 35 f.then(_finishTest); |
29 } else { | 36 } else { |
30 dart.dcall(done); | 37 done.apply([]); |
| 38 } |
31 } | 39 } |
32 } | 40 dart.fn(_finishTest); |
33 dart.fn(_finishTest); | 41 _finishTest(body()); |
34 _finishTest(body()); | 42 }, dart.dynamic, [js.JsFunction])], core.Object)), js.JsObject); |
35 })); | 43 result.set('async', 1); |
36 } | 44 }; |
37 dart.fn(test, dart.void, [core.String, dart.functionType(dart.dynamic, [])], {
skip: core.String}); | 45 dart.fn(unittest.test, dart.void, [core.String, dart.functionType(dart.dynamic
, [])], {skip: core.String}); |
38 class TestFailure extends core.Object { | 46 unittest.TestFailure = class TestFailure extends core.Object { |
39 TestFailure(message) { | 47 TestFailure(message) { |
40 this.message = message; | 48 this.message = message; |
41 } | 49 } |
42 toString() { | 50 toString() { |
43 return this.message; | 51 return this.message; |
44 } | 52 } |
45 } | 53 }; |
46 dart.setSignature(TestFailure, { | 54 dart.setSignature(unittest.TestFailure, { |
47 constructors: () => ({TestFailure: [TestFailure, [core.String]]}) | 55 constructors: () => ({TestFailure: [unittest.TestFailure, [core.String]]}) |
48 }); | 56 }); |
49 const ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionType(
core.String, [dart.dynamic, interfaces.Matcher, core.String, core.Map, core.bool
])); | 57 unittest.ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionTy
pe(core.String, [dart.dynamic, interfaces.Matcher, core.String, core.Map, core.b
ool])); |
50 function expect(actual, matcher, opts) { | 58 unittest.expect = function(actual, matcher, opts) { |
51 let reason = opts && 'reason' in opts ? opts.reason : null; | 59 let reason = opts && 'reason' in opts ? opts.reason : null; |
52 let verbose = opts && 'verbose' in opts ? opts.verbose : false; | 60 let verbose = opts && 'verbose' in opts ? opts.verbose : false; |
53 let formatter = opts && 'formatter' in opts ? opts.formatter : null; | 61 let formatter = opts && 'formatter' in opts ? opts.formatter : null; |
54 matcher = util.wrapMatcher(matcher); | 62 matcher = util.wrapMatcher(matcher); |
55 let matchState = dart.map(); | 63 let matchState = dart.map(); |
56 try { | 64 try { |
57 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) return; | 65 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) return; |
58 } catch (e) { | 66 } catch (e) { |
59 let trace = dart.stackTrace(e); | 67 let trace = dart.stackTrace(e); |
60 if (reason == null) { | 68 if (reason == null) { |
61 reason = `${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`; | 69 reason = `${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`; |
62 } | 70 } |
63 } | 71 } |
64 | 72 |
65 if (formatter == null) formatter = _defaultFailFormatter; | 73 if (formatter == null) formatter = unittest._defaultFailFormatter; |
66 fail(dart.dcall(formatter, actual, matcher, reason, matchState, verbose)); | 74 unittest.fail(dart.dcall(formatter, actual, matcher, reason, matchState, ver
bose)); |
67 } | 75 }; |
68 dart.fn(expect, dart.void, [dart.dynamic, dart.dynamic], {reason: core.String,
verbose: core.bool, formatter: ErrorFormatter}); | 76 dart.fn(unittest.expect, dart.void, [dart.dynamic, dart.dynamic], {reason: cor
e.String, verbose: core.bool, formatter: unittest.ErrorFormatter}); |
69 function fail(message) { | 77 unittest.fail = function(message) { |
70 return dart.throw(new TestFailure(message)); | 78 return dart.throw(new unittest.TestFailure(message)); |
71 } | 79 }; |
72 dart.fn(fail, dart.void, [core.String]); | 80 dart.fn(unittest.fail, dart.void, [core.String]); |
73 function _defaultFailFormatter(actual, matcher, reason, matchState, verbose) { | 81 unittest._defaultFailFormatter = function(actual, matcher, reason, matchState,
verbose) { |
74 let description = new description$.StringDescription(); | 82 let description = new description$.StringDescription(); |
75 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); | 83 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); |
76 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); | 84 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); |
77 let mismatchDescription = new description$.StringDescription(); | 85 let mismatchDescription = new description$.StringDescription(); |
78 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); | 86 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); |
79 if (dart.notNull(mismatchDescription.length) > 0) { | 87 if (dart.notNull(mismatchDescription.length) > 0) { |
80 description.add(` Which: ${mismatchDescription}\n`); | 88 description.add(` Which: ${mismatchDescription}\n`); |
81 } | 89 } |
82 if (reason != null) description.add(reason).add('\n'); | 90 if (reason != null) description.add(reason).add('\n'); |
83 return description.toString(); | 91 return description.toString(); |
84 } | 92 }; |
85 dart.fn(_defaultFailFormatter, core.String, [dart.dynamic, interfaces.Matcher,
core.String, core.Map, core.bool]); | 93 dart.fn(unittest._defaultFailFormatter, core.String, [dart.dynamic, interfaces
.Matcher, core.String, core.Map, core.bool]); |
| 94 unittest.isPositive = numeric_matchers.isPositive; |
| 95 unittest.isRangeError = error_matchers.isRangeError; |
| 96 unittest.isStateError = error_matchers.isStateError; |
| 97 unittest.equals = core_matchers.equals; |
| 98 unittest.CustomMatcher = core_matchers.CustomMatcher; |
| 99 unittest.inOpenClosedRange = numeric_matchers.inOpenClosedRange; |
| 100 unittest.pairwiseCompare = iterable_matchers.pairwiseCompare; |
| 101 unittest.equalsIgnoringCase = string_matchers.equalsIgnoringCase; |
| 102 unittest.isUnimplementedError = error_matchers.isUnimplementedError; |
| 103 unittest.hasLength = core_matchers.hasLength; |
| 104 unittest.StringDescription = description$.StringDescription; |
| 105 unittest.allOf = operator_matchers.allOf; |
| 106 unittest.isNegative = numeric_matchers.isNegative; |
| 107 unittest.isInstanceOf$ = core_matchers.isInstanceOf$; |
| 108 unittest.isInstanceOf = core_matchers.isInstanceOf; |
| 109 unittest.isNaN = core_matchers.isNaN; |
| 110 unittest.lessThan = numeric_matchers.lessThan; |
| 111 unittest.isNotEmpty = core_matchers.isNotEmpty; |
| 112 unittest.greaterThanOrEqualTo = numeric_matchers.greaterThanOrEqualTo; |
| 113 unittest.endsWith = string_matchers.endsWith; |
| 114 unittest.isConcurrentModificationError = error_matchers.isConcurrentModificati
onError; |
| 115 unittest.containsValue = map_matchers.containsValue; |
| 116 unittest.isFalse = core_matchers.isFalse; |
| 117 unittest.isTrue = core_matchers.isTrue; |
| 118 unittest.Matcher = interfaces.Matcher; |
| 119 unittest.lessThanOrEqualTo = numeric_matchers.lessThanOrEqualTo; |
| 120 unittest.matches = string_matchers.matches; |
| 121 unittest.returnsNormally = core_matchers.returnsNormally; |
| 122 unittest.TypeMatcher = core_matchers.TypeMatcher; |
| 123 unittest.inExclusiveRange = numeric_matchers.inExclusiveRange; |
| 124 unittest.equalsIgnoringWhitespace = string_matchers.equalsIgnoringWhitespace; |
| 125 unittest.isIn = core_matchers.isIn; |
| 126 unittest.isNotNaN = core_matchers.isNotNaN; |
| 127 unittest.isNonZero = numeric_matchers.isNonZero; |
| 128 unittest.startsWith = string_matchers.startsWith; |
| 129 unittest.isNullThrownError = error_matchers.isNullThrownError; |
| 130 unittest.isEmpty = core_matchers.isEmpty; |
| 131 unittest.anyOf = operator_matchers.anyOf; |
| 132 unittest.unorderedMatches = iterable_matchers.unorderedMatches; |
| 133 unittest.isZero = numeric_matchers.isZero; |
| 134 unittest.isList = core_matchers.isList; |
| 135 unittest.escape = util.escape; |
| 136 unittest.isCyclicInitializationError = error_matchers.isCyclicInitializationEr
ror; |
| 137 unittest.anyElement = iterable_matchers.anyElement; |
| 138 unittest.anything = core_matchers.anything; |
| 139 unittest.contains = core_matchers.contains; |
| 140 unittest.isUnsupportedError = error_matchers.isUnsupportedError; |
| 141 unittest.isNonPositive = numeric_matchers.isNonPositive; |
| 142 unittest.isNot = operator_matchers.isNot; |
| 143 unittest.same = core_matchers.same; |
| 144 unittest.inClosedOpenRange = numeric_matchers.inClosedOpenRange; |
| 145 unittest.predicate = core_matchers.predicate; |
| 146 unittest.isNotNull = core_matchers.isNotNull; |
| 147 unittest.wrapMatcher = util.wrapMatcher; |
| 148 unittest.isNoSuchMethodError = error_matchers.isNoSuchMethodError; |
| 149 unittest.unorderedEquals = iterable_matchers.unorderedEquals; |
| 150 unittest.everyElement = iterable_matchers.everyElement; |
| 151 unittest.addStateInfo = util.addStateInfo; |
| 152 unittest.isArgumentError = error_matchers.isArgumentError; |
| 153 unittest.isException = error_matchers.isException; |
| 154 unittest.inInclusiveRange = numeric_matchers.inInclusiveRange; |
| 155 unittest.containsPair = map_matchers.containsPair; |
| 156 unittest.isFormatException = error_matchers.isFormatException; |
| 157 unittest.orderedEquals = iterable_matchers.orderedEquals; |
| 158 unittest.collapseWhitespace = string_matchers.collapseWhitespace; |
| 159 unittest.greaterThan = numeric_matchers.greaterThan; |
| 160 unittest.isNonNegative = numeric_matchers.isNonNegative; |
| 161 unittest.isNull = core_matchers.isNull; |
| 162 unittest.isMap = core_matchers.isMap; |
| 163 unittest.stringContainsInOrder = string_matchers.stringContainsInOrder; |
| 164 unittest.closeTo = numeric_matchers.closeTo; |
| 165 unittest.Description = interfaces.Description; |
86 // Exports: | 166 // Exports: |
87 exports.group = group; | 167 exports.unittest = unittest; |
88 exports.test = test; | |
89 exports.TestFailure = TestFailure; | |
90 exports.ErrorFormatter = ErrorFormatter; | |
91 exports.expect = expect; | |
92 exports.fail = fail; | |
93 }); | 168 }); |
OLD | NEW |