// Test runner for cleanc backend regression tests // Run with: ./vnew run vlib/v2_toberemoved/gen/cleanc/tests/run_tests.v // Or: cd vlib/v2_toberemoved/gen/cleanc/tests && v run run_tests.v module main import os import time fn main() { t0 := time.now() vroot := os.dir(@VEXE) v2_source := os.join_path(vroot, 'cmd', 'v2', 'v2.v') v2_binary := os.join_path(vroot, 'cmd', 'v2', 'v2') tests_dir := os.join_path(vroot, 'vlib', 'v2', 'gen', 'cleanc', 'tests') // Build v2 compiler (with v1). println('[*] Building v2...') build_res := os.execute('${@VEXE} -gc none -cc cc ${v2_source} -o ${v2_binary}') if build_res.exit_code != 0 { eprintln('Error: Failed to build v2') eprintln(build_res.output) exit(1) } // Find all test files (*.v except run_tests.v). test_files := os.ls(tests_dir) or { eprintln('Error: Cannot list tests directory') exit(1) } mut passed := 0 mut failed := 0 mut test_count := 0 for file in test_files { if !file.ends_with('.v') || file == 'run_tests.v' { continue } test_count++ test_path := os.join_path(tests_dir, file) test_name := file.replace('.v', '') println('\n[*] Testing: ${file}') // Run v2 with cleanc backend. v2_output := os.join_path(tests_dir, 'test_${test_name}') v2_cmd := '${v2_binary} -gc none -backend cleanc ${test_path} -o ${v2_output}' v2_res := os.execute(v2_cmd) if v2_res.exit_code != 0 { eprintln(' [FAIL] v2 compilation failed') eprintln(v2_res.output) failed++ continue } // Run the generated binary. gen_res := os.execute(v2_output) if gen_res.exit_code != 0 { eprintln(' [FAIL] Generated binary exited with code ${gen_res.exit_code}') eprintln(gen_res.output) failed++ continue } // Run reference compiler (v1). ref_res := os.execute('${@VEXE} -gc none -n -w -enable-globals run ${test_path}') if ref_res.exit_code != 0 { eprintln(' [FAIL] Reference compilation failed') eprintln(ref_res.output) failed++ continue } // Compare outputs. expected := ref_res.output.trim_space().replace('\r\n', '\n') actual := gen_res.output.trim_space().replace('\r\n', '\n') if expected == actual { println(' [PASS] Output matches reference') passed++ } else { println(' [FAIL] Output mismatch') println(' Expected:\n${expected}') println(' Got:\n${actual}') failed++ } // Clean up. os.rm(v2_output) or {} os.rm('${v2_output}.c') or {} } println('\n========================================') println('Results: ${passed}/${test_count} tests passed') if failed > 0 { println('${failed} tests FAILED') exit(1) } println('Total time: ${time.since(t0)}') }