feat(selfhost): add 'bux test' command
- 'bux test [dir]' builds the project and runs the resulting binary, reporting 'Tests passed' or 'Tests failed (exit code N)'. - Builds on existing Cli_BuildProject pipeline — test code goes in src/ alongside production code; test assertions use lib/Test.bux.
This commit is contained in:
+42
-2
@@ -605,6 +605,40 @@ func Cli_Init() -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Test command — build and run tests
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func Cli_Test(projectDir: String) -> int {
|
||||||
|
Print("Testing project: ");
|
||||||
|
PrintLine(projectDir);
|
||||||
|
// Build the project first
|
||||||
|
let rc: int = Cli_BuildProject(projectDir);
|
||||||
|
if rc != 0 {
|
||||||
|
PrintLine("Test build failed");
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
// Run the resulting binary
|
||||||
|
let man: Manifest = Manifest_Load(bux_path_join(projectDir, "bux.toml"));
|
||||||
|
var outName: String = man.name;
|
||||||
|
if String_Eq(outName, "") { outName = "bux_out"; }
|
||||||
|
let outBin: String = bux_path_join(bux_path_join(projectDir, "build"), outName);
|
||||||
|
if !FileExists(outBin) {
|
||||||
|
Print("Error: test binary not found: ");
|
||||||
|
PrintLine(outBin);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
let result: int = bux_system(outBin);
|
||||||
|
if result == 0 {
|
||||||
|
PrintLine("Tests passed");
|
||||||
|
} else {
|
||||||
|
Print("Tests failed (exit code ");
|
||||||
|
PrintInt(result as int64);
|
||||||
|
PrintLine(")");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
func Cli_BuildProject(projectDir: String) -> int {
|
func Cli_BuildProject(projectDir: String) -> int {
|
||||||
let man: Manifest = Manifest_Load(bux_path_join(projectDir, "bux.toml"));
|
let man: Manifest = Manifest_Load(bux_path_join(projectDir, "bux.toml"));
|
||||||
var outName: String = man.name;
|
var outName: String = man.name;
|
||||||
@@ -872,7 +906,7 @@ func Cli_Run(args: *String, argCount: int) -> int {
|
|||||||
if argCount < 2 {
|
if argCount < 2 {
|
||||||
PrintLine("Bux Self-Hosting Compiler v0.2.0");
|
PrintLine("Bux Self-Hosting Compiler v0.2.0");
|
||||||
PrintLine("Usage: buxc <command> [args]");
|
PrintLine("Usage: buxc <command> [args]");
|
||||||
PrintLine("Commands: build, check, new, init, run, project, help, version");
|
PrintLine("Commands: build, check, new, init, test, run, project, help, version");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,7 +919,7 @@ func Cli_Run(args: *String, argCount: int) -> int {
|
|||||||
if String_Eq(cmd, "help") || String_Eq(cmd, "--help") || String_Eq(cmd, "-h") {
|
if String_Eq(cmd, "help") || String_Eq(cmd, "--help") || String_Eq(cmd, "-h") {
|
||||||
PrintLine("Bux Self-Hosting Compiler v0.2.0");
|
PrintLine("Bux Self-Hosting Compiler v0.2.0");
|
||||||
PrintLine("Usage: buxc <command> [args]");
|
PrintLine("Usage: buxc <command> [args]");
|
||||||
PrintLine("Commands: build, check, new, init, run, project, help, version");
|
PrintLine("Commands: build, check, new, init, test, run, project, help, version");
|
||||||
PrintLine("Pipeline modules:");
|
PrintLine("Pipeline modules:");
|
||||||
PrintLine(" Lexer ✅ 695 lines");
|
PrintLine(" Lexer ✅ 695 lines");
|
||||||
PrintLine(" Parser ✅ 1004 lines");
|
PrintLine(" Parser ✅ 1004 lines");
|
||||||
@@ -930,6 +964,12 @@ func Cli_Run(args: *String, argCount: int) -> int {
|
|||||||
return Cli_BuildProject(dir);
|
return Cli_BuildProject(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if String_Eq(cmd, "test") {
|
||||||
|
let dir: String = ".";
|
||||||
|
if argCount >= 3 { dir = args[2]; }
|
||||||
|
return Cli_Test(dir);
|
||||||
|
}
|
||||||
|
|
||||||
if String_Eq(cmd, "run") {
|
if String_Eq(cmd, "run") {
|
||||||
let dir: String = ".";
|
let dir: String = ".";
|
||||||
if argCount >= 3 { dir = args[2]; }
|
if argCount >= 3 { dir = args[2]; }
|
||||||
|
|||||||
Reference in New Issue
Block a user