Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] add tests on latest haxe + hashlink #133

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: krdlab/setup-haxe@v1
- name: Print haxe version
run: haxe -version
- name: Install haxelib dependencies
run: |
haxelib git format https://github.com/HaxeFoundation/format.git
Expand All @@ -22,11 +24,50 @@ jobs:
haxelib install vscode-debugadapter
- name: Build extension
run: make build
- name: Build standalone adapter.js
run: haxe build.hxml
- name: Build CLI hl
run: |
cd debugger
haxe debugger.hxml
cd ..

build_and_test_nightly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: krdlab/setup-haxe@v1
with:
haxe-version: latest
- name: Print haxe version
run: haxe -version
- name: Install haxelib dependencies
run: |
haxelib git format https://github.com/HaxeFoundation/format.git
haxelib git hscript https://github.com/HaxeFoundation/hscript.git
haxelib install vshaxe
haxelib install vscode
haxelib install vscode-debugadapter
- name: Build extension
run: make build
- name: Build standalone adapter.js
run: haxe build.hxml

- name: Build CLI hl
run: |
cd debugger
haxe debugger.hxml
cd ..
- name: Install hl
run: |
git clone https://github.com/HaxeFoundation/hashlink.git hashlink
sudo apt-get install -qqy libpng-dev libturbojpeg-dev libvorbis-dev libopenal-dev libsdl2-dev libglu1-mesa-dev libmbedtls-dev libuv1-dev libsqlite3-dev
cd hashlink
make
sudo make install
hl --version
cd ..
- name: Run tests
run: |
cd tests
haxe RunCi.hxml
cd ..
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ package-lock.json
/debugger/args.txt
/debugger/debug.hl
/hldebug-wrapper/build
*.hl
17 changes: 13 additions & 4 deletions hld/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Main {
var breaks = [];
var dbg : hld.Debugger;
var stdin = Sys.stdin();
var isCi = false;

#if nodejs
var process : js.node.child_process.ChildProcess;
Expand Down Expand Up @@ -62,7 +63,11 @@ class Main {
while( inputArgs.length > 0 ) {
var a = inputArgs.pop();
if( StringTools.endsWith(a,'"') ) {
var arg = [a.substr(0,-1)];
if( StringTools.startsWith(a,'"') ) {
args.unshift(a.substr(1,a.length-2));
continue;
}
var arg = [a.substr(0,a.length-1)];
while( true ) {
var a = inputArgs.pop();
if( a == null ) break;
Expand All @@ -77,6 +82,8 @@ class Main {
}
args.unshift(a);
}
case "--ci":
isCi = true;
case "--debug":
Debugger.DEBUG = true;
default:
Expand All @@ -85,7 +92,7 @@ class Main {
}
file = args.shift();
if( file == null ) {
Sys.println("hldebug [-port <port>] [--cwd <path>] <file.hl> [--args <args>] or [<commands>]");
Sys.println("hldebug [-port <port>] [--cwd <path>] <file.hl> [<commands>]");
Sys.exit(1);
}
if( !sys.FileSystem.exists(file) )
Expand Down Expand Up @@ -173,7 +180,8 @@ class Main {
Sys.println("Process has exit");
Sys.exit(0);
case Breakpoint:
Sys.println(dbg.getThreadName(dbg.stoppedThread) + " paused " + frameStr(dbg.getStackFrame()));
var threadName = if( isCi ) "Thread" else dbg.getThreadName(dbg.stoppedThread);
Sys.println(threadName + " paused " + frameStr(dbg.getStackFrame()));
var exc = dbg.getException();
if( exc != null )
Sys.println("Exception: "+dbg.eval.valueStr(exc));
Expand Down Expand Up @@ -218,7 +226,8 @@ class Main {
}
switch( cmd ) {
case "q", "quit":
dumpProcessOut();
if( !isCi )
dumpProcessOut();
return false;
case "r", "run", "c", "continue":
var time = args.shift();
Expand Down
57 changes: 57 additions & 0 deletions tests/RunCi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class RunCi {
static var MAX_TIME_PER_TEST : Float = 2;

static function main() {
var basePath = Sys.getCwd();
var debuggerHL = sys.FileSystem.absolutePath(basePath + "../debugger/debug.hl");
var errorCount = 0;

var tests = sys.FileSystem.readDirectory(basePath + "unit");
for( test in tests ) {
var fullPath = sys.FileSystem.absolutePath(basePath + "unit/" + test);
log('[INFO] $test begin');
changeDirectory(fullPath);
Sys.command("haxe", ["--main", "Test", "-hl", "test.hl"]);
var process = new sys.io.Process("hl", [debuggerHL, "--input", "input.txt"]);
var expectedOutput = sys.io.File.getContent(fullPath + "/output.txt");
var startingTime = haxe.Timer.stamp();
var exitCode : Null<Int> = 0;
while( true ) {
exitCode = process.exitCode(false);
var currentTime = haxe.Timer.stamp();
if( exitCode != null || currentTime - startingTime > MAX_TIME_PER_TEST )
break;
}
process.kill();
var output = process.stdout.readAll().toString();
process.close();
if( exitCode == null ) {
errorCount ++;
log('[ERROR] $test: not terminated in $MAX_TIME_PER_TEST seconds, output:\n$output');
} else if( exitCode != 0 ) {
errorCount ++;
log('[ERROR] $test: exitCode:$exitCode');
} else if( output != expectedOutput ) {
errorCount ++;
log('[ERROR] $test: output:\n$output');
} else {
log('[SUCCESS] $test');
}
}

changeDirectory(basePath);
log('[INFO] all tests end, error count: $errorCount');
if( errorCount > 0 ) {
Sys.exit(1);
}
}

static public function changeDirectory(path : String) {
log('[CWD] Changing directory to $path');
Sys.setCwd(path);
}

static public inline function log(msg : String) {
Sys.println(msg);
}
}
4 changes: 4 additions & 0 deletions tests/RunCi.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--main RunCi
-hl RunCi.hl

--cmd hl RunCi.hl
33 changes: 33 additions & 0 deletions tests/unit/TestRegReuseArg/Test.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Test {
public function new() {
foo(10, 11);
var functionvar = 15;
function bar(x, y) {
var pt = new Point(x, y);
trace(functionvar, pt.x, pt.y); // nargs=3, captured functionvar at r0, x=pt.x=r1, y=pt.y=r2
}
bar(12, 13);
function bar2(x, y) {
var pt = new Point(x, y);
trace(pt.x, pt.y); // nargs=2, x=pt.x=r0, y=pt.y=r1
}
bar2(14, 15);
}
function foo(x : Int, y : Int) {
var pt = new Point(x, y);
trace(pt.x, pt.y); // nargs=3, this at r0, x=pt.x=r1, y=pt.y=r2
}

static function main() {
new Test();
}
}

class Point {
public var x : Int;
public var y : Int;
public inline function new(x = 0, y = 0) {
this.x = x;
this.y = y;
}
}
14 changes: 14 additions & 0 deletions tests/unit/TestRegReuseArg/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--ci
test.hl
"b Test.hx:18"
"b Test.hx:12"
"b Test.hx:7"
r
"p this"
"p pt"
r
"p functionvar"
"p pt"
r
"p pt"
q
29 changes: 29 additions & 0 deletions tests/unit/TestRegReuseArg/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
> b Test.hx:18
Breakpoint set line 18
> b Test.hx:12
Breakpoint set line 12
> b Test.hx:7
Breakpoint set line 7
> r
Thread paused Test.hx:18 (Test::foo)
> p this
Test : Test
> p pt
inlined : Dynamic
x = 10 : Int
y = 11 : Int
> r
Thread paused Test.hx:7
> p functionvar
15 : Int
> p pt
inlined : Dynamic
x = 12 : Int
y = 13 : Int
> r
Thread paused Test.hx:12
> p pt
inlined : Dynamic
x = 14 : Int
y = 15 : Int
> q
12 changes: 12 additions & 0 deletions tests/unit/TestTryCatch/Test.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Test {
static function doThrow() {
throw "from doThrow";
}
static function main() {
try {
doThrow();
} catch(e:String) {
trace(e); // break here should diaplay e
}
}
}
6 changes: 6 additions & 0 deletions tests/unit/TestTryCatch/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--ci
test.hl
"b Test.hx:9"
r
"p e"
q
7 changes: 7 additions & 0 deletions tests/unit/TestTryCatch/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> b Test.hx:9
Breakpoint set line 9
> r
Thread paused Test.hx:9 ($Test::main)
> p e
"from doThrow" : String
> q
29 changes: 29 additions & 0 deletions tests/unit/TestUnifyArg/Test.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Test {
static function main() {
var iig = new InventoryItemGroup();
var it = new Item();
var data = {count : 1, k : it};
var icon = iig.makeIcon(data);
trace(icon);
}
}
class SlotGroup<T> {
public function new() {}
public function makeIcon( item : SlotItem<T> ) : String {
return "" + item;
}
}
class InventoryItemGroup extends SlotGroup<Item> {
override function makeIcon(item : SlotItem<Item>) {
trace(item); // break here should diaplay _tmp_item
return super.makeIcon(item); // break here should display item
}
}
class Item {
public function new() {}
}
abstract SlotItem<T>({ count : Int, k : T }) {
@:from public inline static function from<T>( data : { count : Int, k : T } ) : SlotItem<T> {
return cast data;
}
}
9 changes: 9 additions & 0 deletions tests/unit/TestUnifyArg/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--ci
test.hl
"b Test.hx:18"
"b Test.hx:19"
r
"p _tmp_item"
r
"p item"
q
17 changes: 17 additions & 0 deletions tests/unit/TestUnifyArg/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
> b Test.hx:18
Breakpoint set line 18
> b Test.hx:19
Breakpoint set line 19
> r
Thread paused Test.hx:18 (InventoryItemGroup::makeIcon)
> p _tmp_item
{...} : hl.DynObj
k = Item : Item
count = 1 : Int
> r
Thread paused Test.hx:19 (InventoryItemGroup::makeIcon)
> p item
{...} : hl.DynObj
k = Item : Item
count = 1 : Int
> q
Loading