Skip to content

Commit 698ef2f

Browse files
Throw error and exit non-zero status when test failed
1 parent f3aad66 commit 698ef2f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

Diff for: IntegrationTests/TestSuites/Sources/PrimaryTests/UnitTestUtils.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ var printTestNames = false
55
// This will make it easier to debug any errors that occur on the JS side.
66
//printTestNames = true
77

8-
func test(_ name: String, testBlock: () throws -> Void) {
8+
func test(_ name: String, testBlock: () throws -> Void) throws {
99
if printTestNames { print(name) }
1010
do {
1111
try testBlock()
1212
} catch {
1313
print("Error in \(name)")
1414
print(error)
15+
throw error
1516
}
1617
}
1718

Diff for: IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import JavaScriptKit
22

3-
test("Literal Conversion") {
3+
try test("Literal Conversion") {
44
let global = JSObject.global
55
let inputs: [JSValue] = [
66
.boolean(true),
@@ -29,7 +29,7 @@ test("Literal Conversion") {
2929
}
3030
}
3131

32-
test("Object Conversion") {
32+
try test("Object Conversion") {
3333
// Notes: globalObject1 is defined in JavaScript environment
3434
//
3535
// ```js
@@ -70,7 +70,7 @@ test("Object Conversion") {
7070
try expectEqual(getJSValue(this: globalObject1Ref, name: "undefined_prop"), .undefined)
7171
}
7272

73-
test("Value Construction") {
73+
try test("Value Construction") {
7474
let globalObject1 = getJSValue(this: .global, name: "globalObject1")
7575
let globalObject1Ref = try expectObject(globalObject1)
7676
let prop_2 = getJSValue(this: globalObject1Ref, name: "prop_2")
@@ -82,7 +82,7 @@ test("Value Construction") {
8282
try expectEqual(Float.construct(from: prop_7), 3.14)
8383
}
8484

85-
test("Array Iterator") {
85+
try test("Array Iterator") {
8686
let globalObject1 = getJSValue(this: .global, name: "globalObject1")
8787
let globalObject1Ref = try expectObject(globalObject1)
8888
let prop_4 = getJSValue(this: globalObject1Ref, name: "prop_4")
@@ -93,7 +93,7 @@ test("Array Iterator") {
9393
try expectEqual(Array(array), expectedProp_4)
9494
}
9595

96-
test("Array RandomAccessCollection") {
96+
try test("Array RandomAccessCollection") {
9797
let globalObject1 = getJSValue(this: .global, name: "globalObject1")
9898
let globalObject1Ref = try expectObject(globalObject1)
9999
let prop_4 = getJSValue(this: globalObject1Ref, name: "prop_4")
@@ -104,7 +104,7 @@ test("Array RandomAccessCollection") {
104104
try expectEqual([array[0], array[1], array[2], array[3]], expectedProp_4)
105105
}
106106

107-
test("Value Decoder") {
107+
try test("Value Decoder") {
108108
struct GlobalObject1: Codable {
109109
struct Prop1: Codable {
110110
let nested_prop: Int
@@ -124,7 +124,7 @@ test("Value Decoder") {
124124
try expectEqual(globalObject1.prop_7, 3.14)
125125
}
126126

127-
test("Function Call") {
127+
try test("Function Call") {
128128
// Notes: globalObject1 is defined in JavaScript environment
129129
//
130130
// ```js
@@ -168,7 +168,7 @@ test("Function Call") {
168168
try expectEqual(func6(true, "OK", 2), .string("OK"))
169169
}
170170

171-
test("Host Function Registration") {
171+
try test("Host Function Registration") {
172172
// ```js
173173
// global.globalObject1 = {
174174
// ...
@@ -213,7 +213,7 @@ test("Host Function Registration") {
213213
hostFunc2.release()
214214
}
215215

216-
test("New Object Construction") {
216+
try test("New Object Construction") {
217217
// ```js
218218
// global.Animal = function(name, age, isCat) {
219219
// this.name = name
@@ -237,7 +237,7 @@ test("New Object Construction") {
237237
try expectEqual(dog1Bark(), .string("wan"))
238238
}
239239

240-
test("Call Function With This") {
240+
try test("Call Function With This") {
241241
// ```js
242242
// global.Animal = function(name, age, isCat) {
243243
// this.name = name
@@ -263,7 +263,7 @@ test("Call Function With This") {
263263
try expectEqual(gotIsCat, .boolean(true))
264264
}
265265

266-
test("Object Conversion") {
266+
try test("Object Conversion") {
267267
let array1 = [1, 2, 3]
268268
let jsArray1 = array1.jsValue().object!
269269
try expectEqual(jsArray1.length, .number(3))
@@ -292,7 +292,7 @@ test("Object Conversion") {
292292
try expectEqual(jsDict1.prop2, .string("foo"))
293293
}
294294

295-
test("ObjectRef Lifetime") {
295+
try test("ObjectRef Lifetime") {
296296
// ```js
297297
// global.globalObject1 = {
298298
// "prop_1": {
@@ -322,7 +322,7 @@ func closureScope() -> ObjectIdentifier {
322322
return result
323323
}
324324

325-
test("Closure Identifiers") {
325+
try test("Closure Identifiers") {
326326
let oid1 = closureScope()
327327
let oid2 = closureScope()
328328
try expectEqual(oid1, oid2)

Diff for: IntegrationTests/bin/primary-tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ const { startWasiTask } = require("../lib")
4141

4242
startWasiTask("./dist/PrimaryTests.wasm").catch(err => {
4343
console.log(err)
44+
process.exit(1)
4445
});

0 commit comments

Comments
 (0)