Skip to content

Commit

Permalink
Fixed some device tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp committed Jan 16, 2024
1 parent db71048 commit 4c3d753
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 68 deletions.
22 changes: 21 additions & 1 deletion tests/src/source/Main.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@ function Main(args)

? "here is my code"
? "hello"
end function
end function

function globalFunctionWithReturn() as dynamic
m.wasCalled = false
return false
end function

sub globalFunctionWithoutReturn()
m.wasCalled = false
end sub

namespace testNamespace
function functionWithReturn() as dynamic
m.wasCalled = false
return false
end function

sub functionWithoutReturn()
m.wasCalled = false
end sub
end namespace
95 changes: 28 additions & 67 deletions tests/src/source/NewExpectSyntax.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -170,52 +170,52 @@ namespace tests

@it("stubs global with inline anon with return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(globalFunctionWithReturn, function()
m.wasCalled = true
return true
end function)

m.assertTrue(globalFunctionWithReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

@it("stubs global with anon from variable with return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
stub = function()
m.wasCalled = true
return true
end function
m.stubCall(globalFunctionWithReturn, stub)

m.assertTrue(globalFunctionWithReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

@it("stubs global with inline anon without return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(globalFunctionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(globalFunctionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

@it("stubs global with anon from variable without return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(globalFunctionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(globalFunctionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

Expand All @@ -225,49 +225,49 @@ namespace tests

@it("stubs namespace with inline anon with return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(testNamespace.functionWithReturn, function()
m.wasCalled = true
return true
end function)
m.assertTrue(testNamespace.functionWithReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

@it("stubs namespace with anon from variable with return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
stub = function()
m.wasCalled = true
return true
end function
m.stubCall(testNamespace.functionWithReturn, stub)

m.assertTrue(testNamespace.functionWithReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

@it("stubs namespace with inline anon without return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = true
end sub)
m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

@it("stubs namespace with anon from variable without return value")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = true
end sub)
m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)
m.assertRunningTestIsPassed()
end function

Expand All @@ -277,38 +277,38 @@ namespace tests

@it("stubs namespace multiple times in one test")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)

m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = 1
end sub)
m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertEqual(m.wasCalled, 1)
m.assertEqual(getGlobalAA().wasCalled, 1)

m.assertRunningTestIsPassed()
end function

@it("stubs global multiple times in one test")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)

m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = 1
end sub)
m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertEqual(m.wasCalled, 1)
m.assertEqual(getGlobalAA().wasCalled, 1)

m.assertRunningTestIsPassed()
end function
Expand All @@ -319,55 +319,36 @@ namespace tests

@it("stubs namespace and then cleans it")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)

m.cleanMocks()

m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertFalse(m.wasCalled)
m.assertFalse(getGlobalAA().wasCalled)

m.assertRunningTestIsPassed()
end function

@it("stubs global and then cleans it")
function _()
m.wasCalled = false
getGlobalAA().wasCalled = false
m.stubCall(globalFunctionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(globalFunctionWithoutReturn())
m.assertTrue(m.wasCalled)
m.assertTrue(getGlobalAA().wasCalled)

m.cleanMocks()

m.assertInvalid(globalFunctionWithoutReturn())
m.assertFalse(m.wasCalled)

m.assertRunningTestIsPassed()
end function

@it("stubs global multiple times in one test")
function _()
m.wasCalled = false
m.stubCall(globalFunctionWithoutReturn, sub()
m.wasCalled = true
end sub)

m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertTrue(m.wasCalled)

m.stubCall(testNamespace.functionWithoutReturn, sub()
m.wasCalled = 1
end sub)
m.assertInvalid(testNamespace.functionWithoutReturn())
m.assertEqual(m.wasCalled, 1)
m.assertFalse(getGlobalAA().wasCalled)

m.assertRunningTestIsPassed()
end function
Expand Down Expand Up @@ -600,23 +581,3 @@ namespace tests
end class

end namespace

function globalFunctionWithReturn() as dynamic
m.wasCalled = false
return false
end function

sub globalFunctionWithoutReturn()
m.wasCalled = false
end sub

namespace testNamespace
function functionWithReturn() as dynamic
m.wasCalled = false
return false
end function

sub functionWithoutReturn()
m.wasCalled = false
end sub
end namespace

0 comments on commit 4c3d753

Please sign in to comment.