From 76d2fc11cae22085f8a2714f03bfde3768edac93 Mon Sep 17 00:00:00 2001 From: Tommy Brosman Date: Sat, 6 Jul 2019 10:30:18 -0700 Subject: [PATCH 1/2] Test cleanup. Added test compilation/run targets for HashLink in Haxe 3 and 4. --- spriter/definitions/Quadrilateral.hx | 2 ++ test-hl-haxe3.hxml | 16 ++++++++++++++++ test-hl-haxe4.hxml | 22 ++++++++++++++++++++++ test/ConstructEngineTestCase.hx | 22 ++++++++++++++++++++++ test/Point.hx | 16 ++++++++++++++++ test/TestMain.hx | 13 +++++++++++++ 6 files changed, 91 insertions(+) create mode 100644 test-hl-haxe3.hxml create mode 100644 test-hl-haxe4.hxml create mode 100644 test/ConstructEngineTestCase.hx create mode 100644 test/Point.hx create mode 100644 test/TestMain.hx diff --git a/spriter/definitions/Quadrilateral.hx b/spriter/definitions/Quadrilateral.hx index 5dc12b6..2b229ef 100644 --- a/spriter/definitions/Quadrilateral.hx +++ b/spriter/definitions/Quadrilateral.hx @@ -7,6 +7,8 @@ import flambe.math.Point; typedef Point = phoenix.Vector; #elseif heaps typedef Point = h2d.col.Point; +#elseif test +typedef Point = test.Point; #end /** diff --git a/test-hl-haxe3.hxml b/test-hl-haxe3.hxml new file mode 100644 index 0000000..23d626d --- /dev/null +++ b/test-hl-haxe3.hxml @@ -0,0 +1,16 @@ +# +# Build and run tests +# +-cp . + +# Turn off dead code elimination so that all sources are compiled +-dce no + +# Specify that we should be using the test definition for Point, etc rather than a type from a specific library +-D test=true + +-main test.TestMain +-hl bin/test.hl + +# Run the tests (requires HashLink 1.1) +-cmd hl bin/test.hl \ No newline at end of file diff --git a/test-hl-haxe4.hxml b/test-hl-haxe4.hxml new file mode 100644 index 0000000..ca0b0d2 --- /dev/null +++ b/test-hl-haxe4.hxml @@ -0,0 +1,22 @@ +# +# Build and run tests +# +-cp . + +# Needed for haxe.unit on Haxe 4 +-lib hx3compat + +# Turn off dead code elimination so that all sources are compiled +-dce no + +# Specify that we should be using the test definition for Point, etc rather than a type from a specific library +-D test=true + +# Force Haxe to generate a specific version of the HashLink bytecode +-D hl_ver=1.9.0 + +-main test.TestMain +-hl bin/test.hl + +# Run the tests +-cmd hl bin/test.hl \ No newline at end of file diff --git a/test/ConstructEngineTestCase.hx b/test/ConstructEngineTestCase.hx new file mode 100644 index 0000000..c421596 --- /dev/null +++ b/test/ConstructEngineTestCase.hx @@ -0,0 +1,22 @@ +package test; + +using haxe.unit.TestCase; +using spriter.engine.SpriterEngine; +using spriter.library.AbstractLibrary; + +class ConstructEngineTestCase extends TestCase +{ + public function new() + { + super(); + } + + public function testConstructEngine():Void + { + var lib:AbstractLibrary = null; + var x:SpriterEngine = new SpriterEngine("", null, lib); + + // At least one assert is needed to make the unit test pass + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/Point.hx b/test/Point.hx new file mode 100644 index 0000000..728a4f7 --- /dev/null +++ b/test/Point.hx @@ -0,0 +1,16 @@ +package test; + +/** + * A point implementation to satisfy test code + */ +class Point +{ + public var x:Float; + public var y:Float; + + public function new(x:Float, y:Float) + { + this.x = x; + this.y = y; + } +} \ No newline at end of file diff --git a/test/TestMain.hx b/test/TestMain.hx new file mode 100644 index 0000000..00f7080 --- /dev/null +++ b/test/TestMain.hx @@ -0,0 +1,13 @@ +package test; + +using haxe.unit.TestRunner; + +class TestMain +{ + public static function main():Void + { + var runner = new TestRunner(); + runner.add(new ConstructEngineTestCase()); + runner.run(); + } +} From 106402a6646883a14b453c66d22136fea26312bd Mon Sep 17 00:00:00 2001 From: Tommy Brosman Date: Sat, 13 Jul 2019 15:00:43 -0700 Subject: [PATCH 2/2] Fixed a bug where calling SpriterUtil.clearArray can break in HashLink at runtime. --- spriter/util/SpriterUtil.hx | 4 ---- test/BasicTestCase.hx | 37 +++++++++++++++++++++++++++++++++ test/ConstructEngineTestCase.hx | 22 -------------------- test/TestMain.hx | 4 ++-- 4 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 test/BasicTestCase.hx delete mode 100644 test/ConstructEngineTestCase.hx diff --git a/spriter/util/SpriterUtil.hx b/spriter/util/SpriterUtil.hx index 4afecca..60158d9 100644 --- a/spriter/util/SpriterUtil.hx +++ b/spriter/util/SpriterUtil.hx @@ -63,11 +63,7 @@ class SpriterUtil { if (array.length > 0) { - #if cpp array.splice(0, array.length);//allocates in hxcpp but fastest - #else - untyped array.length = 0; - #end } } } \ No newline at end of file diff --git a/test/BasicTestCase.hx b/test/BasicTestCase.hx new file mode 100644 index 0000000..ca9995b --- /dev/null +++ b/test/BasicTestCase.hx @@ -0,0 +1,37 @@ +package test; + +import haxe.unit.TestCase; +import spriter.engine.SpriterEngine; +import spriter.library.AbstractLibrary; +import spriter.util.SpriterUtil; +import spriter.definitions.SpatialInfo; + +/** + * Test cases for very common scenarios. + */ +class BasicTestCase extends TestCase +{ + public function new() + { + super(); + } + + public function testConstructEngine():Void + { + var lib:AbstractLibrary = null; + var x:SpriterEngine = new SpriterEngine("", null, lib); + + // At least one assert is needed to make the unit test pass + assertTrue(true); + } + + public function testSpriterUtilClearArray():Void + { + // Construct an array that results in an ArrayDyn in HashLink + var array:Array = [1, 2]; + + // The original version set the length property, which fails when the underlying type is an ArrayDyn. + SpriterUtil.clearArray(array); + assertTrue(array.length == 0); + } +} \ No newline at end of file diff --git a/test/ConstructEngineTestCase.hx b/test/ConstructEngineTestCase.hx deleted file mode 100644 index c421596..0000000 --- a/test/ConstructEngineTestCase.hx +++ /dev/null @@ -1,22 +0,0 @@ -package test; - -using haxe.unit.TestCase; -using spriter.engine.SpriterEngine; -using spriter.library.AbstractLibrary; - -class ConstructEngineTestCase extends TestCase -{ - public function new() - { - super(); - } - - public function testConstructEngine():Void - { - var lib:AbstractLibrary = null; - var x:SpriterEngine = new SpriterEngine("", null, lib); - - // At least one assert is needed to make the unit test pass - assertTrue(true); - } -} \ No newline at end of file diff --git a/test/TestMain.hx b/test/TestMain.hx index 00f7080..1a0b7af 100644 --- a/test/TestMain.hx +++ b/test/TestMain.hx @@ -1,13 +1,13 @@ package test; -using haxe.unit.TestRunner; +import haxe.unit.TestRunner; class TestMain { public static function main():Void { var runner = new TestRunner(); - runner.add(new ConstructEngineTestCase()); + runner.add(new BasicTestCase()); runner.run(); } }