Skip to content

Commit 4ce4af3

Browse files
committed
Add test for String::create unspecified length
1 parent 81852b1 commit 4ce4af3

5 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,19 @@ jobs:
231231
run: haxe compile-cpp.hxml -D ${{ env.HXCPP_ARCH_FLAG }} -D no_http
232232
- name: run
233233
run: bin${{ inputs.sep }}cpp${{ inputs.sep }}TestMain-debug
234+
235+
regression:
236+
runs-on: ${{ inputs.os }}
237+
name: regression tests
238+
defaults:
239+
run:
240+
working-directory: test/regression
241+
steps:
242+
- name: checkout
243+
uses: actions/checkout@v4
244+
- name: setup
245+
uses: ./.github/workflows/setup
246+
with:
247+
haxe: ${{ inputs.haxe }}
248+
- name: run
249+
run: haxe --run Run -D ${{ env.HXCPP_ARCH_FLAG }}

test/regression/Issue849/Main.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function main() {
2+
// char
3+
trace(untyped __cpp__('::String::create("Hello world")'));
4+
5+
// wchar_t
6+
trace(untyped __cpp__('::String::create(L"Hello world")'));
7+
8+
// char16_t
9+
trace(untyped __cpp__('::String::create(u"Hello world")'));
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-cpp bin
2+
-D disable-unicode-strings
3+
-m Main
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Main.hx:3: Hello world
2+
Main.hx:6: Hello world
3+
Main.hx:9: Hello world

test/regression/Run.hx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sys.io.Process;
2+
import sys.io.File;
3+
import sys.FileSystem;
4+
5+
using StringTools;
6+
7+
function runOutput(test:String):String {
8+
final slash = Sys.systemName() == "Windows" ? "\\" : "/";
9+
final proc = new Process([test, "bin", 'Main'].join(slash));
10+
final code = proc.exitCode();
11+
12+
if (code != 0) {
13+
throw 'return code was $code';
14+
}
15+
16+
return proc.stdout.readAll().toString().replace("\r\n", "\n");
17+
}
18+
19+
function main() {
20+
var successes = 0;
21+
var total = 0;
22+
23+
final args = Sys.args();
24+
25+
for (test in FileSystem.readDirectory(".")) {
26+
if (!FileSystem.isDirectory(test)) {
27+
continue;
28+
}
29+
30+
total++;
31+
32+
final buildExitCode = Sys.command("haxe", ["-C", test, "build.hxml"].concat(args));
33+
if (buildExitCode != 0) {
34+
Sys.println('Failed to build test $test. Exit code: $buildExitCode');
35+
continue;
36+
}
37+
38+
final expectedStdout = File.getContent('$test/stdout.txt').replace("\r\n", "\n");
39+
final actualStdout = try {
40+
runOutput(test);
41+
} catch (e) {
42+
Sys.println('Test $test failed: $e');
43+
continue;
44+
};
45+
46+
if (actualStdout != expectedStdout) {
47+
Sys.println('Test $test failed: Output did not match');
48+
49+
Sys.println("Expected stdout:");
50+
Sys.println(expectedStdout);
51+
Sys.println("Actual stdout:");
52+
Sys.println(actualStdout);
53+
continue;
54+
}
55+
56+
successes++;
57+
}
58+
59+
Sys.println('Regression tests complete. Successes: $successes / $total');
60+
}

0 commit comments

Comments
 (0)