From c14578d9dd4cf663497c05193821f8b018ee00fa Mon Sep 17 00:00:00 2001 From: dimgigov Date: Tue, 9 Jun 2026 17:11:31 +0300 Subject: [PATCH] feat(selfhost): add 'bux test' command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - '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. --- src/cli.bux | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/cli.bux b/src/cli.bux index 74f8364..6ada623 100644 --- a/src/cli.bux +++ b/src/cli.bux @@ -605,6 +605,40 @@ func Cli_Init() -> int { 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 { let man: Manifest = Manifest_Load(bux_path_join(projectDir, "bux.toml")); var outName: String = man.name; @@ -872,7 +906,7 @@ func Cli_Run(args: *String, argCount: int) -> int { if argCount < 2 { PrintLine("Bux Self-Hosting Compiler v0.2.0"); PrintLine("Usage: buxc [args]"); - PrintLine("Commands: build, check, new, init, run, project, help, version"); + PrintLine("Commands: build, check, new, init, test, run, project, help, version"); 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") { PrintLine("Bux Self-Hosting Compiler v0.2.0"); PrintLine("Usage: buxc [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(" Lexer ✅ 695 lines"); PrintLine(" Parser ✅ 1004 lines"); @@ -930,6 +964,12 @@ func Cli_Run(args: *String, argCount: int) -> int { 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") { let dir: String = "."; if argCount >= 3 { dir = args[2]; }