-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refac(gen): move generation of test main function into transformer (#294
- Loading branch information
Showing
11 changed files
with
141 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2023-present Lukas Neubert <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
package context | ||
|
||
// Information shared between checker, transformer and gen | ||
pub struct GenContext { | ||
// Testing | ||
global has_test_begin bool | ||
global has_test_end bool | ||
global test_fun_names []string | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-FileCopyrightText: 2023-present Lukas Neubert <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
package transformer | ||
|
||
import bait.ast | ||
|
||
fun (t Transformer) gen_test_main() &ast.File { | ||
mut test_main := ast.FunDecl{ | ||
mix_name = "main" | ||
name = "main" | ||
} | ||
|
||
if t.gen_ctx.has_test_begin { | ||
test_main.stmts.push(ast.ExprStmt{ | ||
expr = ast.CallExpr{ | ||
mix_name = "testsuite_begin" | ||
name = "testsuite_begin" | ||
} | ||
}) | ||
} | ||
|
||
esc_path := t.path.replace("\\", "\\\\") | ||
for name in t.gen_ctx.test_fun_names { | ||
mut val := 'TestRunner_set_test_info(builtin__test_runner, from_js_string("${esc_path}"), from_js_string("${name}"))' | ||
if t.prefs.backend == .c { | ||
val = 'TestRunner_set_test_info(&builtin__test_runner, from_c_string("${esc_path}"), from_c_string("${name}"))' | ||
} | ||
test_main.stmts.push(ast.ExprStmt{ | ||
// TODO properly transform this (requires changes to method calls) | ||
expr = ast.HashExpr{ | ||
val = val | ||
} | ||
}) | ||
test_main.stmts.push(ast.ExprStmt{ | ||
expr = ast.CallExpr{ | ||
mix_name = name | ||
name = name | ||
} | ||
}) | ||
} | ||
|
||
if t.gen_ctx.has_test_end { | ||
test_main.stmts.push(ast.ExprStmt{ | ||
expr = ast.CallExpr{ | ||
mix_name = "testsuite_end" | ||
name = "testsuite_end" | ||
} | ||
}) | ||
} | ||
|
||
// exit(test_runner.exit_code()) | ||
test_main.stmts.push(ast.ExprStmt{ | ||
expr = ast.CallExpr{ | ||
mix_name = "exit" | ||
name = "exit" | ||
args = [ | ||
ast.CallArg{ | ||
// TODO properly transform this (requires changes to method calls) | ||
expr = ast.HashExpr{ | ||
val = "TestRunner_exit_code(builtin__test_runner)" | ||
} | ||
} | ||
] | ||
} | ||
}) | ||
return ast.File{ | ||
stmts = [test_main as ast.Stmt] | ||
} | ||
} |
Oops, something went wrong.