Skip to content

Commit

Permalink
CI - UTest2 (HaxeFoundation#1120)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Aidan63 authored Jun 27, 2024
1 parent d4e8d40 commit f97a11e
Show file tree
Hide file tree
Showing 49 changed files with 735 additions and 1,465 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
8 changes: 4 additions & 4 deletions test/cffi/compile-neko.hxml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions test/cffi/compile-utf8.hxml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions test/cffi/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-cp src
-main TestMain
-cpp bin/cpp
-cp ../unit
-p src
-m TestMain
-L utest
--cpp bin/cpp
18 changes: 0 additions & 18 deletions test/cffi/src/TestBase.hx

This file was deleted.

107 changes: 54 additions & 53 deletions test/cffi/src/TestCffi.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -49,45 +51,45 @@ 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))
{
#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
}

Expand All @@ -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);

Expand All @@ -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;
Expand Down
9 changes: 1 addition & 8 deletions test/cffi/src/TestMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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() ]);
}
}

Expand Down
53 changes: 27 additions & 26 deletions test/cffi/src/TestPrime.hx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 );

}
}
5 changes: 2 additions & 3 deletions test/cppia/compile-client.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-main Client
-m Client
-D dll_import=host_classes.info
-cppia bin/client.cppia
-cp ../unit
--cppia bin/client.cppia
7 changes: 3 additions & 4 deletions test/cppia/compile-host.hxml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions test/debugger/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-main App
-cpp bin
-m App
-D hxcpp_debugger
-D HXCPP_DEBUGGER
-debug
-cp ../unit
--cpp bin
--debug
5 changes: 2 additions & 3 deletions test/extern-lib/compile-api.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-cpp gen-externs
--cpp gen-externs
-D static_link
api.HaxeApi
-cp ../unit
api.HaxeApi
Loading

0 comments on commit f97a11e

Please sign in to comment.