diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2e3ddbf6d..2289108c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -221,3 +221,19 @@ jobs: run: haxe compile-cpp.hxml -D ${{ env.HXCPP_ARCH_FLAG }} -D no_http - name: run run: bin${{ inputs.sep }}cpp${{ inputs.sep }}TestMain-debug + + regression: + runs-on: ${{ inputs.os }} + name: regression tests + defaults: + run: + working-directory: test/regression + steps: + - name: checkout + uses: actions/checkout@v4 + - name: setup + uses: ./.github/workflows/setup + with: + haxe: ${{ inputs.haxe }} + - name: run + run: haxe --run Run -D ${{ env.HXCPP_ARCH_FLAG }} diff --git a/include/cpp/Pointer.h b/include/cpp/Pointer.h index 25c28b451..d1899df0c 100644 --- a/include/cpp/Pointer.h +++ b/include/cpp/Pointer.h @@ -499,7 +499,7 @@ class Pointer_obj } template - inline static AutoCast ofArray(::Array array) { return AutoCast(&array[0]); } + inline static AutoCast ofArray(::Array array) { return AutoCast(array->Pointer()); } inline static AutoCast ofArray(Dynamic inVal) { if (inVal==null() || !inVal->__IsArray()) diff --git a/test/regression/Issue1028/Main.hx b/test/regression/Issue1028/Main.hx new file mode 100644 index 000000000..86f94f7cc --- /dev/null +++ b/test/regression/Issue1028/Main.hx @@ -0,0 +1,7 @@ +class Main { + static function main() { + var array:Array = []; + cpp.Pointer.ofArray(array); + trace(array.length); + } +} diff --git a/test/regression/Issue1028/build.hxml b/test/regression/Issue1028/build.hxml new file mode 100644 index 000000000..ea891d9fc --- /dev/null +++ b/test/regression/Issue1028/build.hxml @@ -0,0 +1,2 @@ +--cpp bin +-m Main diff --git a/test/regression/Issue1028/stdout.txt b/test/regression/Issue1028/stdout.txt new file mode 100644 index 000000000..d6a5d4108 --- /dev/null +++ b/test/regression/Issue1028/stdout.txt @@ -0,0 +1 @@ +Main.hx:5: 0 diff --git a/test/regression/Run.hx b/test/regression/Run.hx new file mode 100644 index 000000000..a233a18c7 --- /dev/null +++ b/test/regression/Run.hx @@ -0,0 +1,60 @@ +import sys.io.Process; +import sys.io.File; +import sys.FileSystem; + +using StringTools; + +function runOutput(test:String):String { + final slash = Sys.systemName() == "Windows" ? "\\" : "/"; + final proc = new Process([test, "bin", 'Main'].join(slash)); + final code = proc.exitCode(); + + if (code != 0) { + throw 'return code was $code'; + } + + return proc.stdout.readAll().toString().replace("\r\n", "\n"); +} + +function main() { + var successes = 0; + var total = 0; + + final args = Sys.args(); + + for (test in FileSystem.readDirectory(".")) { + if (!FileSystem.isDirectory(test)) { + continue; + } + + total++; + + final buildExitCode = Sys.command("haxe", ["-C", test, "build.hxml"].concat(args)); + if (buildExitCode != 0) { + Sys.println('Failed to build test $test. Exit code: $buildExitCode'); + continue; + } + + final expectedStdout = File.getContent('$test/stdout.txt').replace("\r\n", "\n"); + final actualStdout = try { + runOutput(test); + } catch (e) { + Sys.println('Test $test failed: $e'); + continue; + }; + + if (actualStdout != expectedStdout) { + Sys.println('Test $test failed: Output did not match'); + + Sys.println("Expected stdout:"); + Sys.println(expectedStdout); + Sys.println("Actual stdout:"); + Sys.println(actualStdout); + continue; + } + + successes++; + } + + Sys.println('Regression tests complete. Successes: $successes / $total'); +}