OLD | NEW |
1 dart_library.library('unittest', null, /* Imports */[ | 1 dart_library.library('unittest', null, /* Imports */[ |
2 'dart_sdk', | 2 'dart_sdk', |
3 'matcher' | 3 'matcher' |
4 ], function(exports, dart_sdk, matcher) { | 4 ], function(exports, dart_sdk, matcher) { |
5 'use strict'; | 5 'use strict'; |
6 const core = dart_sdk.core; | 6 const core = dart_sdk.core; |
| 7 const async = dart_sdk.async; |
7 const js = dart_sdk.js; | 8 const js = dart_sdk.js; |
8 const async = dart_sdk.async; | |
9 const dart = dart_sdk.dart; | 9 const dart = dart_sdk.dart; |
10 const dartx = dart_sdk.dartx; | 10 const dartx = dart_sdk.dartx; |
| 11 const src__util = matcher.src__util; |
11 const src__interfaces = matcher.src__interfaces; | 12 const src__interfaces = matcher.src__interfaces; |
12 const src__util = matcher.src__util; | |
13 const src__description = matcher.src__description; | 13 const src__description = matcher.src__description; |
14 const src__numeric_matchers = matcher.src__numeric_matchers; | 14 const src__numeric_matchers = matcher.src__numeric_matchers; |
15 const src__error_matchers = matcher.src__error_matchers; | 15 const src__error_matchers = matcher.src__error_matchers; |
16 const src__core_matchers = matcher.src__core_matchers; | 16 const src__core_matchers = matcher.src__core_matchers; |
17 const src__iterable_matchers = matcher.src__iterable_matchers; | 17 const src__iterable_matchers = matcher.src__iterable_matchers; |
18 const src__string_matchers = matcher.src__string_matchers; | 18 const src__string_matchers = matcher.src__string_matchers; |
19 const src__operator_matchers = matcher.src__operator_matchers; | 19 const src__operator_matchers = matcher.src__operator_matchers; |
20 const src__map_matchers = matcher.src__map_matchers; | 20 const src__map_matchers = matcher.src__map_matchers; |
21 const unittest = Object.create(null); | 21 const unittest = Object.create(null); |
| 22 dart.defineLazy(unittest, { |
| 23 get _wrapAsync() { |
| 24 return dart.fn((f, id) => { |
| 25 if (id === void 0) id = null; |
| 26 return f; |
| 27 }, core.Function, [core.Function], [dart.dynamic]); |
| 28 }, |
| 29 set _wrapAsync(_) {} |
| 30 }); |
| 31 const _matcher = Symbol('_matcher'); |
| 32 unittest.Throws = class Throws extends src__interfaces.Matcher { |
| 33 Throws(matcher) { |
| 34 if (matcher === void 0) matcher = null; |
| 35 this[_matcher] = matcher; |
| 36 super.Matcher(); |
| 37 } |
| 38 matches(item, matchState) { |
| 39 if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) return
false; |
| 40 if (dart.is(item, async.Future)) { |
| 41 let done = dart.dcall(unittest._wrapAsync, dart.fn(fn => dart.dcall(fn))
); |
| 42 item.then(dart.fn(value => { |
| 43 dart.dcall(done, dart.fn(() => { |
| 44 unittest.fail(`Expected future to fail, but succeeded with '${value}
'.`); |
| 45 })); |
| 46 }), {onError: dart.fn((error, trace) => { |
| 47 dart.dcall(done, dart.fn(() => { |
| 48 if (this[_matcher] == null) return; |
| 49 let reason = null; |
| 50 if (trace != null) { |
| 51 let stackTrace = dart.toString(trace); |
| 52 stackTrace = ` ${stackTrace[dartx.replaceAll]("\n", "\n ")}`; |
| 53 reason = `Actual exception trace:\n${stackTrace}`; |
| 54 } |
| 55 unittest.expect(error, this[_matcher], {reason: dart.as(reason, co
re.String)}); |
| 56 })); |
| 57 })}); |
| 58 return true; |
| 59 } |
| 60 try { |
| 61 dart.dcall(item); |
| 62 return false; |
| 63 } catch (e) { |
| 64 let s = dart.stackTrace(e); |
| 65 if (this[_matcher] == null || dart.notNull(this[_matcher].matches(e, mat
chState))) { |
| 66 return true; |
| 67 } else { |
| 68 src__util.addStateInfo(matchState, dart.map({exception: e, stack: s}))
; |
| 69 return false; |
| 70 } |
| 71 } |
| 72 |
| 73 } |
| 74 describe(description) { |
| 75 if (this[_matcher] == null) { |
| 76 return description.add("throws"); |
| 77 } else { |
| 78 return description.add('throws ').addDescriptionOf(this[_matcher]); |
| 79 } |
| 80 } |
| 81 describeMismatch(item, mismatchDescription, matchState, verbose) { |
| 82 if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) { |
| 83 return mismatchDescription.add('is not a Function or Future'); |
| 84 } else if (this[_matcher] == null || matchState[dartx.get]('exception') ==
null) { |
| 85 return mismatchDescription.add('did not throw'); |
| 86 } else { |
| 87 mismatchDescription.add('threw ').addDescriptionOf(matchState[dartx.get]
('exception')); |
| 88 if (dart.notNull(verbose)) { |
| 89 mismatchDescription.add(' at ').add(dart.toString(matchState[dartx.get
]('stack'))); |
| 90 } |
| 91 return mismatchDescription; |
| 92 } |
| 93 } |
| 94 }; |
| 95 dart.setSignature(unittest.Throws, { |
| 96 constructors: () => ({Throws: [unittest.Throws, [], [src__interfaces.Matcher
]]}), |
| 97 methods: () => ({ |
| 98 matches: [core.bool, [dart.dynamic, core.Map]], |
| 99 describe: [src__interfaces.Description, [src__interfaces.Description]] |
| 100 }) |
| 101 }); |
| 102 unittest.throws = dart.const(new unittest.Throws()); |
| 103 unittest.throwsA = function(matcher) { |
| 104 return new unittest.Throws(src__util.wrapMatcher(matcher)); |
| 105 }; |
| 106 dart.fn(unittest.throwsA, src__interfaces.Matcher, [dart.dynamic]); |
22 unittest.group = function(name, body) { | 107 unittest.group = function(name, body) { |
23 return js.context.callMethod('suite', dart.list([name, body], core.Object)); | 108 return js.context.callMethod('suite', dart.list([name, body], core.Object)); |
24 }; | 109 }; |
25 dart.fn(unittest.group, dart.void, [core.String, dart.functionType(dart.void,
[])]); | 110 dart.fn(unittest.group, dart.void, [core.String, dart.functionType(dart.void,
[])]); |
26 unittest.test = function(name, body, opts) { | 111 unittest.test = function(name, body, opts) { |
27 let skip = opts && 'skip' in opts ? opts.skip : null; | 112 let skip = opts && 'skip' in opts ? opts.skip : null; |
28 if (skip != null) { | 113 if (skip != null) { |
29 core.print(`SKIP ${name}: ${skip}`); | 114 core.print(`SKIP ${name}: ${skip}`); |
30 return; | 115 return; |
31 } | 116 } |
(...skipping 15 matching lines...) Loading... |
47 TestFailure(message) { | 132 TestFailure(message) { |
48 this.message = message; | 133 this.message = message; |
49 } | 134 } |
50 toString() { | 135 toString() { |
51 return this.message; | 136 return this.message; |
52 } | 137 } |
53 }; | 138 }; |
54 dart.setSignature(unittest.TestFailure, { | 139 dart.setSignature(unittest.TestFailure, { |
55 constructors: () => ({TestFailure: [unittest.TestFailure, [core.String]]}) | 140 constructors: () => ({TestFailure: [unittest.TestFailure, [core.String]]}) |
56 }); | 141 }); |
| 142 unittest.TestCase = class TestCase extends core.Object { |
| 143 get isComplete() { |
| 144 return !dart.notNull(this.enabled) || this.result != null; |
| 145 } |
| 146 }; |
57 unittest.ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionTy
pe(core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, c
ore.bool])); | 147 unittest.ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionTy
pe(core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, c
ore.bool])); |
58 unittest.expect = function(actual, matcher, opts) { | 148 unittest.expect = function(actual, matcher, opts) { |
59 let reason = opts && 'reason' in opts ? opts.reason : null; | 149 let reason = opts && 'reason' in opts ? opts.reason : null; |
60 let verbose = opts && 'verbose' in opts ? opts.verbose : false; | 150 let verbose = opts && 'verbose' in opts ? opts.verbose : false; |
61 let formatter = opts && 'formatter' in opts ? opts.formatter : null; | 151 let formatter = opts && 'formatter' in opts ? opts.formatter : null; |
62 matcher = src__util.wrapMatcher(matcher); | 152 matcher = src__util.wrapMatcher(matcher); |
63 let matchState = dart.map(); | 153 let matchState = dart.map(); |
64 try { | 154 try { |
65 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) return; | 155 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) return; |
66 } catch (e) { | 156 } catch (e) { |
(...skipping 17 matching lines...) Loading... |
84 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); | 174 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); |
85 let mismatchDescription = new src__description.StringDescription(); | 175 let mismatchDescription = new src__description.StringDescription(); |
86 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); | 176 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); |
87 if (dart.notNull(mismatchDescription.length) > 0) { | 177 if (dart.notNull(mismatchDescription.length) > 0) { |
88 description.add(` Which: ${mismatchDescription}\n`); | 178 description.add(` Which: ${mismatchDescription}\n`); |
89 } | 179 } |
90 if (reason != null) description.add(reason).add('\n'); | 180 if (reason != null) description.add(reason).add('\n'); |
91 return description.toString(); | 181 return description.toString(); |
92 }; | 182 }; |
93 dart.fn(unittest._defaultFailFormatter, core.String, [dart.dynamic, src__inter
faces.Matcher, core.String, core.Map, core.bool]); | 183 dart.fn(unittest._defaultFailFormatter, core.String, [dart.dynamic, src__inter
faces.Matcher, core.String, core.Map, core.bool]); |
| 184 unittest.useHtmlConfiguration = function(isLayoutTest) { |
| 185 if (isLayoutTest === void 0) isLayoutTest = false; |
| 186 }; |
| 187 dart.fn(unittest.useHtmlConfiguration, dart.void, [], [core.bool]); |
94 unittest.isPositive = src__numeric_matchers.isPositive; | 188 unittest.isPositive = src__numeric_matchers.isPositive; |
95 unittest.isRangeError = src__error_matchers.isRangeError; | 189 unittest.isRangeError = src__error_matchers.isRangeError; |
96 unittest.isStateError = src__error_matchers.isStateError; | 190 unittest.isStateError = src__error_matchers.isStateError; |
97 unittest.equals = src__core_matchers.equals; | 191 unittest.equals = src__core_matchers.equals; |
98 unittest.CustomMatcher = src__core_matchers.CustomMatcher; | 192 unittest.CustomMatcher = src__core_matchers.CustomMatcher; |
99 unittest.inOpenClosedRange = src__numeric_matchers.inOpenClosedRange; | 193 unittest.inOpenClosedRange = src__numeric_matchers.inOpenClosedRange; |
100 unittest.pairwiseCompare = src__iterable_matchers.pairwiseCompare; | 194 unittest.pairwiseCompare = src__iterable_matchers.pairwiseCompare; |
101 unittest.equalsIgnoringCase = src__string_matchers.equalsIgnoringCase; | 195 unittest.equalsIgnoringCase = src__string_matchers.equalsIgnoringCase; |
102 unittest.isUnimplementedError = src__error_matchers.isUnimplementedError; | 196 unittest.isUnimplementedError = src__error_matchers.isUnimplementedError; |
103 unittest.hasLength = src__core_matchers.hasLength; | 197 unittest.hasLength = src__core_matchers.hasLength; |
(...skipping 55 matching lines...) Loading... |
159 unittest.greaterThan = src__numeric_matchers.greaterThan; | 253 unittest.greaterThan = src__numeric_matchers.greaterThan; |
160 unittest.isNonNegative = src__numeric_matchers.isNonNegative; | 254 unittest.isNonNegative = src__numeric_matchers.isNonNegative; |
161 unittest.isNull = src__core_matchers.isNull; | 255 unittest.isNull = src__core_matchers.isNull; |
162 unittest.isMap = src__core_matchers.isMap; | 256 unittest.isMap = src__core_matchers.isMap; |
163 unittest.stringContainsInOrder = src__string_matchers.stringContainsInOrder; | 257 unittest.stringContainsInOrder = src__string_matchers.stringContainsInOrder; |
164 unittest.closeTo = src__numeric_matchers.closeTo; | 258 unittest.closeTo = src__numeric_matchers.closeTo; |
165 unittest.Description = src__interfaces.Description; | 259 unittest.Description = src__interfaces.Description; |
166 // Exports: | 260 // Exports: |
167 exports.unittest = unittest; | 261 exports.unittest = unittest; |
168 }); | 262 }); |
OLD | NEW |