Skip to content

Commit 2257233

Browse files
Concurrency: Adjust test cases for new exception handling
1 parent 042e26e commit 2257233

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func entrypoint() async throws {
4848
resolve(.failure(.number(3)))
4949
})
5050
let error = try await expectAsyncThrow(await p.value)
51-
let jsValue = try expectCast(error, to: JSValue.self)
51+
let jsValue = try expectCast(error, to: JSException.self).thrownValue
5252
try expectEqual(jsValue, 3)
5353
try await expectEqual(p.result, .failure(.number(3)))
5454
}
@@ -157,7 +157,7 @@ func entrypoint() async throws {
157157
)
158158
}
159159
let promise2 = promise.then { _ in
160-
throw JSError(message: "should not succeed")
160+
throw MessageError("Should not be called", file: #file, line: #line, column: #column)
161161
} failure: { err in
162162
return err
163163
}

IntegrationTests/TestSuites/Sources/PrimaryTests/UnitTestUtils.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func expectThrow<T>(_ body: @autoclosure () throws -> T, file: StaticString = #f
110110
throw MessageError("Expect to throw an exception", file: file, line: line, column: column)
111111
}
112112

113-
func wrapUnsafeThrowableFunction(_ body: @escaping () -> Void, file: StaticString = #file, line: UInt = #line, column: UInt = #column) throws -> Error {
113+
func wrapUnsafeThrowableFunction(_ body: @escaping () -> Void, file: StaticString = #file, line: UInt = #line, column: UInt = #column) throws -> JSValue {
114114
JSObject.global.callThrowingClosure.function!(JSClosure { _ in
115115
body()
116116
return .undefined

IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

+17-20
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ try test("Closure Lifetime") {
263263
let c1Line = #line + 1
264264
let c1 = JSClosure { $0[0] }
265265
c1.release()
266-
let error = try expectThrow(try evalClosure.throws(c1, JSValue.number(42.0))) as! JSValue
267-
try expect("Error message should contains definition location", error.description.hasSuffix("PrimaryTests/main.swift:\(c1Line)"))
266+
let error = try expectThrow(try evalClosure.throws(c1, JSValue.number(42.0))) as! JSException
267+
try expect("Error message should contains definition location", error.thrownValue.description.hasSuffix("PrimaryTests/main.swift:\(c1Line)"))
268268
}
269269
#endif
270270

@@ -275,8 +275,8 @@ try test("Closure Lifetime") {
275275

276276
do {
277277
let c1 = JSClosure { _ in fatalError("Crash while closure evaluation") }
278-
let error = try expectThrow(try evalClosure.throws(c1)) as! JSValue
279-
try expectEqual(error.description, "RuntimeError: unreachable")
278+
let error = try expectThrow(try evalClosure.throws(c1)) as! JSException
279+
try expectEqual(error.thrownValue.description, "RuntimeError: unreachable")
280280
}
281281
}
282282

@@ -770,32 +770,32 @@ try test("Exception") {
770770

771771
// MARK: Throwing method calls
772772
let error1 = try expectThrow(try prop_9.object!.throwing.func1!())
773-
try expectEqual(error1 is JSValue, true)
774-
let errorObject = JSError(from: error1 as! JSValue)
773+
try expectEqual(error1 is JSException, true)
774+
let errorObject = JSError(from: (error1 as! JSException).thrownValue)
775775
try expectNotNil(errorObject)
776776

777777
let error2 = try expectThrow(try prop_9.object!.throwing.func2!())
778-
try expectEqual(error2 is JSValue, true)
779-
let errorString = try expectString(error2 as! JSValue)
778+
try expectEqual(error2 is JSException, true)
779+
let errorString = try expectString((error2 as! JSException).thrownValue)
780780
try expectEqual(errorString, "String Error")
781781

782782
let error3 = try expectThrow(try prop_9.object!.throwing.func3!())
783-
try expectEqual(error3 is JSValue, true)
784-
let errorNumber = try expectNumber(error3 as! JSValue)
783+
try expectEqual(error3 is JSException, true)
784+
let errorNumber = try expectNumber((error3 as! JSException).thrownValue)
785785
try expectEqual(errorNumber, 3.0)
786786

787787
// MARK: Simple function calls
788788
let error4 = try expectThrow(try prop_9.func1.function!.throws())
789-
try expectEqual(error4 is JSValue, true)
790-
let errorObject2 = JSError(from: error4 as! JSValue)
789+
try expectEqual(error4 is JSException, true)
790+
let errorObject2 = JSError(from: (error4 as! JSException).thrownValue)
791791
try expectNotNil(errorObject2)
792792

793793
// MARK: Throwing constructor call
794794
let Animal = JSObject.global.Animal.function!
795795
_ = try Animal.throws.new("Tama", 3, true)
796796
let ageError = try expectThrow(try Animal.throws.new("Tama", -3, true))
797-
try expectEqual(ageError is JSValue, true)
798-
let errorObject3 = JSError(from: ageError as! JSValue)
797+
try expectEqual(ageError is JSException, true)
798+
let errorObject3 = JSError(from: (ageError as! JSException).thrownValue)
799799
try expectNotNil(errorObject3)
800800
}
801801

@@ -824,18 +824,15 @@ try test("Unhandled Exception") {
824824

825825
// MARK: Throwing method calls
826826
let error1 = try wrapUnsafeThrowableFunction { _ = prop_9.object!.func1!() }
827-
try expectEqual(error1 is JSValue, true)
828-
let errorObject = JSError(from: error1 as! JSValue)
827+
let errorObject = JSError(from: error1)
829828
try expectNotNil(errorObject)
830829

831830
let error2 = try wrapUnsafeThrowableFunction { _ = prop_9.object!.func2!() }
832-
try expectEqual(error2 is JSValue, true)
833-
let errorString = try expectString(error2 as! JSValue)
831+
let errorString = try expectString(error2)
834832
try expectEqual(errorString, "String Error")
835833

836834
let error3 = try wrapUnsafeThrowableFunction { _ = prop_9.object!.func3!() }
837-
try expectEqual(error3 is JSValue, true)
838-
let errorNumber = try expectNumber(error3 as! JSValue)
835+
let errorNumber = try expectNumber(error3)
839836
try expectEqual(errorNumber, 3.0)
840837
}
841838

0 commit comments

Comments
 (0)