From f97a11e72519e21378acfb4ba9a96fdb09d490c4 Mon Sep 17 00:00:00 2001 From: Aidan Lee Date: Thu, 27 Jun 2024 06:49:46 +0100 Subject: [PATCH] CI - UTest2 (#1120) * std tests now use utest * utest for native tests * utest for telemetry * rest of the tests hopefully working * another isNull test * Easier to reason about assert * Swivel asserts around * More aggressive stack clearing * Non debug haxe tests --- .github/workflows/setup/action.yml | 2 +- .github/workflows/test.yml | 4 +- test/cffi/compile-neko.hxml | 8 +- test/cffi/compile-utf8.hxml | 8 +- test/cffi/compile.hxml | 8 +- test/cffi/src/TestBase.hx | 18 - test/cffi/src/TestCffi.hx | 107 ++-- test/cffi/src/TestMain.hx | 9 +- test/cffi/src/TestPrime.hx | 53 +- test/cppia/compile-client.hxml | 5 +- test/cppia/compile-host.hxml | 7 +- test/debugger/compile.hxml | 7 +- test/extern-lib/compile-api.hxml | 5 +- test/haxe/TestIntHash.hx | 18 +- test/haxe/TestKeywords.hx | 7 +- test/haxe/TestMain.hx | 51 +- test/haxe/TestObjectHash.hx | 20 +- test/haxe/TestSort.hx | 8 +- test/haxe/TestStringHash.hx | 19 +- test/haxe/TestTypes.hx | 25 +- test/haxe/TestWeakHash.hx | 36 +- test/haxe/compile.hxml | 8 +- test/haxe/compile_nme.nmml | 3 +- test/haxe/file/TestFile.hx | 10 +- test/haxe/gc/TestGC.hx | 77 +-- test/haxe/gc/TestGCThreaded.hx | 14 +- test/haxe/native/TestFinalizer.hx | 13 +- test/native/Native.hx | 25 +- test/native/compile.hxml | 6 +- test/native/tests/TestGlobalNamespace.hx | 7 +- test/native/tests/TestNativeEnum.hx | 29 +- test/native/tests/TestNativeGen.hx | 9 +- test/native/tests/TestNonVirtual.hx | 17 +- test/native/tests/TestPtr.hx | 246 ++++---- test/native/tests/TestRectangle.hx | 41 +- test/native/tests/TestRgb.hx | 23 +- test/native/tests/TestStdio.hx | 8 +- test/std/Test.hx | 702 ++++++++--------------- test/std/compile32.hxml | 8 +- test/std/compile64.hxml | 8 +- test/std/testAndroid.hxml | 14 +- test/telemetry/TestBasic.hx | 11 +- test/telemetry/TestMain.hx | 7 +- test/telemetry/compile.hxml | 8 +- test/threads/compile.hxml | 7 +- test/unit/haxe/unit/TestCase.hx | 116 ---- test/unit/haxe/unit/TestResult.hx | 100 ---- test/unit/haxe/unit/TestRunner.hx | 186 ------ test/unit/haxe/unit/TestStatus.hx | 72 --- 49 files changed, 735 insertions(+), 1465 deletions(-) delete mode 100644 test/cffi/src/TestBase.hx delete mode 100644 test/unit/haxe/unit/TestCase.hx delete mode 100644 test/unit/haxe/unit/TestResult.hx delete mode 100644 test/unit/haxe/unit/TestRunner.hx delete mode 100644 test/unit/haxe/unit/TestStatus.hx diff --git a/.github/workflows/setup/action.yml b/.github/workflows/setup/action.yml index 01f2c6b47..5e2978381 100644 --- a/.github/workflows/setup/action.yml +++ b/.github/workflows/setup/action.yml @@ -14,7 +14,7 @@ runs: - name: install haxe libraries shell: pwsh run: | - haxelib install utest + haxelib git utest https://github.com/haxe-utest/utest haxelib git hx4compat https://github.com/HaxeFoundation/hx4compat haxelib dev hxcpp ${{ github.workspace }} haxelib list diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da7c478cd..786576295 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,9 +33,9 @@ jobs: with: haxe: ${{ inputs.haxe }} - name: build - run: haxe compile.hxml --debug -D HXCPP_M${{ inputs.arch }} + run: haxe compile.hxml -D HXCPP_M${{ inputs.arch }} - name: run - run: bin${{ inputs.sep }}TestMain-debug + run: bin${{ inputs.sep }}TestMain cffi: runs-on: ${{ inputs.os }} diff --git a/test/cffi/compile-neko.hxml b/test/cffi/compile-neko.hxml index 7c2e20c49..883f9ee6b 100644 --- a/test/cffi/compile-neko.hxml +++ b/test/cffi/compile-neko.hxml @@ -1,4 +1,4 @@ --cp src --main TestMain --neko bin/neko/TestMain.n --cp ../unit +-p src +-m TestMain +-L utest +--neko bin/neko/TestMain.n \ No newline at end of file diff --git a/test/cffi/compile-utf8.hxml b/test/cffi/compile-utf8.hxml index 021ec3683..f28d14588 100644 --- a/test/cffi/compile-utf8.hxml +++ b/test/cffi/compile-utf8.hxml @@ -1,5 +1,5 @@ --cp src --main TestMain --cpp bin/cpp-utf8 --cp ../unit +-p src +-m TestMain +-L utest -D disable_unicode_strings +--cpp bin/cpp-utf8 \ No newline at end of file diff --git a/test/cffi/compile.hxml b/test/cffi/compile.hxml index 1d2be32bf..769320c3b 100644 --- a/test/cffi/compile.hxml +++ b/test/cffi/compile.hxml @@ -1,4 +1,4 @@ --cp src --main TestMain --cpp bin/cpp --cp ../unit +-p src +-m TestMain +-L utest +--cpp bin/cpp \ No newline at end of file diff --git a/test/cffi/src/TestBase.hx b/test/cffi/src/TestBase.hx deleted file mode 100644 index 18465c2ef..000000000 --- a/test/cffi/src/TestBase.hx +++ /dev/null @@ -1,18 +0,0 @@ -import haxe.PosInfos; - -class TestBase extends haxe.unit.TestCase -{ - public function assertClose(inWant:Float, inGot:Float, ?c : PosInfos ) - { - assertTrue( Math.abs(inWant-inGot) < 0.001, c ); - } - - public function assertEq(inWant:T, inGot:T, ?c : PosInfos ) - { - var same = inWant==inGot; - if (!same) - trace('Expected $inWant, got $inGot'); - assertTrue(same, c); - } -} - diff --git a/test/cffi/src/TestCffi.hx b/test/cffi/src/TestCffi.hx index c2c0c302e..9ebe93e92 100644 --- a/test/cffi/src/TestCffi.hx +++ b/test/cffi/src/TestCffi.hx @@ -9,8 +9,10 @@ import neko.vm.Gc; import Loader; import haxe.io.BytesData; +import utest.Test; +import utest.Assert; -class TestCffi extends TestBase +class TestCffi extends Test { static var isBool:Dynamic->Bool = Lib.load("prime", "isBool", 1); static var isNull:Dynamic->Bool = Lib.load("prime", "isNull", 1); @@ -49,37 +51,37 @@ class TestCffi extends TestBase { cpp.Prime.nekoInit("prime"); - assertTrue( isBool!=null ); - assertTrue( isBool(true) ); - assertTrue( isBool(false) ); - assertFalse( isBool(21) ); - assertFalse( isBool("Hello") ); - assertFalse( isBool(null) ); + Assert.isTrue( isBool!=null ); + Assert.isTrue( isBool(true) ); + Assert.isTrue( isBool(false) ); + Assert.isFalse( isBool(21) ); + Assert.isFalse( isBool("Hello") ); + Assert.isFalse( isBool(null) ); - assertTrue( isNull!=null ); - assertTrue( isNull(null) ); - assertFalse( isNull(false) ); - assertFalse( isNull(32) ); - assertFalse( isNull("") ); + Assert.isTrue( isNull!=null ); + Assert.isTrue( isNull(null) ); + Assert.isFalse( isNull(false) ); + Assert.isFalse( isNull(32) ); + Assert.isFalse( isNull("") ); - assertTrue( allocNull!=null ); - assertEquals(null, allocNull() ); + Assert.isTrue( allocNull!=null ); + Assert.isNull( allocNull() ); - assertTrue( appendString!=null ); - assertTrue( bufferToString!=null ); - assertTrue( getRoot!=null ); - assertTrue( setRoot!=null ); + Assert.isTrue( appendString!=null ); + Assert.isTrue( bufferToString!=null ); + Assert.isTrue( getRoot!=null ); + Assert.isTrue( setRoot!=null ); - assertTrue( createAnon!=null ); + Assert.isTrue( createAnon!=null ); - assertFalse( valIsBuffer(null) ); - assertFalse( valIsBuffer(1) ); - assertFalse( valIsBuffer({}) ); - assertFalse( valIsBuffer("String Buf") ); + Assert.isFalse( valIsBuffer(null) ); + Assert.isFalse( valIsBuffer(1) ); + Assert.isFalse( valIsBuffer({}) ); + Assert.isFalse( valIsBuffer("String Buf") ); if (cppObjectAsDynamic!=null) - assertTrue( getObjectAsString()==null); + Assert.isNull( getObjectAsString() ); var anon = createAnon(); for(f in Reflect.fields(anon)) @@ -87,7 +89,7 @@ class TestCffi extends TestBase #if cpp var value:Dynamic = Reflect.field(anon, f); //trace(f + " " + Type.typeof(value) ); - assertTrue( Std.string(Type.typeof(value)) == f ); + Assert.isTrue( Std.string(Type.typeof(value)) == f ); #end } @@ -102,52 +104,51 @@ class TestCffi extends TestBase var bytes = haxe.io.Bytes.ofString(base).getData(); #if !neko - assertTrue( valIsBuffer(bytes) ); + Assert.isTrue( valIsBuffer(bytes) ); // Can't acess neko buffer from haxe code bytes = appendString(bytes,"World"); var result = bufferToString(bytes); - assertEq(result,"Hello World"); + Assert.equals("Hello World", result); #end - assertEq(valToString(null,1),"String:null1"); - assertEq(valToString("x",1.1),"String:x1.1"); - assertEq(valToString("Hello"," World"),"String:Hello World"); - assertEq(valToString([1],[]),"String:[1][]"); + Assert.equals("String:null1", valToString(null,1)); + Assert.equals("String:x1.1", valToString("x",1.1)); + Assert.equals("String:Hello World", valToString("Hello"," World")); + Assert.equals("String:[1][]", valToString([1],[])); - assertEq(subBuffer("hello",4),"Cold as hell"); + Assert.equals("Cold as hell", subBuffer("hello",4)); #if !neko - assertEq(charString(99,97,116),"A cat"); + Assert.equals("A cat", charString(99,97,116)); #end var bytes = haxe.io.Bytes.ofString("String Buffer"); - assertEq( byteDataSize(bytes), 13 ); - assertEq( byteDataByte(bytes,1), 't'.code ); + Assert.equals( 13, byteDataSize(bytes) ); + Assert.equals( 't'.code, byteDataByte(bytes,1) ); - assertEq( getAbstractFreeCount(), 0 ); + Assert.equals( 0, getAbstractFreeCount() ); var createdAbs = createAbstract(); - assertTrue( createdAbs!=null ); - assertEq( getAbstract(createdAbs), 99 ); + Assert.notNull( createdAbs ); + Assert.equals( 99, getAbstract(createdAbs) ); // Explicitly freeing abstract does not call finalizer freeAbstract( createdAbs ); - assertEq( getAbstractFreeCount(), 0 ); - assertEq( getAbstract(createdAbs), -1 ); - assertEq( getAbstractFreeCount(), 0 ); + Assert.equals( 0, getAbstractFreeCount() ); + Assert.equals( -1, getAbstract(createdAbs) ); + Assert.equals( 0, getAbstractFreeCount() ); createdAbs = null; Gc.run(true); - assertEq( getAbstractFreeCount(), 0 ); + Assert.equals( 0, getAbstractFreeCount() ); var allocatedAbs = allocAbstract(); - assertTrue( allocatedAbs!=null ); - assertEq( getAbstract(allocatedAbs), 99 ); - assertEq( getAbstractFreeCount(), 0 ); + Assert.notNull( allocatedAbs ); + Assert.equals( 99, getAbstract(allocatedAbs) ); + Assert.equals( 0, getAbstractFreeCount() ); freeAbstract( allocatedAbs ); - assertEq( getAbstract(allocatedAbs), -1 ); - assertEq( getAbstractFreeCount(), 0 ); + Assert.equals( -1, getAbstract(allocatedAbs) ); + Assert.equals( 0, getAbstractFreeCount() ); allocatedAbs = null; - createDeepAbstracts(2); clearStack(12); @@ -156,21 +157,21 @@ class TestCffi extends TestBase var freeCount = getAbstractFreeCount(); if (freeCount!=2) { - Sys.println('\nWarning: $freeCount != 2'); + Assert.warn('$freeCount != 2'); } for(i in 0...100) - assertEq( getRoot(i)+"", [i]+"" ); + Assert.equals( [i]+"", getRoot(i)+"" ); clearRoots(); for(i in 0...100) - assertEq( getRoot(i), null ); + Assert.isNull( getRoot(i) ); - assertEq( getAbstractFreeCount(), 2 ); + Assert.equals( 2, getAbstractFreeCount() ); } - function clearStack(count:Int, ?nothing:Dynamic):Dynamic + function clearStack(count:Int, ?_:Dynamic, ?_:Dynamic, ?_:Dynamic, ?_:Dynamic, ?_:Dynamic):Dynamic { if (count==0) return 0; diff --git a/test/cffi/src/TestMain.hx b/test/cffi/src/TestMain.hx index 3a7f07ed5..78c8083ab 100644 --- a/test/cffi/src/TestMain.hx +++ b/test/cffi/src/TestMain.hx @@ -3,14 +3,7 @@ class TestMain { public static function main() { - var r = new haxe.unit.TestRunner(); - r.add(new TestCffi()); - r.add(new TestPrime()); - - var t0 = haxe.Timer.stamp(); - var success = r.run(); - trace(" Time : " + (haxe.Timer.stamp()-t0)*1000 ); - Sys.exit(success ? 0 : 1); + utest.UTest.run([ new TestCffi(), new TestPrime() ]); } } diff --git a/test/cffi/src/TestPrime.hx b/test/cffi/src/TestPrime.hx index a628f3a8e..2f3991828 100644 --- a/test/cffi/src/TestPrime.hx +++ b/test/cffi/src/TestPrime.hx @@ -1,6 +1,7 @@ +import utest.Assert; +import utest.Test; - -class TestPrime extends TestBase +class TestPrime extends Test { static var add = Loader.load("addInts", "iii" ); #if cpp @@ -28,51 +29,51 @@ class TestPrime extends TestBase { cpp.Prime.nekoInit("prime"); - assertTrue(add!=null); - assertEquals(7, add(2,5)); + Assert.notNull(add); + Assert.equals(7, add(2,5)); #if cpp printString("Hello World"); #end var len = distance3d(3,4,5); - assertClose(50,len*len); + Assert.floatEquals(50,len*len, 0.001); fields( { x:11, name:"Hello" } ); fields( null ); - assertEquals("Ok", stringVal("HxString")); + Assert.equals("Ok", stringVal("HxString")); - assertEquals(null, getNullString()); + Assert.isNull(getNullString()); - assertEquals( ""+[1], ""+select(0, [1], "Hello", {x:1}, add) ); + Assert.equals( ""+[1], ""+select(0, [1], "Hello", {x:1}, add) ); var shouldBeNull:String = "" + select(0, null, "Hello", {x:1}, add); trace( "null ?" + shouldBeNull + "/" + shouldBeNull.length ); - assertEquals( "null", shouldBeNull ); - //assertEquals( "null", ""+select(0, null, "Hello", {x:1}, add) ); - assertEquals( ""+"Hello", ""+select(1, [1], "Hello", {x:1}, add)); - assertEquals( ""+{x:1}, ""+select(2, [1], "Hello", {x:1}, add) ); - assertEquals( ""+add, ""+select(3, [1], "Hello", {x:1}, add) ); + Assert.equals( "null", shouldBeNull ); + //Assert.equals( "null", ""+select(0, null, "Hello", {x:1}, add) ); + Assert.equals( ""+"Hello", ""+select(1, [1], "Hello", {x:1}, add)); + Assert.equals( ""+{x:1}, ""+select(2, [1], "Hello", {x:1}, add) ); + Assert.equals( ""+add, ""+select(3, [1], "Hello", {x:1}, add) ); - assertClose( 7.3, floats(true,4.2,3.1) ); - assertClose( 1.1, floats(false,4.2,3.1) ); + Assert.floatEquals( 7.3, floats(true,4.2,3.1), 0.001 ); + Assert.floatEquals( 1.1, floats(false,4.2,3.1), 0.001 ); - assertEquals( 5, multi5(1,1,1,1,1) ); - assertEquals( 6, multi6(1,1,1,1,1,1) ); - assertEquals( 7, multi7(1,1,1,1,1,1,1) ); - assertEquals( 8, multi8(1,1,1,1,1,1,1,1) ); - assertEquals( 9, multi9(1,1,1,1,1,1,1,1,1) ); - assertEquals( 10, multi10(1,1,1,1,1,1,1,1,1,1) ); - assertEquals( 11, multi11(1,1,1,1,1,1,1,1,1,1,1) ); - assertEquals( 12, multi12(1,1,1,1,1,1,1,1,1,1,1,1) ); + Assert.equals( 5, multi5(1,1,1,1,1) ); + Assert.equals( 6, multi6(1,1,1,1,1,1) ); + Assert.equals( 7, multi7(1,1,1,1,1,1,1) ); + Assert.equals( 8, multi8(1,1,1,1,1,1,1,1) ); + Assert.equals( 9, multi9(1,1,1,1,1,1,1,1,1) ); + Assert.equals( 10, multi10(1,1,1,1,1,1,1,1,1,1) ); + Assert.equals( 11, multi11(1,1,1,1,1,1,1,1,1,1,1) ); + Assert.equals( 12, multi12(1,1,1,1,1,1,1,1,1,1,1,1) ); var s0 = "hello"; var s1 = "こんにちは"; - assertTrue( addStrings(s0,s0) == s0+s0 ); + Assert.isTrue( addStrings(s0,s0) == s0+s0 ); var s01 = addStrings(s0,s1); - assertTrue( s01 == s0+s1 ); + Assert.isTrue( s01 == s0+s1 ); var s11 = addStrings(s1,s1); - assertTrue( s11 == s1+s1 ); + Assert.isTrue( s11 == s1+s1 ); } } diff --git a/test/cppia/compile-client.hxml b/test/cppia/compile-client.hxml index 39f465615..4c9c3e0c5 100644 --- a/test/cppia/compile-client.hxml +++ b/test/cppia/compile-client.hxml @@ -1,4 +1,3 @@ --main Client +-m Client -D dll_import=host_classes.info --cppia bin/client.cppia --cp ../unit +--cppia bin/client.cppia \ No newline at end of file diff --git a/test/cppia/compile-host.hxml b/test/cppia/compile-host.hxml index 93197cd62..0c39f79c5 100644 --- a/test/cppia/compile-host.hxml +++ b/test/cppia/compile-host.hxml @@ -1,6 +1,5 @@ --main CppiaHost +-m CppiaHost -D scriptable -D dll_export=host_classes.info --dce no --cpp bin --cp ../unit +--dce no +--cpp bin \ No newline at end of file diff --git a/test/debugger/compile.hxml b/test/debugger/compile.hxml index 8898b6b16..a14492f92 100644 --- a/test/debugger/compile.hxml +++ b/test/debugger/compile.hxml @@ -1,6 +1,5 @@ --main App --cpp bin +-m App -D hxcpp_debugger -D HXCPP_DEBUGGER --debug --cp ../unit +--cpp bin +--debug \ No newline at end of file diff --git a/test/extern-lib/compile-api.hxml b/test/extern-lib/compile-api.hxml index 492f03b90..7b22d2fe3 100644 --- a/test/extern-lib/compile-api.hxml +++ b/test/extern-lib/compile-api.hxml @@ -1,4 +1,3 @@ --cpp gen-externs +--cpp gen-externs -D static_link -api.HaxeApi --cp ../unit +api.HaxeApi \ No newline at end of file diff --git a/test/haxe/TestIntHash.hx b/test/haxe/TestIntHash.hx index 125839594..cd28b10a8 100644 --- a/test/haxe/TestIntHash.hx +++ b/test/haxe/TestIntHash.hx @@ -1,4 +1,7 @@ -class TestIntHash extends haxe.unit.TestCase +import utest.Test; +import utest.Assert; + +class TestIntHash extends Test { function spamAlot() { @@ -51,16 +54,9 @@ class TestIntHash extends haxe.unit.TestCase public function test() { - var err = ""; - try - { - spamAlot(); - } - catch(e:String) - { - err = e; - } - assertTrue(err==""); + spamAlot(); + + Assert.pass(); } } diff --git a/test/haxe/TestKeywords.hx b/test/haxe/TestKeywords.hx index 811a1987b..746565b3d 100644 --- a/test/haxe/TestKeywords.hx +++ b/test/haxe/TestKeywords.hx @@ -1,3 +1,6 @@ +import utest.Test; +import utest.Assert; + private enum GnarlyEnum { e0; @@ -16,7 +19,7 @@ private enum GnarlyEnum getObject(i:Int); } -class TestKeywords extends haxe.unit.TestCase +class TestKeywords extends Test { public function new() super(); @@ -44,6 +47,6 @@ class TestKeywords extends haxe.unit.TestCase case getObject(i): 1; default: 0; } - assertTrue(count==3); + Assert.equals(3, count); } } diff --git a/test/haxe/TestMain.hx b/test/haxe/TestMain.hx index d94a50662..8aefcf24b 100644 --- a/test/haxe/TestMain.hx +++ b/test/haxe/TestMain.hx @@ -1,4 +1,7 @@ package; + +import utest.Runner; +import utest.ui.Report; import gc.TestGC; class TestMain #if nme extends nme.display.Sprite #end { @@ -12,33 +15,35 @@ class TestMain #if nme extends nme.display.Sprite #end { passes = Std.parseInt(args[0]); #end - var r = new haxe.unit.TestRunner(); - r.add(new TestTypes()); - r.add(new TestKeywords()); - r.add(new TestSort()); - r.add(new TestGC()); + final runner = new Runner(); + runner.addCase(new TestTypes()); + runner.addCase(new TestKeywords()); + runner.addCase(new TestSort()); + runner.addCase(new TestGC()); #if !nme - r.add(new gc.TestGCThreaded()); + runner.addCase(new gc.TestGCThreaded()); #end - r.add(new TestIntHash()); - r.add(new TestStringHash()); - r.add(new TestObjectHash()); - r.add(new TestWeakHash()); + runner.addCase(new TestIntHash()); + runner.addCase(new TestStringHash()); + runner.addCase(new TestObjectHash()); + runner.addCase(new TestWeakHash()); #if !nme - r.add(new file.TestFile()); + runner.addCase(new file.TestFile()); #end #if cpp - r.add(new native.TestFinalizer()); + runner.addCase(new native.TestFinalizer()); #end + final report = Report.create(runner); + + runner.run(); + for(i in 0...passes) { var t0 = haxe.Timer.stamp(); - var success = r.run(); + runner.run(); trace(" Time : " + (haxe.Timer.stamp()-t0)*1000 ); - if (!success) - return 1; } return 0; } @@ -63,13 +68,23 @@ class TestMain #if nme extends nme.display.Sprite #end { } - static function endTest(error:Int) trace(error==0 ? "All tests OK" : "Tests Failed!"); #else public static function main() { - Sys.exit(runTests()); + utest.UTest.run([ + new TestTypes(), + new TestKeywords(), + new TestSort(), + new TestGC(), + new gc.TestGCThreaded(), + new TestIntHash(), + new TestStringHash(), + new TestObjectHash(), + new TestWeakHash(), + new file.TestFile(), + new native.TestFinalizer() + ]); } - public static function endTest(error:Int) Sys.exit(error); #end } diff --git a/test/haxe/TestObjectHash.hx b/test/haxe/TestObjectHash.hx index f9a95427d..0988c575e 100644 --- a/test/haxe/TestObjectHash.hx +++ b/test/haxe/TestObjectHash.hx @@ -1,11 +1,13 @@ +import utest.Test; +import utest.Assert; + class ObjectData { public var id:Int; public function new(inId:Int) id = inId; } - -class TestObjectHash extends haxe.unit.TestCase +class TestObjectHash extends Test { function spamAlot() { @@ -75,17 +77,9 @@ class TestObjectHash extends haxe.unit.TestCase public function test() { - var err = ""; - try - { - spamAlot(); - } - catch(e:Dynamic) - { - trace(e); - err = e; - } - assertTrue(err==""); + spamAlot(); + + Assert.pass(); } } diff --git a/test/haxe/TestSort.hx b/test/haxe/TestSort.hx index 6e658942c..f722b93cc 100644 --- a/test/haxe/TestSort.hx +++ b/test/haxe/TestSort.hx @@ -1,3 +1,6 @@ +import utest.Test; +import utest.Assert; + class SortData { public var value:Int; @@ -11,8 +14,7 @@ class SortData } } - -class TestSort extends haxe.unit.TestCase +class TestSort extends Test { public function testObjects() { @@ -54,7 +56,7 @@ class TestSort extends haxe.unit.TestCase throw "Not stable sort"; } - assertTrue(true); + Assert.pass(); } } diff --git a/test/haxe/TestStringHash.hx b/test/haxe/TestStringHash.hx index c9894a9b9..2cdaa3635 100644 --- a/test/haxe/TestStringHash.hx +++ b/test/haxe/TestStringHash.hx @@ -1,4 +1,7 @@ -class TestStringHash extends haxe.unit.TestCase +import utest.Test; +import utest.Assert; + +class TestStringHash extends Test { function spamAlot() { @@ -72,17 +75,9 @@ class TestStringHash extends haxe.unit.TestCase public function test() { - var err = ""; - try - { - spamAlot(); - } - catch(e:Dynamic) - { - trace(e); - err = e; - } - assertTrue(err==""); + spamAlot(); + + Assert.pass(); } } diff --git a/test/haxe/TestTypes.hx b/test/haxe/TestTypes.hx index 977ef071a..55075a889 100644 --- a/test/haxe/TestTypes.hx +++ b/test/haxe/TestTypes.hx @@ -1,4 +1,7 @@ -class TestTypes extends haxe.unit.TestCase +import utest.Test; +import utest.Assert; + +class TestTypes extends Test { var i0:Int = 1; var i1:cpp.Int32 = 1; @@ -30,20 +33,20 @@ class TestTypes extends haxe.unit.TestCase public function testConstCharStar() { var ccs = stringToCcs("hello"); - assertTrue( ccsToString(ccs)=="hello" ); - assertTrue( ccsToStringCast(ccs)=="hello" ); + Assert.equals( ccsToString(ccs), "hello" ); + Assert.equals( ccsToStringCast(ccs), "hello" ); } public function testDynamic() { var d:Dynamic = this; - assertTrue(d.i0==1); - assertTrue(d.i1==1); - assertTrue(d.i2==1); - assertTrue(d.i3==1); - assertTrue(d.i4==1); - assertTrue(d.i5==1); - assertTrue(d.i6==1); - assertTrue(d.i7==1); + Assert.equals(d.i0, 1); + Assert.equals(d.i1, 1); + Assert.equals(d.i2, 1); + Assert.equals(d.i3, 1); + Assert.equals(d.i4, 1); + Assert.equals(d.i5, 1); + Assert.equals(d.i6, 1); + Assert.equals(d.i7, 1); } } diff --git a/test/haxe/TestWeakHash.hx b/test/haxe/TestWeakHash.hx index 73316e5ae..d1db98627 100644 --- a/test/haxe/TestWeakHash.hx +++ b/test/haxe/TestWeakHash.hx @@ -1,3 +1,5 @@ +import utest.Test; +import utest.Assert; import haxe.ds.WeakMap; class WeakObjectData @@ -7,8 +9,7 @@ class WeakObjectData public function toString() return "Data " + id; } - -class TestWeakHash extends haxe.unit.TestCase +class TestWeakHash extends Test { var retained:Array; @@ -48,11 +49,8 @@ class TestWeakHash extends haxe.unit.TestCase valid++; } // There may be one or two values lurking on the stack, which is conservatively marked - if (oddFound>2) - trace("Too many odd values retained " + oddFound); - if (!(valid>=expect && valid=expect && valid=expect && valid, expect:Int) { @@ -72,22 +70,14 @@ class TestWeakHash extends haxe.unit.TestCase public function test() { - var err = ""; - try - { - var map = createMapDeep(20,1000); - cpp.vm.Gc.run(true); - deepCheckMap(10,map,500); - deepClearRetained(10); - cpp.vm.Gc.run(true); - checkMap(map,0); - } - catch(e:String) - { - trace(e); - err = e; - } - assertTrue(err==""); + final map = createMapDeep(20,1000); + cpp.vm.Gc.run(true); + deepCheckMap(10,map,500); + deepClearRetained(10); + cpp.vm.Gc.run(true); + checkMap(map,0); + + Assert.pass(); } } diff --git a/test/haxe/compile.hxml b/test/haxe/compile.hxml index 7ad2370f5..2a23d789e 100644 --- a/test/haxe/compile.hxml +++ b/test/haxe/compile.hxml @@ -1,5 +1,5 @@ --cpp bin --main TestMain --resource TestMain.hx +-m TestMain +-r TestMain.hx -D HXCPP_GC_GENERATIONAL --cp ../unit +-L utest +--cpp bin \ No newline at end of file diff --git a/test/haxe/compile_nme.nmml b/test/haxe/compile_nme.nmml index 8e2bed2e4..7fe4f5380 100644 --- a/test/haxe/compile_nme.nmml +++ b/test/haxe/compile_nme.nmml @@ -25,10 +25,9 @@ /> + - - diff --git a/test/haxe/file/TestFile.hx b/test/haxe/file/TestFile.hx index 6ad2ac869..c9a1009d8 100644 --- a/test/haxe/file/TestFile.hx +++ b/test/haxe/file/TestFile.hx @@ -1,10 +1,12 @@ package file; -class TestFile extends haxe.unit.TestCase +import utest.Test; +import utest.Assert; + +class TestFile extends Test { public function testGetContentEmptyFile() { - assertEquals('', sys.io.File.getContent('./file/empty.txt')); + Assert.equals('', sys.io.File.getContent('./file/empty.txt')); } - -} +} \ No newline at end of file diff --git a/test/haxe/gc/TestGC.hx b/test/haxe/gc/TestGC.hx index deea8f3ef..20b39e98d 100644 --- a/test/haxe/gc/TestGC.hx +++ b/test/haxe/gc/TestGC.hx @@ -1,4 +1,7 @@ package gc; + +import utest.Test; +import utest.Assert; import haxe.io.Bytes; import cpp.vm.Gc; @@ -6,7 +9,7 @@ class CustomObject { public function new():Void {} } -class TestGC extends haxe.unit.TestCase { +class TestGC extends Test { function createDummy(val:Dynamic):Dynamic { return { dummy: val }; } @@ -38,10 +41,10 @@ class TestGC extends haxe.unit.TestCase { } public function testObject():Void { create(createAbc); - var zombie = gc(); - assertTrue(zombie != null); - assertEquals("abc", zombie.test); - assertTrue(gc() == null); + var zombie:Dynamic = gc(); + Assert.notNull(zombie); + Assert.equals("abc", zombie.test); + Assert.isNull(gc()); } // Null for numbers < 256 are special cases @@ -66,10 +69,10 @@ class TestGC extends haxe.unit.TestCase { }; public function testFunc():Void { create(createFunction); - var zombie = gc(); - assertTrue(zombie != null); - assertEquals("abc", zombie()); - assertTrue(gc() == null); + var zombie:Dynamic = gc(); + Assert.notNull(zombie); + Assert.equals("abc", zombie()); + Assert.isNull(gc()); } function createCustom():Void { @@ -79,9 +82,9 @@ class TestGC extends haxe.unit.TestCase { public function testCustomObject():Void { create(createCustom); var zombie = gc(); - assertTrue(zombie != null); - assertTrue(Std.isOfType(zombie, CustomObject)); - assertTrue(gc() == null); + Assert.notNull(zombie); + Assert.isOfType(zombie, CustomObject); + Assert.isNull(gc()); } function createBytes():Void { @@ -91,39 +94,39 @@ class TestGC extends haxe.unit.TestCase { public function testBytes():Void { create(createBytes); var zombie = gc(); - assertTrue(zombie != null); - assertTrue(Std.isOfType(zombie, Bytes)); - assertTrue(gc() == null); + Assert.notNull(zombie); + Assert.isOfType(zombie, Bytes); + Assert.isNull(gc()); } public function testBigStack():Void { - assertTrue( TestBigStack.test() ); - } + Assert.isTrue( TestBigStack.test() ); + } #if !cppia public function testConstStrings():Void { - // Const strings void Gc overhead - var strings = new Array(); - strings.push( haxe.Resource.getString("TestMain.hx") ); - strings.push( "some string" ); - var chars = "abc123"; - // Optimization for single chars... - for(c in 0...chars.length) - strings.push( chars.substr(c,1) ); - for(string in strings) - assertTrue( untyped __global__.__hxcpp_is_const_string(string) ); - Gc.run(true); - for(string in strings) - assertTrue( untyped __global__.__hxcpp_is_const_string(string) ); + // Const strings void Gc overhead + var strings = new Array(); + strings.push( haxe.Resource.getString("TestMain.hx") ); + strings.push( "some string" ); + var chars = "abc123"; + // Optimization for single chars... + for(c in 0...chars.length) + strings.push( chars.substr(c,1) ); + for(string in strings) + Assert.isTrue( untyped __global__.__hxcpp_is_const_string(string) ); + Gc.run(true); + for(string in strings) + Assert.isTrue( untyped __global__.__hxcpp_is_const_string(string) ); - var strings = new Array(); - strings.push( haxe.Resource.getString("TestMain.hx").substr(10) ); - strings.push( "some string" + chars ); - for(c in 0...chars.length-1) - strings.push( chars.substr(c,2) ); + var strings = new Array(); + strings.push( haxe.Resource.getString("TestMain.hx").substr(10) ); + strings.push( "some string" + chars ); + for(c in 0...chars.length-1) + strings.push( chars.substr(c,2) ); - for(string in strings) - assertFalse( untyped __global__.__hxcpp_is_const_string(string) ); + for(string in strings) + Assert.isFalse( untyped __global__.__hxcpp_is_const_string(string) ); } #end } diff --git a/test/haxe/gc/TestGCThreaded.hx b/test/haxe/gc/TestGCThreaded.hx index f35c686a3..00eab6bae 100644 --- a/test/haxe/gc/TestGCThreaded.hx +++ b/test/haxe/gc/TestGCThreaded.hx @@ -1,4 +1,7 @@ package gc; + +import utest.Test; +import utest.Assert; import haxe.io.Bytes; import haxe.crypto.Md5; import cpp.vm.Gc; @@ -18,7 +21,7 @@ class Wrapper @:cppInclude("./ZoneTest.cpp") @:depend("./ZoneTest.cpp") -class TestGCThreaded extends haxe.unit.TestCase +class TestGCThreaded extends Test { @:keep static var keepRunning = false; @@ -27,7 +30,7 @@ class TestGCThreaded extends haxe.unit.TestCase var bigText:String; - override public function setup() + function setup() { var lines = [ for(i in 0...100000) "abc123\n" ]; #if nme @@ -42,10 +45,9 @@ class TestGCThreaded extends haxe.unit.TestCase startNative(); doThreadedWork(4,100); stopNative(); - assertTrue(true); + Assert.pass(); } - public function testThreadMany():Void { startNative(); @@ -56,7 +58,7 @@ class TestGCThreaded extends haxe.unit.TestCase doThreadedWork(100,100); #end stopNative(); - assertTrue(true); + Assert.pass(); } @:native("nativeLoop") @@ -122,7 +124,7 @@ class TestGCThreaded extends haxe.unit.TestCase for(w in a) sum += w.a; - assertTrue(sum==100000); + Assert.equals(100000, sum); } main.sendMessage('done'); }) ); diff --git a/test/haxe/native/TestFinalizer.hx b/test/haxe/native/TestFinalizer.hx index e7997bd2e..8d057e2ec 100644 --- a/test/haxe/native/TestFinalizer.hx +++ b/test/haxe/native/TestFinalizer.hx @@ -1,5 +1,8 @@ package native; +import utest.Test; +import utest.Assert; + @:native("ExternStruct") extern class ExternStruct { @@ -78,10 +81,10 @@ class MyFinalizable extends cpp.Finalizable } -class TestFinalizer extends haxe.unit.TestCase +class TestFinalizer extends Test { - override public function setup() + function setup() { MyFinalizable.count = 0; CustomFinalizable.count = 0; @@ -105,7 +108,7 @@ class TestFinalizer extends haxe.unit.TestCase cpp.vm.Gc.run(true); } Sys.println("\nExtern instances remaining:" + ExternWrapper.instances); - assertTrue( ExternWrapper.instances < 10 ); + Assert.isTrue( ExternWrapper.instances < 10 ); } function createCustomFinalizable(i:Int) @@ -123,7 +126,7 @@ class TestFinalizer extends haxe.unit.TestCase createCustomFinalizable(2); cpp.vm.Gc.run(true); Sys.println("custom cleared:" + CustomFinalizable.count); - assertTrue(CustomFinalizable.count>0); + Assert.isTrue(CustomFinalizable.count>0); } #end @@ -142,7 +145,7 @@ class TestFinalizer extends haxe.unit.TestCase createMyFinalizable(2); cpp.vm.Gc.run(true); Sys.println("MyFinalizable cleared:" + MyFinalizable.count); - assertTrue(MyFinalizable.count>0); + Assert.isTrue(MyFinalizable.count>0); } } diff --git a/test/native/Native.hx b/test/native/Native.hx index 4ed17f136..acab7aada 100644 --- a/test/native/Native.hx +++ b/test/native/Native.hx @@ -3,19 +3,16 @@ package; class Native { static function main() - { - var r = new haxe.unit.TestRunner(); - r.add(new tests.TestStdio()); - r.add(new tests.TestRgb()); - r.add(new tests.TestRectangle()); - r.add(new tests.TestGlobalNamespace()); - r.add(new tests.TestNativeGen()); - r.add(new tests.TestNonVirtual()); - r.add(new tests.TestPtr()); - r.add(new tests.TestNativeEnum()); - var t0 = haxe.Timer.stamp(); - var success = r.run(); - trace(" Time : " + (haxe.Timer.stamp()-t0)*1000 ); - Sys.exit(success ? 0 : 1); + { + utest.UTest.run([ + new tests.TestStdio(), + new tests.TestRgb(), + new tests.TestRectangle(), + new tests.TestGlobalNamespace(), + new tests.TestNativeGen(), + new tests.TestNonVirtual(), + new tests.TestPtr(), + new tests.TestNativeEnum() + ]); } } diff --git a/test/native/compile.hxml b/test/native/compile.hxml index 090ccbd2d..b2e405bb7 100644 --- a/test/native/compile.hxml +++ b/test/native/compile.hxml @@ -1,4 +1,4 @@ --cpp bin --main Native +-m Native -D HXCPP_DEBUGGER --cp ../unit +-L utest +--cpp bin \ No newline at end of file diff --git a/test/native/tests/TestGlobalNamespace.hx b/test/native/tests/TestGlobalNamespace.hx index a74ef609b..1a76e4841 100755 --- a/test/native/tests/TestGlobalNamespace.hx +++ b/test/native/tests/TestGlobalNamespace.hx @@ -1,12 +1,15 @@ package tests; -class TestGlobalNamespace extends haxe.unit.TestCase +import utest.Test; +import utest.Assert; + +class TestGlobalNamespace extends Test { var shortPtr:externs.ShortPtr; public function testGen() { - assertTrue(true); + Assert.pass(); } } diff --git a/test/native/tests/TestNativeEnum.hx b/test/native/tests/TestNativeEnum.hx index 1357d7118..286b7d1a3 100644 --- a/test/native/tests/TestNativeEnum.hx +++ b/test/native/tests/TestNativeEnum.hx @@ -1,5 +1,8 @@ package tests; +import utest.Test; +import utest.Assert; + // Uses native enum, which does not play nice with Dynamic - must use @:unreflective @:unreflective #if (haxe_ver >= 4.0) extern enum #else @:extern @:enum #end abstract SystemMetric(SystemMetricImpl) { @@ -27,7 +30,7 @@ enum wxSystemMetric wxSYS_MOUSE_BUTTONS = 27, }; ') -class TestNativeEnum extends haxe.unit.TestCase +class TestNativeEnum extends Test { var x:SystemMetric = SystemMetric.MOUSE_BUTTONS; var xStruct:SystemMetricStruct = SystemMetricStruct.MOUSE_BUTTONS; @@ -45,19 +48,19 @@ class TestNativeEnum extends haxe.unit.TestCase public function test() { - assertTrue( isX(SystemMetric.MOUSE_BUTTONS)==true ); - assertTrue( isX(SystemMetric.OS)==false ); - assertTrue( isXStruct(SystemMetricStruct.MOUSE_BUTTONS)==true ); - assertTrue( isXStruct(SystemMetricStruct.OS)==false ); + Assert.isTrue( isX(SystemMetric.MOUSE_BUTTONS)==true ); + Assert.isTrue( isX(SystemMetric.OS)==false ); + Assert.isTrue( isXStruct(SystemMetricStruct.MOUSE_BUTTONS)==true ); + Assert.isTrue( isXStruct(SystemMetricStruct.OS)==false ); var d:Dynamic = this; - assertTrue( d.x==null ); - assertTrue( d.xStruct!=null ); - assertTrue( d.isX==null ); - assertTrue( d.isXStruct!=null ); - var func = d.isXStruct; - assertTrue(func!=null); - assertTrue(func(SystemMetricStruct.MOUSE_BUTTONS)==true ); - assertTrue(func(SystemMetricStruct.OS)==false ); + Assert.isNull( d.x ); + Assert.notNull( d.xStruct ); + Assert.isNull( d.isX ); + Assert.notNull( d.isXStruct ); + var func: (SystemMetricStruct)->Bool = d.isXStruct; + Assert.notNull(func); + Assert.isTrue(func(SystemMetricStruct.MOUSE_BUTTONS)==true ); + Assert.isTrue(func(SystemMetricStruct.OS)==false ); } } diff --git a/test/native/tests/TestNativeGen.hx b/test/native/tests/TestNativeGen.hx index aaef2b71c..6b89897a4 100644 --- a/test/native/tests/TestNativeGen.hx +++ b/test/native/tests/TestNativeGen.hx @@ -1,8 +1,10 @@ package tests; import NativeGen; +import utest.Test; +import utest.Assert; -class TestNativeGen extends haxe.unit.TestCase +class TestNativeGen extends Test { @:unreflective var unreflectiveValue:NativeGen; @@ -16,8 +18,7 @@ class TestNativeGen extends haxe.unit.TestCase { var nGen:NativeGenStruct = null; nGen.x = 22; - assertTrue(nGen.getValue()==22); - - assertTrue(unreflectiveFunction(nGen) ); + Assert.equals(22f64, nGen.getValue()); + Assert.isTrue(unreflectiveFunction(nGen)); } } diff --git a/test/native/tests/TestNonVirtual.hx b/test/native/tests/TestNonVirtual.hx index 71732144a..c1c7c623c 100644 --- a/test/native/tests/TestNonVirtual.hx +++ b/test/native/tests/TestNonVirtual.hx @@ -1,5 +1,8 @@ package tests; +import utest.Test; +import utest.Assert; + class Base { public function new() {} @@ -16,22 +19,22 @@ class Derived extends Base } -class TestNonVirtual extends haxe.unit.TestCase +class TestNonVirtual extends Test { public function testOverride() { var derived = new Derived(); - assertTrue( derived.getName() == "Derived" ); - assertTrue( derived.getNvName() == "Derived" ); + Assert.equals( "Derived", derived.getName() ); + Assert.equals( "Derived", derived.getNvName() ); var closure:Dynamic = derived.getNvName; - assertTrue( closure() == "Derived" ); + Assert.equals( "Derived", closure() ); var base:Base = derived; - assertTrue( base.getName() == "Derived" ); - assertTrue( base.getNvName() == "Base" ); + Assert.equals( "Derived", base.getName()); + Assert.equals( "Base", base.getNvName() ); var closure:Dynamic = base.getNvName; - assertTrue( closure() == "Base" ); + Assert.equals( "Base", closure() ); } } diff --git a/test/native/tests/TestPtr.hx b/test/native/tests/TestPtr.hx index c58253925..cbbfa8905 100644 --- a/test/native/tests/TestPtr.hx +++ b/test/native/tests/TestPtr.hx @@ -1,5 +1,7 @@ package tests; +import utest.Test; +import utest.Assert; import NativeGen; import cpp.NativeGc; import cpp.Stdlib; @@ -92,8 +94,8 @@ struct CVec{ @:cppFileCode(' int callPointer(CVec *) { return 5; } ') -class TestPtr extends haxe.unit.TestCase{ - +class TestPtr extends Test +{ /* Alternate version @:generic @@ -105,10 +107,10 @@ class TestPtr extends haxe.unit.TestCase{ public function testMalloc() { var a : Pointer = Stdlib.malloc( Stdlib.sizeof(Vec) ); - assertTrue( a!=null ); - assertTrue( a.raw!=null ); + Assert.notNull( a ); + Assert.notNull( a.raw ); a.ptr.x = 66; - assertTrue( a.ptr.x == 66 ); + Assert.equals( 66f64, a.ptr.x ); Stdlib.free(a); } @@ -118,7 +120,7 @@ class TestPtr extends haxe.unit.TestCase{ for(i in 0...5) a.setAt(i,i); for(i in 0...5) - assertTrue( a.postIncRef() == i ); + Assert.equals( i, a.postIncRef() ); } function test9194() { @@ -132,20 +134,20 @@ class TestPtr extends haxe.unit.TestCase{ var floatBuffer: cpp.Star = cast buffer; // generates correct: float* floatBuffer = ( (float*) buffer ) - assertTrue(floatBuffer==null); + Assert.isNull(floatBuffer); } public function testNull() { var nullP : Pointer = null; var nullRawP = nullP.raw; - assertTrue( nullP==null ); - assertTrue( null==nullP ); - assertFalse( nullP!=null ); - assertTrue( nullRawP==null ); - assertFalse( nullRawP!=null ); + Assert.isTrue( nullP==null ); + Assert.isTrue( null==nullP ); + Assert.isFalse( nullP!=null ); + Assert.isTrue( nullRawP==null ); + Assert.isFalse( nullRawP!=null ); nullRawP = null; - assertTrue( nullRawP==null ); + Assert.isTrue( nullRawP==null ); } private function anonOf(d:Dynamic) : Dynamic return {ptr:d}; @@ -155,34 +157,34 @@ class TestPtr extends haxe.unit.TestCase{ var tmp = e.ptr; var tmp1 = e.ref; tmp.set99(tmp1); - assertTrue(e.ptr.x==99); + Assert.equals(99f64, e.ptr.x); } - @:native("callPointer") @:extern - private static function callPointer(ptr:cpp.Pointer):Int; + @:native("callPointer") + extern private static function callPointer(ptr:cpp.Pointer):Int; public function testPointerCast() { var map = new Map >(); map.set(1,null); var result = callPointer( map.get(2) ); - assertTrue(result==5); + Assert.equals(5, result); } public function testDynamic() { var a = [1]; var intPtr = a.address(0); var d:Dynamic = intPtr; - assertFalse(d==[2].address(0)); - assertTrue(d==a.address(0)); + Assert.notEquals(d, [2].address(0)); + Assert.equals(d, a.address(0)); var anon = anonOf(d); - assertFalse([2].address(0)==d); - assertTrue(a.address(0)==d); - assertFalse(intPtr==[2].address(0)); - assertTrue(intPtr==a.address(0)); - assertFalse(anon.ptr==[2].address(0)); - assertTrue(anon.ptr==a.address(0)); - assertFalse([2].address(0)==anon.ptr); - assertTrue(a.address(0)==anon.ptr); + Assert.notEquals([2].address(0), d); + Assert.equals(a.address(0), d); + Assert.notEquals(intPtr, [2].address(0)); + Assert.equals(intPtr, a.address(0)); + Assert.notEquals(anon.ptr, [2].address(0)); + Assert.equals(anon.ptr, a.address(0)); + Assert.notEquals([2].address(0), anon.ptr); + Assert.equals(a.address(0), anon.ptr); } function getAnonI(a:Dynamic) : Dynamic @@ -195,16 +197,16 @@ class TestPtr extends haxe.unit.TestCase{ var a = [1]; var intPtr = a.address(0); var anon = { i:intPtr }; - assertTrue( getAnonI(anon)==intPtr ); + Assert.equals( getAnonI(anon), intPtr ); var vecPtr = VecStructAccess.create(1); var anon = { i:vecPtr }; - assertTrue( getAnonI(anon)==vecPtr ); + Assert.equals( getAnonI(anon), vecPtr ); var vec:VecStruct = null; vec.x = 123; var anon = { i:vec }; - assertTrue( getAnonI(anon)==vec ); + Assert.equals( getAnonI(anon), vec ); } static function callMe(x:Int) return 10+x; @@ -212,102 +214,94 @@ class TestPtr extends haxe.unit.TestCase{ static function notProcAddress(module:String, func:String) return null; public function testArrayAccess() { - var array = [ 0.0, 1.1, 2.2, 3.3 ]; - var ptr = cpp.Pointer.arrayElem(array, 0); - assertTrue( ptr[1]==1.1 ); - ptr[1] = 2; - assertTrue( ptr[1]==2 ); - ptr[1]++; - assertTrue( ptr[1]==3 ); - ptr[1]-=2.5; - assertTrue( ptr[1]==0.5 ); - - var raw = ptr.raw; - assertTrue( raw[2]==2.2 ); - raw[2] = 2; - assertTrue( raw[2]==2 ); - raw[2]++; - assertTrue( raw[2]==3 ); - raw[2]-=2.5; - assertTrue( raw[2]==0.5 ); - + var array = [ 0.0, 1.1, 2.2, 3.3 ]; + var ptr = cpp.Pointer.arrayElem(array, 0); + Assert.equals( ptr[1], 1.1 ); + ptr[1] = 2; + Assert.equals( ptr[1], 2 ); + ptr[1]++; + Assert.equals( ptr[1], 3 ); + ptr[1]-=2.5; + Assert.equals( ptr[1], 0.5 ); + + var raw = ptr.raw; + Assert.equals( raw[2], 2.2 ); + raw[2] = 2; + Assert.equals( raw[2], 2 ); + raw[2]++; + Assert.equals( raw[2], 3 ); + raw[2]-=2.5; + Assert.equals( raw[2], 0.5 ); } public function testFromRaw() { var i = new IntHolder(3); var ptr = cpp.Pointer.fromRaw(cpp.Pointer.addressOf(i).rawCast()); - assertTrue( ptr.ref.ival==i.ival ); + Assert.equals( ptr.ref.ival, i.ival ); ptr.ref.ival==23; - assertTrue( ptr.ref.ival==i.ival ); + Assert.equals( ptr.ref.ival, i.ival ); + } + + private static var output:cpp.Pointer>; + + private static var arrayValue:Array; + private static function makeValue():{ a:cpp.Pointer> } + { + arrayValue = [9]; + return { a: cpp.Pointer.addressOf(arrayValue) }; } - private static var output:cpp.Pointer>; - - private static var arrayValue:Array; - private static function makeValue():{ a:cpp.Pointer> } - { - arrayValue = [9]; - return { a: cpp.Pointer.addressOf(arrayValue) }; - } - - @:analyzer(no_fusion) - public function testDynamicOutput() - { - // Declared as structure (just `var val = ...` works too) - var val:{ a:cpp.Pointer> } = makeValue(); - - var a:cpp.Pointer> = val.a; - output = a; - output = (val.a:Dynamic); - output = val.a; - output = (val.a:cpp.Pointer>); - val.a = output; - - // Declared as Dynamic - var val2:Dynamic = makeValue(); - a = val2.a; - output = a; - output = (val2.a:Dynamic); - output = val2.a; - output = (val2.a:cpp.Pointer>); - val2.a = output; - assertTrue( val2.a==output ); - assertTrue( output==val.a ); - } + @:analyzer(no_fusion) + public function testDynamicOutput() + { + // Declared as structure (just `var val = ...` works too) + var val:{ a:cpp.Pointer> } = makeValue(); + + var a:cpp.Pointer> = val.a; + output = a; + output = (val.a:Dynamic); + output = val.a; + output = (val.a:cpp.Pointer>); + val.a = output; + + // Declared as Dynamic + var val2:Dynamic = makeValue(); + a = val2.a; + output = a; + output = (val2.a:Dynamic); + output = val2.a; + output = (val2.a:cpp.Pointer>); + val2.a = output; + Assert.equals( val2.a, output ); + Assert.equals( output, val.a ); + } public function testAutoCast() { - var z = [ 1, 2, 3 ]; - assertTrue( cpp.NativeArray.address(z, 0).ptr == cpp.NativeArray.address(z, 0).ptr ); - assertTrue( cpp.NativeArray.address(z, 1).ptr != cpp.NativeArray.address(z, 0).ptr ); - assertTrue( cpp.NativeArray.address(z, 1).gt(cpp.NativeArray.address(z, 0)) ); - assertTrue( cpp.NativeArray.address(z, 1).geq(cpp.NativeArray.address(z, 0)) ); - assertTrue( cpp.NativeArray.address(z, 1).geq(cpp.NativeArray.address(z, 1)) ); - assertTrue( cpp.NativeArray.address(z, 0).leq(cpp.NativeArray.address(z, 0)) ); - assertTrue( cpp.NativeArray.address(z, 1).leq(cpp.NativeArray.address(z, 2)) ); - assertTrue( cpp.NativeArray.address(z, 1).leq(cpp.NativeArray.address(z, 2)) ); - assertTrue( cpp.NativeArray.address(z, 0) == cpp.Pointer.ofArray(z) ); - assertTrue( cpp.NativeArray.address(z, 1) == cpp.Pointer.arrayElem(z,1) ); - assertTrue( cpp.NativeArray.address(z, 1) != cpp.Pointer.fromHandle(null) ); - assertTrue( cpp.Function.fromStaticFunction(callMe)(1)==11 ); - try - { - assertTrue( cpp.Function.fromStaticFunction(notProcAddress)!=cpp.Function.getProcAddress("nomodule","nofunc!") ); - } - catch(e:Dynamic) - { - // Could not load module - expected - } + var z = [ 1, 2, 3 ]; + Assert.isTrue( cpp.NativeArray.address(z, 0).ptr == cpp.NativeArray.address(z, 0).ptr ); + Assert.isTrue( cpp.NativeArray.address(z, 1).ptr != cpp.NativeArray.address(z, 0).ptr ); + Assert.isTrue( cpp.NativeArray.address(z, 1).gt(cpp.NativeArray.address(z, 0)) ); + Assert.isTrue( cpp.NativeArray.address(z, 1).geq(cpp.NativeArray.address(z, 0)) ); + Assert.isTrue( cpp.NativeArray.address(z, 1).geq(cpp.NativeArray.address(z, 1)) ); + Assert.isTrue( cpp.NativeArray.address(z, 0).leq(cpp.NativeArray.address(z, 0)) ); + Assert.isTrue( cpp.NativeArray.address(z, 1).leq(cpp.NativeArray.address(z, 2)) ); + Assert.isTrue( cpp.NativeArray.address(z, 1).leq(cpp.NativeArray.address(z, 2)) ); + Assert.equals( cpp.NativeArray.address(z, 0), cpp.Pointer.ofArray(z) ); + Assert.equals( cpp.NativeArray.address(z, 1), cpp.Pointer.arrayElem(z,1) ); + Assert.notEquals( cpp.NativeArray.address(z, 1), cpp.Pointer.fromHandle(null) ); + Assert.equals(11, cpp.Function.fromStaticFunction(callMe)(1)); + Assert.exception(() -> cpp.Function.fromStaticFunction(notProcAddress)!=cpp.Function.getProcAddress("nomodule","nofunc!"), String); } static function functionCaller(fn:cpp.FunctionInt,cpp.abi.Abi>) { - var a = fn.call(); - } + var a = fn.call(); + } public function testFunctionStructAccess() { - assertTrue( functionCaller != null ); + Assert.notNull( functionCaller ); } public function testSetData() { @@ -315,47 +309,47 @@ class TestPtr extends haxe.unit.TestCase{ ss.dataLength = 4; ss.data = cast "bye!".c_str(); var b = ss.getDataBytes(); - assertTrue( b.getString(0, b.length) == "bye!" ); + Assert.equals( "bye!", b.getString(0, b.length) ); var ss:SomeStruct = null; var b = ss.getUnmanagedDataBytes(); - assertTrue( b.getString(0, b.length) == "Hi!" ); + Assert.equals( "Hi!", b.getString(0, b.length) ); } public function testZero() { var a = [1,2,3]; a.zero(); - assertTrue(a.length==3); - assertTrue(a[0]==0); - assertTrue(a[1]==0); - assertTrue(a[2]==0); + Assert.equals(3, a.length); + Assert.equals(0, a[0]); + Assert.equals(0, a[1]); + Assert.equals(0, a[2]); } public function testMemcmp() { var a = [1,2,3]; var b = [2,2,3]; - assertTrue( a.memcmp(b) == -1 ); - assertTrue( b.memcmp(a) == 1 ); - assertTrue( a.memcmp(a) == 0 ); + Assert.equals( -1, a.memcmp(b)); + Assert.equals( 1, b.memcmp(a) ); + Assert.equals( 0, a.memcmp(a) ); } public function testCapacity() { var a = [1,2,3]; - assertTrue( a.capacity() < 1000 ); + Assert.isTrue( a.capacity() < 1000 ); a.reserve(1000); - assertTrue( a.capacity() == 1000 ); + Assert.equals( 1000, a.capacity() ); a[1000] = 1; - assertTrue( a.capacity() > 1000 ); + Assert.isTrue( a.capacity() > 1000 ); } public function testElementSize() { var a = [1]; - assertTrue( a.getElementSize() == cpp.Stdlib.sizeof(Int) ); + Assert.equals( cpp.Stdlib.sizeof(Int), a.getElementSize() ); var a = ["hello!"]; - assertTrue( a.getElementSize() == cpp.Stdlib.sizeof(String) ); + Assert.equals( cpp.Stdlib.sizeof(String), a.getElementSize() ); var a = [7.1]; - assertTrue( a.getElementSize() == cpp.Stdlib.sizeof(Float) ); + Assert.equals( cpp.Stdlib.sizeof(Float), a.getElementSize() ); } @@ -364,15 +358,15 @@ class TestPtr extends haxe.unit.TestCase{ var b = [0,0,0,0]; b.blit(0,a,0,a.length); for(i in 0...4) - assertTrue(b[i] == a[i]); + Assert.equals(b[i], a[i]); for(i in 0...4) b.blit(i,a,0,1); for(i in 0...4) - assertTrue(b[i] == a[0]); + Assert.equals(b[i], a[0]); for(i in 0...4) b.blit(i,a,2,1); for(i in 0...4) - assertTrue(b[i] == a[2]); + Assert.equals(b[i], a[2]); } } diff --git a/test/native/tests/TestRectangle.hx b/test/native/tests/TestRectangle.hx index 4f2526d44..87be46350 100755 --- a/test/native/tests/TestRectangle.hx +++ b/test/native/tests/TestRectangle.hx @@ -1,7 +1,10 @@ package tests; + +import utest.Test; +import utest.Assert; import externs.Rectangle; -class TestRectangle extends haxe.unit.TestCase +class TestRectangle extends Test { static var statRect:Rectangle; static var statRectPtr:RectanglePtr; @@ -31,13 +34,13 @@ class TestRectangle extends haxe.unit.TestCase { // Struct - copy semantic var rectangle = Rectangle.make(3,4); - assertTrue( rectangle.area()==0 ); + Assert.equals( 0, rectangle.area() ); var rect2 = rectangle; rect2.width = 2; rect2.height = 4; - assertTrue( rect2.area()==8 ); - assertTrue( rectangle.area()==0 ); + Assert.equals( 8, rect2.area() ); + Assert.equals( 0, rectangle.area() ); // Take address ... @@ -48,23 +51,23 @@ class TestRectangle extends haxe.unit.TestCase rectPtr.height = 5; var dynamicPtr:Dynamic = rectPtr; - assertTrue( rectPtr.area()==15 ); + Assert.equals( 15, rectPtr.area() ); // Same object - assertTrue( rectangle.area()==15 ); + Assert.equals( 15, rectangle.area() ); var dynamicCopy:Dynamic = rectangle; // 3,4 3x5 rectangle.width = 10; rectangle.height = 10; - assertTrue( rectangle.area()==100 ); + Assert.equals( 100, rectangle.area() ); // points to original object var fromDynamic:RectanglePtr = rectPtr; - assertTrue( fromDynamic.area()==100 ); + Assert.equals( 100, fromDynamic.area() ); // Restore from Dynamic ... rectangle = dynamicCopy; - assertTrue( rectangle.area()==15 ); + Assert.equals( 15, rectangle.area() ); } public function testReflect() @@ -76,26 +79,26 @@ class TestRectangle extends haxe.unit.TestCase statRectPtr = Rectangle.create(1,1,2,2); memRectPtr = statRect; - assertTrue( statRectProp.area()==12 ); - assertTrue( memRectProp.area()==42 ); - assertTrue( statRectPtrProp.area()==4 ); - assertTrue( memRectPtrProp.area()==12 ); + Assert.equals( statRectProp.area(), 12 ); + Assert.equals( memRectProp.area(), 42 ); + Assert.equals( statRectPtrProp.area(), 4 ); + Assert.equals( memRectPtrProp.area(), 12 ); var d:Dynamic = this; var r:Rectangle = d.memRect; - assertTrue( r.area()==42 ); + Assert.equals( r.area(), 42 ); var prop:Rectangle = Reflect.getProperty(d,"memRectProp"); - assertTrue( prop.area()==42 ); + Assert.equals( prop.area(), 42 ); var propPtr:RectanglePtr = Reflect.getProperty(d,"memRectPtrProp"); - assertTrue( propPtr.area()==12 ); + Assert.equals( propPtr.area(), 12 ); var d:Dynamic = TestRectangle; var r:Rectangle = d.statRect; - assertTrue( r.area()==12 ); + Assert.equals( r.area(), 12 ); var prop:Rectangle = Reflect.getProperty(d,"statRectProp"); - assertTrue( prop.area()==12 ); + Assert.equals( prop.area(), 12 ); var propPtr:RectanglePtr = Reflect.getProperty(d,"statRectPtrProp"); - assertTrue( propPtr.area()==4 ); + Assert.equals( propPtr.area(), 4 ); // No longer valid diff --git a/test/native/tests/TestRgb.hx b/test/native/tests/TestRgb.hx index d79ee36c2..6541b216d 100644 --- a/test/native/tests/TestRgb.hx +++ b/test/native/tests/TestRgb.hx @@ -1,13 +1,16 @@ package tests; + +import utest.Test; +import utest.Assert; import externs.RGB; -class TestRgb extends haxe.unit.TestCase +class TestRgb extends Test { public function testCreate() { // Pointer-like sysntax var rgbPtr = RGB.create(255,0,128); - assertTrue( rgbPtr.ptr.toInt() == 0xff0080 ); + Assert.equals( rgbPtr.ptr.toInt(), 0xff0080 ); rgbPtr.ptr.deleteMe(); @@ -18,35 +21,35 @@ class TestRgb extends haxe.unit.TestCase rgbStruct.r = 1; rgbStruct.g = 2; rgbStruct.b = 3; - assertTrue( rgbStruct.toInt() == 0x010203 ); + Assert.equals( rgbStruct.toInt(), 0x010203 ); // Store in dynamic var d:Dynamic = rgbStruct; // Reference (pointer) like syntax var rgbRef:RGBRef = rgbStruct; rgbRef.g = 255; - assertTrue( rgbStruct.toInt() == 0x01ff03 ); + Assert.equals( rgbStruct.toInt(), 0x01ff03 ); // Get from dynamic rgbStruct = d; - assertTrue( rgbStruct.toInt() == 0x010203 ); + Assert.equals( rgbStruct.toInt(), 0x010203 ); var rgbStruct2:RGBStruct = cast rgbRef; - assertTrue( rgbStruct2.toInt() == 0x010203 ); + Assert.equals( rgbStruct2.toInt(), 0x010203 ); // Reference refers to rgbStruct, not rgbStruct2 rgbRef.b = 0; - assertTrue( rgbStruct2.toInt() == 0x010203 ); - assertTrue( rgbStruct.toInt() == 0x010200 ); + Assert.equals( rgbStruct2.toInt(), 0x010203 ); + Assert.equals( rgbStruct.toInt(), 0x010200 ); // TODO - non-dynamic versions var d2:Dynamic = rgbStruct2; // == dynamic - assertTrue( d2==d ); + Assert.equals( d2, d ); // != dynamic var d0:Dynamic = rgbStruct; - assertTrue( d0!=d ); + Assert.notEquals( d0, d ); } } diff --git a/test/native/tests/TestStdio.hx b/test/native/tests/TestStdio.hx index 4480f4abb..cc3a5bfa4 100644 --- a/test/native/tests/TestStdio.hx +++ b/test/native/tests/TestStdio.hx @@ -1,8 +1,12 @@ package tests; + +import utest.Test; +import utest.Assert; import cpp.Stdio; + using cpp.NativeArray; -class TestStdio extends haxe.unit.TestCase +class TestStdio extends Test { public function test() { @@ -16,7 +20,7 @@ class TestStdio extends haxe.unit.TestCase var input = new haxe.io.BytesInput(bytes); var val = input.readInt32(); - assertTrue(val==ints[0]); + Assert.equals(val, ints[0]); } } diff --git a/test/std/Test.hx b/test/std/Test.hx index ca874d2ea..e505926da 100644 --- a/test/std/Test.hx +++ b/test/std/Test.hx @@ -16,7 +16,6 @@ import sys.io.FileSeek; import sys.net.Host; import sys.net.Socket; import sys.net.UdpSocket; -import sys.net.UdpSocket; import sys.io.Process; #if haxe4 @@ -30,6 +29,8 @@ import cpp.vm.Thread; using cpp.NativeArray; using cpp.AtomicInt; +import utest.Assert; + @:buildXml('') extern class SslTest { @@ -37,15 +38,14 @@ extern class SslTest extern public static function socket_init():Void; } -class Test +class Test extends utest.Test { - static var errors = new Array(); - static var lastErrorCount = 0; - var x:Int; public function new() { + super(); + x = 1; } @@ -59,28 +59,6 @@ class Test Sys.println(" " + t); } - public static function ok() - { - if (lastErrorCount==errors.length) - { - v("ok"); - return 0; - } - else - { - lastErrorCount=errors.length; - v("bad"); - return 1; - } - } - - public static function error(e:String) - { - Sys.println("Test Failed:" + e); - errors.push(e); - return -1; - } - public static function thisFile() { #if nme_install_tool @@ -91,7 +69,7 @@ class Test return bytes; } - public static function testDb(cnx:Connection) : Int + function implTestDb(cnx:Connection) : Int { v("connected :" + cnx); if (cnx.dbName() == "SQLite") { @@ -116,8 +94,7 @@ class Test )"); } var dels = cnx.request("DELETE FROM UserPwd"); - if (dels.nfields != 0) - return error("Bad DELETE'd result"); + Assert.equals(0, dels.nfields, "Bad DELETE'd result"); v("deleted " + dels.length + " existing rows"); cnx.request("INSERT INTO UserPwd (name,age,money,password) VALUES ('John',32,100.45,X'c0ffee')"); @@ -127,16 +104,14 @@ class Test var length = rset.length; v("found "+length+" users"); - if (length!=2) - return error("Bad user count"); + Assert.equals(2, length, "Bad user count"); for( row in rset ) { var pass:Dynamic = row.password; var password = Std.isOfType(pass, haxe.io.BytesData) ? haxe.io.Bytes.ofData(pass) : pass; var md5 = haxe.crypto.Md5.make(password).toHex().substr(0,8); v(" user "+row.name+" is "+row.age+" years old, password:" + md5); - if (md5!="5f80e231" && md5!="8ed0b363") - return error("Bad binary blob store"); + Assert.isFalse(md5!="5f80e231" && md5!="8ed0b363", "Bad binary blob store"); } return 0; } @@ -148,54 +123,39 @@ class Test v(Std.string(now)); var then = Date.fromString("1977-06-11"); v(Std.string(then)); - if (now.getTime()<=then.getTime()) - return error("Date fromString - time travel"); + + Assert.isFalse(now.getTime()<=then.getTime(), "Date fromString - time travel"); var later = DateTools.makeUtc(1996,5,4,17,55,11); v(Std.string(later)); var diff:Float = untyped __global__.__hxcpp_timezone_offset(now.mSeconds); v("timezone offet:" + diff); - - return ok(); } - public static function testCompress() + function testCompress() { log("Test compress"); - var bytes = thisFile(); + final bytes = thisFile(); - var compress = new Compress(9); + final compress = new Compress(9); compress.setFlushMode(FlushMode.FINISH); - var buffer = haxe.io.Bytes.alloc(bytes.length * 2 + 100); - var r = compress.execute(bytes,0,buffer,0); + final buffer = haxe.io.Bytes.alloc(bytes.length * 2 + 100); + final r = compress.execute(bytes,0,buffer,0); compress.close(); - var compressed = buffer.sub(0,r.write); + final compressed = buffer.sub(0,r.write); v("compressed size " + compressed.length ); v("try closing too many times..."); - var caughtError = false; - try - { - compress.close(); - } - catch(e:Dynamic) - { - v("correctly caught " + e ); - caughtError = true; - } - if (!caughtError) - error("Zlib closed without throwing error"); + Assert.exception(() -> compress.close(), String, null, "Zlib closed without throwing error"); var decompressed = Uncompress.run(compressed); v("decompressed size:" + decompressed.length + "/" + bytes.length); - if (decompressed.compare(bytes)!=0) - return error("Compress/Uncompress mismatch"); - return ok(); + Assert.equals(0, decompressed.compare(bytes), "Compress/Uncompress mismatch"); } - public static function testRegexp() + function testRegexp() { log("Test Regexp/BytesInput"); @@ -211,13 +171,12 @@ class Test try { while(true) { - var line = input.readLine(); + final line = input.readLine(); if (match.match(line)) { - var xml = Xml.parse(line.substr(5)); + final xml = Xml.parse(line.substr(5)); v("found xml:" + xml.firstElement().get("value")); - if (xml.firstElement().get("value")!="Hello World!") - return error("Bad universal greeting"); + Assert.equals("Hello World!", xml.firstElement().get("value")); } if (utf8Match.match(line)) { @@ -226,38 +185,32 @@ class Test } } } catch (e:Dynamic) { } - if (!success) - return error("Could not find success in utf8 code"); - return ok(); + + Assert.isTrue(success, "Could not find success in utf8 code"); } - public static function testRegexpMixedUnicode() { + function testRegexpMixedUnicode() { var success = true; // when matching a utf8 subject string against a utf16 pattern and vice versa for (pattern => subject in ["[A-Za-zÀ-ÖØ-öø-ÿ0-9]+" => "a", "[A-Z]+" => "ÀÖA"]) { - if (new EReg(pattern, "").match(subject)) { - v('"$subject" matches against ~/$pattern/'); - } else { - return error('"$subject" does not match against ~/$pattern/'); - } + Assert.isTrue(new EReg(pattern, "").match(subject), '"$subject" does not match against ~/$pattern/'); } - return ok(); } - public static function testSqlite() + function testSqlite() { log("Test sqlite"); - var dbFile = "hxcpp.db"; - var cnx = Sqlite.open(dbFile); - if (testDb(cnx)!=0) - return error("db error"); + final dbFile = "hxcpp.db"; + final cnx = Sqlite.open(dbFile); + + Assert.equals(0, implTestDb(cnx)); + cnx.close(); - return ok(); } - public static function testMysql() + function testMysql() { log("Test mysql"); var cnx:sys.db.Connection = null; @@ -280,37 +233,40 @@ class Test if (cnx!=null) { - if (testDb(cnx)!=0) - error("TestDB failed"); + Assert.equals(0, implTestDb(cnx)); + cnx.close(); } - return ok(); + else + { + Assert.pass(); + } } - public static function testRandom() + function testRandom() { log("Test Random"); - var rand = new Random(); - var f0 = rand.float(); - var f1 = rand.float(); + + final rand = new Random(); + final f0 = rand.float(); + final f1 = rand.float(); + v('samples $f0,$f1'); - if (f0==f1) - return error("Not random enough"); + Assert.notEquals(f0, f1, "Not random enough"); + rand.setSeed(1); - var i0 = rand.int(256); + final i0 = rand.int(256); rand.setSeed(2); - var i1 = rand.int(256); - v('int samples $i0,$i1'); - if (i0!=91 || i1!=217) - return error("Non-repeatable random seed, should be 91,217"); + final i1 = rand.int(256); + + Assert.equals( 91, i0, "Non-repeatable random seed"); + Assert.equals(217, i1, "Non-repeatable random seed"); + var tries = 0; while(rand.int(1000)!=999) tries++; - v('tries to 1000 = $tries'); - if (tries!=749) - return error("Non-repeatable random iterations"); - return ok(); + Assert.equals(749, tries, "Non-repeatable random iterations"); } public static function tryFunc( func ) : Bool @@ -324,133 +280,98 @@ class Test return false; } - public static function testFile() + function testFile() { log("Test File"); - try - { - var filename = "testfile.txt"; + final filename = "testfile.txt"; tryFunc( function() FileSystem.deleteFile(filename) ); tryFunc( function() FileSystem.deleteFile(filename+"-copy") ); tryFunc( function() FileSystem.deleteFile(filename+".bin") ); tryFunc( function() FileSystem.deleteFile(filename+".out") ); - var contents = "line1\nline2\n"; + final contents = "line1\nline2\n"; + final bytes = Bytes.ofString(contents); v("compare..."); File.saveContent(filename,contents); - if ( File.getContent(filename)!=contents ) - return error("getContent mismatch"); + Assert.equals(contents, File.getContent(filename)); v("copy..."); File.copy(filename,filename+"-copy"); - var bytes = File.getBytes(filename+"-copy"); - if ( bytes.compare( Bytes.ofString(contents) ) !=0 ) - return error("copy getBytes mismatch"); - - File.saveBytes(filename+".bin",bytes); - + Assert.equals(0, File.getBytes(filename+"-copy").compare(bytes), "copy getBytes mismatch"); + v("file in..."); - var fileIn = File.read(filename+".bin"); - if (fileIn.readByte()!=contents.charCodeAt(0)) - return error("File readByte mismatch"); - var buffer = Bytes.alloc(5); + File.saveBytes(filename+".bin",bytes); + final fileIn = File.read(filename+".bin"); + Assert.equals(contents.charCodeAt(0), fileIn.readByte(), "File readByte mismatch"); + final buffer = Bytes.alloc(5); buffer.set(0,'-'.code); buffer.set(4,'+'.code); - if (fileIn.readBytes(buffer,1,3)!=3) - return error("Could not read 3 bytes"); - v( "read 3: " + buffer.toString() ); - if ( buffer.toString() != "-ine+" ) - return error("Bad sub-buffer readBytes"); + Assert.equals(3, fileIn.readBytes(buffer,1,3), "Could not read 3 bytes"); + Assert.equals("-ine+", buffer.toString(), "Bad sub-buffer readBytes"); + v("seek..."); - if (fileIn.tell()!=4) - return error("tell!=4"); - fileIn.seek(4, SeekCur ); - if (fileIn.tell()!=8) - return error("SeekCur tell!=8"); + Assert.equals(4, fileIn.tell()); + fileIn.seek(4, SeekCur); + Assert.equals(8, fileIn.tell()); fileIn.seek(7, SeekBegin ); - if (fileIn.tell()!=7) - return error("SeekSet tell!=7"); - var rest = Bytes.alloc( contents.length - fileIn.tell() ); + Assert.equals(7, fileIn.tell()); + + final rest = Bytes.alloc( contents.length - fileIn.tell() ); fileIn.readBytes(rest,0,rest.length); - if (fileIn.eof()) - return error("File at end, but not eof"); - fileIn.seek( -contents.length, SeekEnd ); - if (fileIn.tell()!=0) - return error("File seek from end to beginning failed"); + Assert.isFalse(fileIn.eof(), "File at end, but not eof"); + fileIn.seek(-contents.length, SeekEnd); + Assert.equals(0, fileIn.tell(), "File seek from end to beginning failed"); fileIn.close(); v("write..."); - var fileOut = File.write(filename+".out"); + final fileOut = File.write(filename+".out"); + fileOut.writeByte('W'.code); - if (fileOut.writeBytes(buffer,1,3)!=3) - return error("Could not write 3 bytes"); - if (fileOut.tell()!=4) - return error("Bad tell on file write"); + Assert.equals(3, fileOut.writeBytes(buffer,1,3), "Could not write 3 bytes"); + Assert.equals(4, fileOut.tell(), "Bad tell on file write"); + fileOut.flush(); - if (File.getContent(filename+".out")!="Wine") - return error("Bad reading after flush"); + Assert.equals("Wine", File.getContent(filename+".out"), "Bad reading after flush"); + fileOut.seek(1,SeekBegin); fileOut.writeByte('a'.code); fileOut.close(); - var contents = File.getContent(filename+".out"); + + final contents = File.getContent(filename+".out"); v("have :" + contents); - if (contents!="Wane") - return error("Bad readback after seek"); + Assert.equals("Wane", contents, "Bad readback after seek"); v("cleanup..."); FileSystem.deleteFile(filename); FileSystem.deleteFile(filename + "-copy"); FileSystem.deleteFile(filename + ".bin"); FileSystem.deleteFile(filename + ".out"); - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testFile: " + e); - } - } - public static function testLocalhost() + function testLocalhost() { log("Test Host"); - try - { - var localhost = Host.localhost(); + + final localhost = Host.localhost(); + v('localhost :$localhost'); - if (localhost == null || localhost.length == 0) - return error("null or empty localhost"); - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testHost: " + e); - } + + Assert.notNull(localhost); + Assert.notEquals(0, localhost.length); } - public static function testHost() + function testHost() { log("Test Host"); - try - { - var host = new Host("github.com"); - v('host :$host'); - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testHost: " + e); - } + + v('host :${ new Host("github.com") }'); + Assert.pass(); } - - public static function testFileSystem() + function testFileSystem() { - try - { - log("Test FileSystem"); tryFunc( function() FileSystem.deleteFile("dir/file.txt") ); tryFunc( function() FileSystem.deleteFile("dir/txt.file") ); @@ -458,151 +379,111 @@ class Test tryFunc( function() FileSystem.deleteDirectory("dir") ); v("create dir"); - if (!tryFunc( function() FileSystem.createDirectory("dir") ) ) - return error("Could not create 'dir'"); - if (!tryFunc( function() FileSystem.createDirectory("dir/child") ) ) - return error("Could not create 'dir/child'"); + FileSystem.createDirectory("dir"); + FileSystem.createDirectory("dir/child"); File.saveContent("dir/file.txt","hello"); - var stat = FileSystem.stat("dir/file.txt"); + + final stat = FileSystem.stat("dir/file.txt"); v(Std.string(stat)); - if (stat.size!=5) - return error("File does not contain 5 bytes"); - if ( Std.string(stat.ctime).length != 19) - return error("File ctime does not appear to be a date"); + + Assert.equals(5, stat.size, "File does not contain 5 bytes"); + Assert.equals(19, Std.string(stat.ctime).length, "File ctime does not appear to be a date"); v("exists"); - if (!FileSystem.exists("dir")) - return error("'dir' should exist"); - if (!FileSystem.exists("dir/file.txt")) - return error("'/file.txt' should exist"); - var files = FileSystem.readDirectory("dir"); + Assert.isTrue(FileSystem.exists("dir")); + Assert.isTrue(FileSystem.exists("dir/file.txt")); + + final files = FileSystem.readDirectory("dir"); v("dir contents:" + files); - if (files.length!=2 || files.indexOf("file.txt")<0 || files.indexOf("child")<0) - return error("Unexpected dir contents " + (files.indexOf("file.txt") + "," + files.indexOf("child")) ); - if (tryFunc( function() FileSystem.deleteDirectory("dir/junk") ) ) - return error("No error deleting junk directory"); - if (tryFunc( function() FileSystem.deleteFile("dir/junk") ) ) - return error("No error deleting junk file"); - if (tryFunc( function() FileSystem.deleteFile("dir/child") ) ) - return error("No error deleting directory as file"); - if (tryFunc( function() FileSystem.deleteDirectory("dir/file.txt") ) ) - return error("No error deleting file as directory"); - var fullPath = FileSystem.fullPath("dir/child"); + + Assert.equals(2, files.length); + Assert.contains("file.txt", files); + Assert.contains("child", files); + + Assert.raises(() -> FileSystem.deleteDirectory("dir/junk")); + Assert.raises(() -> FileSystem.deleteFile("dir/junk")); + Assert.raises(() -> FileSystem.deleteFile("dir/child")); + Assert.raises(() -> FileSystem.deleteDirectory("dir/file.txt")); + + final fullPath = FileSystem.fullPath("dir/child"); v('fullPath: $fullPath'); - var fullPath = FileSystem.fullPath("dir/file.txt"); + final fullPath = FileSystem.fullPath("dir/file.txt"); v('fullPath: $fullPath'); + v("isDirectory..."); - if (FileSystem.isDirectory("dir/file.txt")) - return error("file appears to be a directory"); - if (!FileSystem.isDirectory("dir/child")) - return error("directory appears to not be a directory"); - if (FileSystem.isDirectory("dir/junk")) - return error("junk appears to be a directory"); - if (FileSystem.isDirectory("dir/file.txt")) - return error("file appears to be a directory"); + Assert.isFalse(FileSystem.isDirectory("dir/file.txt"), "file appears to be a directory"); + Assert.isTrue(FileSystem.isDirectory("dir/child"), "directory appears to not be a directory"); + Assert.isFalse(FileSystem.isDirectory("dir/junk"), "junk appears to be a directory"); + Assert.isFalse(FileSystem.isDirectory("dir/file.txt"), "file appears to be a directory"); v("rename..."); - if (tryFunc( function() FileSystem.rename("dir/a", "dir/b")) ) - return error("No error renaming missing file"); + + Assert.exception(() -> FileSystem.rename("dir/a", "dir/b"), String, null, "No error renaming missing file"); + FileSystem.rename("dir/file.txt","dir/txt.file"); - if (!FileSystem.exists("dir/txt.file") || FileSystem.exists("dir/file.txt")) - return error("Rename seemed to go wrong " + FileSystem.readDirectory("dir")); + + Assert.isFalse(FileSystem.exists("dir/file.txt")); + Assert.isTrue(FileSystem.exists("dir/txt.file")); + v("cleanup.."); FileSystem.deleteFile("dir/txt.file"); FileSystem.deleteDirectory("dir/child"); FileSystem.deleteDirectory("dir"); - if (FileSystem.readDirectory(".").indexOf("dir")>=0) - return error("Directory removed, but sill there?:" + FileSystem.readDirectory(".")); - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testFileSystem: " + e); + // Assert.equals(0, FileSystem.readDirectory(".").indexOf("dir"), "Directory removed, but sill there?"); + if (FileSystem.readDirectory(".").indexOf("dir")>=0) { + Assert.fail("Directory removed, but sill there?:" + FileSystem.readDirectory(".")); } } - - public static function testSys() + function testSys() { log("Test Sys"); - try + { - Sys.putEnv("mykey","123"); - var env = Sys.getEnv("mykey"); - v("got env:" + env); - if (env!="123") - return error("Bad environment get"); - v("little sleep..."); - var t0 = Sys.time(); - Sys.sleep(0.1); - var t1 = Sys.time(); - v("Slept for: " + (t1-t0)); - if (t1<=t0 || (t1-t0)>10) - return error("Too sleepy"); - v("CpuTime: " + Sys.cpuTime()); - v("Cwd: " + Sys.getCwd()); - v("Program Path: " + Sys.programPath()); - var env = Sys.environment(); - v("Environment mykey: " + env.get("mykey") ); - if (env.get("mykey")!="123") - return error("Could not find mykey in environment"); - v("Ignore getChar auto test"); - v("Args: " + Sys.args()); - v("SystemName: " + Sys.systemName()); - v("Skipping Sys.setTimeLocale" + Sys.setTimeLocale); - // Sys.command - - return ok(); + final key = "myKey"; + final value = "123"; + + Sys.putEnv(key, value); + + Assert.equals(value, Sys.getEnv(key)); + Assert.equals(value, Sys.environment().get(key)); } - catch(e:Dynamic) + { - return error("Unexpected error in testSys: " + e); - } + v("little sleep..."); - } + final t0 = Sys.time(); + Sys.sleep(0.1); + final t1 = Sys.time(); - public static function testCommand() - { - log("Test Command"); - try - { - var code = Sys.command( Sys.programPath(), ["exit", "13"]); - if (code!=13) - return error('Process exited with code $code, not 13'); + v("Slept for: " + (t1-t0)); - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testCommand: " + e); + Assert.isFalse(t1<=t0 || (t1-t0)>10, "Too sleepy"); } + + v("CpuTime: " + Sys.cpuTime()); + v("Cwd: " + Sys.getCwd()); + v("Program Path: " + Sys.programPath()); + v("Ignore getChar auto test"); + v("Args: " + Sys.args()); + v("SystemName: " + Sys.systemName()); + v("Skipping Sys.setTimeLocale" + Sys.setTimeLocale); } - public static function runAsProcess() + function testCommand() { - var args = Sys.args(); - var job = args.shift(); - if (job=="exit") - { - Sys.exit( Std.parseInt(args[0]) ); - } - else if (job=="socket") - { - socketClient(); - Sys.exit(0); - } - else - Sys.println('Unknown job : "$job"'); - Sys.exit(-99); + log("Test Command"); + + final expected = 13; + + Assert.equals(expected, Sys.command( Sys.programPath(), ["exit", Std.string(expected)])); } - public static function testPoll() + function testPoll() { log("Test poll"); - try - { - + var poll = new Poll(4); poll.prepare([],[]); var t0 = Sys.time(); @@ -617,31 +498,19 @@ class Test return error("Timeout too slow"); */ - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testPoll: " + e); - } - + Assert.pass(); } - public static function testUdpSocket() + function testUdpSocket() { log("Test UdpSocket"); - try - { - + var udp = new UdpSocket(); + udp.close(); - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in testUdpSocket: " + e); - } + Assert.pass(); } static var socketClientRunning = true; @@ -666,11 +535,9 @@ class Test }); } - public static function testSocket() + function testSocket() { log("Test Socket"); - try - { v("Spawn client.."); var proc = new Process( Sys.programPath(), ["socket"] ); readOutput(proc); @@ -691,12 +558,9 @@ class Test connected.setFastSend(true); connected.write("ping"); var buffer = Bytes.alloc(8); - if (input.readBytes(buffer,0,8)!=8) - return error("Could not read from socket"); - var got = buffer.toString(); - v('got $got'); - if (got!="pingpong") - return error("Bad socket read"); + + Assert.equals(8, input.readBytes(buffer,0,buffer.length)); + Assert.equals("pingpong", buffer.toString()); v("close connection.."); connected.close(); @@ -710,16 +574,7 @@ class Test v("wait for client..."); Sys.sleep(0.1); } - if (socketClientRunning) - return error("Socket client did not finish"); - - return ok(); - } - catch(e:Dynamic) - { - return error("Unexpected error in Socket: " + e); - } - + Assert.isFalse(socketClientRunning, "Socket client did not finish"); } public static function socketClient() @@ -763,50 +618,42 @@ class Test socket.shutdown(true,true); } - public static function testSsl() : Int + function testSsl() { log("Test ssl"); + SslTest.socket_init(); - return ok(); + + Assert.pass(); } - public static function testSerialization() : Int + function testSerialization() { log("Test serialization"); + var orig:haxe.Int64 = haxe.Int64.make(0xdeadbeef,0xbeefdead); var recon:haxe.Int64 = haxe.Unserializer.run(haxe.Serializer.run(orig)); - if (orig!=recon) - error('Bad Int64 serialization $orig != $recon'); - return ok(); + Assert.equals(orig, recon); } - // Hide from optimizer static function getOne() return 1; - public static function testThread() + function testThread() { log("Test thread"); v("atomics.."); var a:AtomicInt = getOne(); var aPtr = cpp.Pointer.addressOf(a); - if (aPtr.exchangeIf(2,3)) - error("Bad exchageIf " + a); - if (!aPtr.exchangeIf(1,3)) - error("No exchageIf " + a); - if (a!=3) - error("Bad exchageIf value "); - if (aPtr.atomicInc()!=3) - error("Bad atomicInc return"); - if (a!=4) - error("Bad atomicInc value " + a); - if (aPtr.atomicDec()!=4) - error("Bad atomicDec return"); - if (a!=3) - error("Bad atomicDec value " + a); - + Assert.isFalse(aPtr.exchangeIf(2,3)); + Assert.isTrue(aPtr.exchangeIf(1,3)); + Assert.equals(3, a); + Assert.equals(3, aPtr.atomicInc()); + Assert.equals(4, a); + Assert.equals(4, aPtr.atomicDec()); + Assert.equals(3, a); a = getOne(); v('deque a=$a'); @@ -845,166 +692,77 @@ class Test v('got $i'); } - if (a!=1) - error('Bad deque count : $a'); - - return ok(); + Assert.equals(1, a); } - public static function testFloatReads() + function testFloatReads() { log("Test float bytes"); - var bytes =haxe.io.Bytes.alloc(1+4+8); - bytes.fill(0,1,46); + final value = 46; + final bytes = haxe.io.Bytes.alloc(1+4+8); + bytes.fill(0,1,value); // Test unaligned read/write bytes.setFloat(1,1.25); bytes.setDouble(5,1.25); - if (bytes.get(0)!=46) - error("Bad byte 0"); - - if (bytes.getDouble(5)!=bytes.getFloat(1)) - error("Bad byte read/write"); - - return ok(); + Assert.equals(value, bytes.get(0), "Bad byte 0"); + Assert.equals(bytes.getDouble(5), bytes.getFloat(1), "Bad byte read/write"); } public dynamic function getX() return x; - public static function testDynamicMember() + function testDynamicMember() { log("Test dynamic member"); - var t = new Test(); - if (t.getX()!=1) - error("Bad dynamic member function"); - return ok(); + + Assert.equals(1, getX(), "Bad dynamic member function"); } @:noDebug - public static function testNoDebug() + function testNoDebug() { log("Test noDebug"); + // Just testing to see it it compiles... - if ( null == new haxe.io.BytesBuffer() ) - error("Bad alloc"); - return ok(); + Assert.notNull(new haxe.io.BytesBuffer(), "bad alloc"); } @:noDebug - public static function testNoDebugNoAlloc() + function testNoDebugNoAlloc() { - log("Test noDebug, no alloc"); - return ok(); + Assert.pass("Test noDebug, no alloc"); } - public static function testIntParsing() + function testIntParsing() { log("Test int parsing"); - var val = Std.parseInt('0x1'); - if (val != 1) - { - error('parsed hex value was not 1, $val'); - } - var val = Std.parseInt(' 0x1'); - if (val != 1) - { - error('parsed hex value was not 1, $val'); - } - var val = Std.parseInt('\t0x1'); - if (val != 1) - { - error('parsed hex value was not 1, $val'); - } - var val = Std.parseInt(' 0x'); - if (val != 0) - { - error('parsed hex value was not 0, $val'); - } - var val = Std.parseInt(' 0xyz'); - if (val != 0) - { - error('parsed hex value was not 0, $val'); - } - var val = Std.parseInt('-0x1'); - if (val != -1) - { - error('parsed hex value was not 1, $val'); - } - var val = Std.parseInt(' -0x1'); - if (val != -1) - { - error('parsed hex value was not 1, $val'); - } - var val = Std.parseInt('\t-0x1'); - if (val != -1) - { - error('parsed hex value was not 1, $val'); - } - var val = Std.parseInt(' -0x'); - if (val != 0) - { - error('parsed hex value was not 0, $val'); - } - var val = Std.parseInt(' -0xyz'); - if (val != 0) - { - error('parsed hex value was not 0, $val'); - } - var val = Std.parseInt(' 5'); - if (val != 5) - { - error('parsed int value was not 5, $val'); - } - var val = Std.parseInt(' \t\n5'); - if (val != 5) - { - error('parsed int value was not 5, $val'); - } - return ok(); + Assert.equals( 1, Std.parseInt('0x1')); + Assert.equals( 1, Std.parseInt(' 0x1')); + Assert.equals( 1, Std.parseInt('\t0x1')); + Assert.equals( 0, Std.parseInt(' 0x')); + Assert.equals( 0, Std.parseInt(' 0xyz')); + Assert.equals(-1, Std.parseInt('-0x1')); + Assert.equals(-1, Std.parseInt(' -0x1')); + Assert.equals(-1, Std.parseInt('\t-0x1')); + Assert.equals( 0, Std.parseInt(' -0x')); + Assert.equals( 0, Std.parseInt(' -0xyz')); + Assert.equals( 5, Std.parseInt(' 5')); + Assert.equals( 5, Std.parseInt(' \t\n5')); } public static function main() { - var exitCode = 0; - if (Sys.args().length>0) - { - runAsProcess(); - } - else - { - exitCode |= testDate(); - exitCode |= testCompress(); - exitCode |= testRegexp(); - exitCode |= testRegexpMixedUnicode(); - exitCode |= testSqlite(); - exitCode |= testMysql(); - exitCode |= testRandom(); - exitCode |= testFile(); - exitCode |= testFileSystem(); - exitCode |= testHost(); - exitCode |= testSys(); - exitCode |= testCommand(); - exitCode |= testPoll(); - exitCode |= testUdpSocket(); - exitCode |= testSocket(); - exitCode |= testThread(); - exitCode |= testSsl(); - exitCode |= testSerialization(); - exitCode |= testFloatReads(); - exitCode |= testDynamicMember(); - exitCode |= testNoDebug(); - exitCode |= testNoDebugNoAlloc(); - exitCode |= testIntParsing(); - - if (exitCode!=0) - Sys.println("############# Errors running tests:\n " + errors.join("\n ") ); - else - Sys.println("All tests passed."); - Sys.exit(exitCode); + switch Sys.args() { + case [ 'exit', code ]: + Sys.exit(Std.parseInt(code)); + case [ 'socket' ]: + socketClient(); + case _: + utest.UTest.run([ new Test() ]); } } } diff --git a/test/std/compile32.hxml b/test/std/compile32.hxml index 2732affa3..692ed7581 100644 --- a/test/std/compile32.hxml +++ b/test/std/compile32.hxml @@ -1,6 +1,6 @@ --main Test --cpp cpp32 +-m Test -D HXCPP_M32 -D HXCPP_DEBUGGER --cp ../unit --lib hx4compat +-L hx4compat +-L utest +--cpp cpp32 \ No newline at end of file diff --git a/test/std/compile64.hxml b/test/std/compile64.hxml index 2928668e5..2793e6bd3 100644 --- a/test/std/compile64.hxml +++ b/test/std/compile64.hxml @@ -1,5 +1,5 @@ --main Test --cpp cpp64 +-m Test -D HXCPP_M64 --cp ../unit --lib hx4compat +-L hx4compat +-L utest +--cpp cpp64 \ No newline at end of file diff --git a/test/std/testAndroid.hxml b/test/std/testAndroid.hxml index 5ff93520e..7e7e1d0b6 100644 --- a/test/std/testAndroid.hxml +++ b/test/std/testAndroid.hxml @@ -1,9 +1,9 @@ --main Test --cpp arm32 +-m Test -D android -D exe_link --cp ../unit --lib hx4compat --cmd adb push arm32/Test /storage/ext_sd --cmd adb push Test.hx /storage/ext_sd --cmd adb shell "cd /storage/ext_sd && ./Test" +-L hx4compat +-L utest +--cmd adb push arm32/Test /storage/ext_sd +--cmd adb push Test.hx /storage/ext_sd +--cmd adb shell "cd /storage/ext_sd && ./Test" +--cpp arm32 \ No newline at end of file diff --git a/test/telemetry/TestBasic.hx b/test/telemetry/TestBasic.hx index ad44bb60a..556403536 100644 --- a/test/telemetry/TestBasic.hx +++ b/test/telemetry/TestBasic.hx @@ -1,11 +1,12 @@ -class TestBasic extends haxe.unit.TestCase -{ - public function new() super(); +import utest.Test; +import utest.Assert; - function testStartTelemetry(string:String) +class TestBasic extends Test +{ + function testStartTelemetry() { var thread_id:Int = startTelemetry(true, true); - assertTrue(thread_id>=0); + Assert.isTrue(thread_id>=0); } function startTelemetry(with_profiler:Bool=true, diff --git a/test/telemetry/TestMain.hx b/test/telemetry/TestMain.hx index dfcea4aa8..f13d9e28a 100644 --- a/test/telemetry/TestMain.hx +++ b/test/telemetry/TestMain.hx @@ -3,11 +3,6 @@ package; class TestMain { static function main(){ - var r = new haxe.unit.TestRunner(); - r.add(new TestBasic()); - var t0 = haxe.Timer.stamp(); - var success = r.run(); - trace(" Time : " + (haxe.Timer.stamp()-t0)*1000 ); - Sys.exit(success ? 0 : 1); + utest.UTest.run([ new TestBasic() ]); } } diff --git a/test/telemetry/compile.hxml b/test/telemetry/compile.hxml index c908665c5..758233838 100644 --- a/test/telemetry/compile.hxml +++ b/test/telemetry/compile.hxml @@ -1,6 +1,6 @@ --cpp bin --main TestMain --resource TestMain.hx +-m TestMain +-r TestMain.hx -D HXCPP_TELEMETRY -D HXCPP_STACK_TRACE --cp ../unit +-L utest +--cpp bin \ No newline at end of file diff --git a/test/threads/compile.hxml b/test/threads/compile.hxml index 8db60c868..96e05ffae 100644 --- a/test/threads/compile.hxml +++ b/test/threads/compile.hxml @@ -1,4 +1,3 @@ --main Test --cpp cpp --debug --cp ../unit +-m Test +--cpp cpp +--debug \ No newline at end of file diff --git a/test/unit/haxe/unit/TestCase.hx b/test/unit/haxe/unit/TestCase.hx deleted file mode 100644 index b81704316..000000000 --- a/test/unit/haxe/unit/TestCase.hx +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C)2005-2017 Haxe Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -package haxe.unit; -import haxe.PosInfos; - -/** - This unit test class should be extended to create test cases. Each test - method created in this extended class should start with the name "test". - - These test methods should call the assertion methods: - - * `assertTrue(a)`: Succeeds if `a` is `true`. - * `assertFalse(a)`: Succeeds if `a` is `false`. - * `assertEquals(expected, actual)`: Succeeds if `expected` and `actual` - are equal. - - ```haxe - class MyTestCase extends haxe.unit.TestCase { - function testBasic() { - assertEquals("A", "A"); - } - } - ``` - - The TestCase can be tested using `TestRunner`. - - To run code before or after the test, override the functions `setup` - and `tearDown`. - - @see -**/ -@:keepSub -@:publicFields -class TestCase { - /** - The current test status of the TestRunner. - **/ - public var currentTest : TestStatus; - - public function new( ) { - } - - /** - Override this method to execute code before the test runs. - **/ - public function setup() : Void { - } - - /** - Override this method to execute code after the test ran. - **/ - public function tearDown() : Void { - } - - function print( v : Dynamic ) { - haxe.unit.TestRunner.print(v); - } - - /** - Succeeds if `b` is `true`. - **/ - function assertTrue( b:Bool, ?c : PosInfos ) : Void { - currentTest.done = true; - if (b != true){ - currentTest.success = false; - currentTest.error = "expected true but was false"; - currentTest.posInfos = c; - throw currentTest; - } - } - - /** - Succeeds if `b` is `false`. - **/ - function assertFalse( b:Bool, ?c : PosInfos ) : Void { - currentTest.done = true; - if (b == true){ - currentTest.success = false; - currentTest.error = "expected false but was true"; - currentTest.posInfos = c; - throw currentTest; - } - } - - /** - Succeeds if `expected` and `actual` are equal. - **/ - function assertEquals( expected: T , actual: T, ?c : PosInfos ) : Void { - currentTest.done = true; - if (actual != expected){ - currentTest.success = false; - currentTest.error = "expected '" + expected + "' but was '" + actual + "'"; - currentTest.posInfos = c; - throw currentTest; - } - } -} diff --git a/test/unit/haxe/unit/TestResult.hx b/test/unit/haxe/unit/TestResult.hx deleted file mode 100644 index f906e4243..000000000 --- a/test/unit/haxe/unit/TestResult.hx +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C)2005-2017 Haxe Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - package haxe.unit; - -/** - TestResult contains the result of the executed unit tests. -**/ -class TestResult { - var m_tests : List; - - /** - `true` if the unit test succesfully executed the test cases. - **/ - public var success(default, null) : Bool; - - public function new() { - m_tests = new List(); - success = true; - } - - public function add( t:TestStatus ) : Void { - m_tests.add(t); - if( !t.success ) - success = false; - } - - /** - String representation from the result of the unit test. - **/ - public function toString() : String { - var buf = new StringBuf(); - var failures = 0; - for ( test in m_tests ){ - if (test.success == false){ - buf.add("* "); - buf.add(test.classname); - buf.add("::"); - buf.add(test.method); - buf.add("()"); - buf.add("\n"); - - buf.add("ERR: "); - if( test.posInfos != null ){ - buf.add(test.posInfos.fileName); - buf.add(":"); - buf.add(test.posInfos.lineNumber); - buf.add("("); - buf.add(test.posInfos.className); - buf.add("."); - buf.add(test.posInfos.methodName); - buf.add(") - "); - } - buf.add(test.error); - buf.add("\n"); - - if (test.backtrace != null) { - buf.add(test.backtrace); - buf.add("\n"); - } - - buf.add("\n"); - failures++; - } - } - buf.add("\n"); - if (failures == 0) - buf.add("OK "); - else - buf.add("FAILED "); - - buf.add(m_tests.length); - buf.add(" tests, "); - buf.add(failures); - buf.add(" failed, "); - buf.add( (m_tests.length - failures) ); - buf.add(" success"); - buf.add("\n"); - return buf.toString(); - } - -} diff --git a/test/unit/haxe/unit/TestRunner.hx b/test/unit/haxe/unit/TestRunner.hx deleted file mode 100644 index 7473d780f..000000000 --- a/test/unit/haxe/unit/TestRunner.hx +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C)2005-2017 Haxe Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -package haxe.unit; -import Reflect; - -/** - This class runs unit test cases and prints the result. - - ```haxe - var r = new haxe.unit.TestRunner(); - r.add(new MyTestCase()); - // add other TestCases here - - // finally, run the tests - r.run(); - ``` - - @see -**/ -class TestRunner { - /** - The unit test results. Available after the `run()` is called. - **/ - public var result(default, null) : TestResult; - - var cases : List; - -#if flash - static var tf : flash.text.TextField = null; -#end - - /** - Prints the given object/value. - - * Flash outputs the result in a new `TextField` on stage. - * JavaScript outputs the result using `console.log`. - * Other targets use native `print` to output the result. - - This function is `dynamic` so it can be overriden in custom setups. - **/ - public static dynamic function print( v : Dynamic ) untyped { - #if flash - if( tf == null ) { - tf = new flash.text.TextField(); - tf.selectable = false; - tf.width = flash.Lib.current.stage.stageWidth; - tf.autoSize = flash.text.TextFieldAutoSize.LEFT; - flash.Lib.current.addChild(tf); - } - tf.appendText(v); - #elseif neko - __dollar__print(v); - #elseif php - php.Lib.print(v); - #elseif cpp - cpp.Lib.print(v); - #elseif js - var msg = js.Boot.__string_rec(v,""); - var d; - if( __js__("typeof")(document) != "undefined" - && (d = document.getElementById("haxe:trace")) != null ) { - msg = StringTools.htmlEscape(msg).split("\n").join("
"); - d.innerHTML += msg+"
"; - } - else if ( __js__("typeof process") != "undefined" - && __js__("process").stdout != null - && __js__("process").stdout.write != null) - __js__("process").stdout.write(msg); // node - else if ( __js__("typeof console") != "undefined" - && __js__("console").log != null ) - __js__("console").log(msg); // document-less js (which may include a line break) - - #elseif cs - cs.system.Console.Write(v); - #elseif java - var str:String = v; - untyped __java__("java.lang.System.out.print(str)"); - #elseif python - python.Lib.print(v); - #elseif (hl || lua) - Sys.print(Std.string(v)); - #end - } - - private static function customTrace( v, ?p : haxe.PosInfos ) { - print(p.fileName+":"+p.lineNumber+": "+Std.string(v)+"\n"); - } - - public function new() { - result = new TestResult(); - cases = new List(); - } - - /** - Add TestCase instances to the unit test. - **/ - public function add( c:TestCase ) : Void{ - cases.add(c); - } - - /** - Runs the unit tests and prints the results. - - @return `true` if the unit test succesfully executed the test cases. - **/ - public function run() : Bool { - result = new TestResult(); - for ( c in cases ){ - runCase(c); - } - print(result.toString()); - return result.success; - } - - function runCase( t:TestCase ) : Void { - var old = haxe.Log.trace; - haxe.Log.trace = customTrace; - - var cl = Type.getClass(t); - var fields = Type.getInstanceFields(cl); - - print( "Class: "+Type.getClassName(cl)+" "); - for ( f in fields ){ - var fname = f; - var field = Reflect.field(t, f); - if ( StringTools.startsWith(fname,"test") && Reflect.isFunction(field) ){ - t.currentTest = new TestStatus(); - t.currentTest.classname = Type.getClassName(cl); - t.currentTest.method = fname; - t.setup(); - - try { - Reflect.callMethod(t, field, new Array()); - - if( t.currentTest.done ){ - t.currentTest.success = true; - print("."); - }else{ - t.currentTest.success = false; - t.currentTest.error = "(warning) no assert"; - print("W"); - } - }catch ( e : TestStatus ){ - print("F"); - t.currentTest.backtrace = haxe.CallStack.toString(haxe.CallStack.exceptionStack()); - }catch ( e : Dynamic ){ - print("E"); - #if js - if( e.message != null ){ - t.currentTest.error = "exception thrown : "+e+" ["+e.message+"]"; - }else{ - t.currentTest.error = "exception thrown : "+e; - } - #else - t.currentTest.error = "exception thrown : "+e; - #end - t.currentTest.backtrace = haxe.CallStack.toString(haxe.CallStack.exceptionStack()); - } - result.add(t.currentTest); - t.tearDown(); - } - } - - print("\n"); - haxe.Log.trace = old; - } -} diff --git a/test/unit/haxe/unit/TestStatus.hx b/test/unit/haxe/unit/TestStatus.hx deleted file mode 100644 index bd885597b..000000000 --- a/test/unit/haxe/unit/TestStatus.hx +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C)2005-2017 Haxe Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -package haxe.unit; -import haxe.CallStack; - -import haxe.PosInfos; - -/** - The status information of a unit test case method. - - @see -**/ -class TestStatus { - /** - `true` when the unit test is executed. - **/ - public var done : Bool; - - /** - `true` when succesfully unit tested. - **/ - public var success : Bool; - - /** - The error message of the unit test method. - **/ - public var error : String; - - /** - The method name of the unit test. - **/ - public var method : String; - - /** - The class name of the unit test. - **/ - public var classname : String; - - /** - The position information of the unit test. - **/ - public var posInfos : PosInfos; - - /** - The representation of the stack exception. - **/ - public var backtrace : String; - - public function new() { - done = false; - success = false; - } -}