Skip to content

Commit

Permalink
tests: Use XCTUnwrap instead of '!'
Browse files Browse the repository at this point in the history
Also clean up a bunch of other unnecessary '!'
  • Loading branch information
tomsci committed Oct 24, 2024
1 parent 5d3f63a commit dfa65ef
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Tests/lua-test/LuaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ final class LuaTests: XCTestCase {
XCTAssertEqual(L.gettop(), 0)

// Avoid calling lua_toclose, to make this test still compile with Lua 5.3
try! L.load(string: """
try L.load(string: """
val = ...
local arg <close> = val
""")
Expand All @@ -1185,7 +1185,7 @@ final class LuaTests: XCTestCase {
let valUserdata: DeinitChecker? = L.touserdata(-1)
XCTAssertNotNil(valUserdata)
}
try! L.pcall(nargs: 1, nret: 0)
try L.pcall(nargs: 1, nret: 0)
XCTAssertEqual(deinited, 1)
XCTAssertEqual(L.getglobal("val"), .userdata)
do {
Expand Down Expand Up @@ -1213,7 +1213,7 @@ final class LuaTests: XCTestCase {
XCTAssertEqual(L.gettop(), 0)

// Avoid calling lua_toclose, to make this test still compile with Lua 5.3
try! L.load(string: """
try L.load(string: """
val = ...
local arg <close> = val
""")
Expand All @@ -1225,7 +1225,7 @@ final class LuaTests: XCTestCase {
let valUserdata: DeinitChecker? = L.touserdata(-1)
XCTAssertNotNil(valUserdata)
}
try! L.pcall(nargs: 1, nret: 0)
try L.pcall(nargs: 1, nret: 0)
XCTAssertEqual(deinited, 0)
XCTAssertEqual(closed, 1)
XCTAssertEqual(L.getglobal("val"), .userdata)
Expand Down Expand Up @@ -1430,7 +1430,7 @@ final class LuaTests: XCTestCase {
return 0
}
])
try! L.load(string: "obj = ...; return obj.woop()")
try L.load(string: "obj = ...; return obj.woop()")
// Check that Foo gets the default metatable with a woop() fn
L.push(userdata: Foo())
try L.pcall(nargs: 1, nret: 1)
Expand All @@ -1450,7 +1450,7 @@ final class LuaTests: XCTestCase {
return 1
}
))
try! L.load(string: "obj = ...; return obj()")
try L.load(string: "obj = ...; return obj()")
// Check that Foo gets the default metatable and is callable
L.push(userdata: Foo())
try L.pcall(nargs: 1, nret: 1)
Expand Down Expand Up @@ -1640,7 +1640,7 @@ final class LuaTests: XCTestCase {
XCTAssertNil(L.toany(1))
L.pop()

try! L.dostring("function foo() end")
try L.dostring("function foo() end")
L.getglobal("foo")
XCTAssertNotNil(L.toany(1) as? LuaValue)
L.pop()
Expand Down Expand Up @@ -2084,7 +2084,7 @@ final class LuaTests: XCTestCase {
}

func test_tovalue_userdata_dict() throws {
let ud: UnsafeMutableRawPointer = lua_newuserdata(L, 8)!
let ud: UnsafeMutableRawPointer = lua_newuserdata(L, 8)
let udVal: LuaValue = L.popref()
let lud: UnsafeMutableRawPointer = malloc(4)
defer {
Expand Down Expand Up @@ -2179,10 +2179,10 @@ final class LuaTests: XCTestCase {
}

func test_ref_scoping() {
var ref: LuaValue? = L.ref(any: "hello")
XCTAssertEqual(ref!.type, .string) // shut up compiler complaining about unused ref
var ref: LuaValue! = L.ref(any: "hello")
XCTAssertEqual(ref.type, .string) // shut up compiler complaining about unused ref
L.close()
XCTAssertNil(ref!.internal_get_L())
XCTAssertNil(ref.internal_get_L())
// The act of nilling this will cause a crash if the close didn't nil ref.L
ref = nil

Expand Down Expand Up @@ -2299,7 +2299,7 @@ final class LuaTests: XCTestCase {
XCTAssertEqual(intVal, 3)

// This is a test for tovalue(_:type:) really
XCTAssertEqual(Int8(L.tovalue(1, type: Int.self)!), 3)
XCTAssertEqual(Int8(try XCTUnwrap(L.tovalue(1, type: Int.self))), 3)

let integerVal: lua_Integer? = L.tovalue(1)
XCTAssertEqual(integerVal, 3)
Expand Down

0 comments on commit dfa65ef

Please sign in to comment.