mirror of
https://github.com/open-goal/jak-project
synced 2026-07-09 06:53:45 -04:00
Add lambda and static objects (#30)
* add some more tests for let * support static strings * add function calling * add prints for windows debgu * one test only * try swapping r14 and r15 in windows * swap back * disable defun for now * fix massive bug * fix formatting
This commit is contained in:
@@ -55,36 +55,59 @@ struct CompilerTestRunner {
|
||||
struct Test {
|
||||
std::vector<std::string> expected, actual;
|
||||
std::string test_name;
|
||||
bool auto_pass = false;
|
||||
};
|
||||
|
||||
std::vector<Test> tests;
|
||||
|
||||
void run_test(const std::string& test_file, const std::vector<std::string>& expected) {
|
||||
void run_test(const std::string& test_file,
|
||||
const std::vector<std::string>& expected,
|
||||
MatchParam<int> truncate = {}) {
|
||||
fprintf(stderr, "Testing %s\n", test_file.c_str());
|
||||
auto result = c->run_test("goal_src/test/" + test_file);
|
||||
if (!truncate.is_wildcard) {
|
||||
for (auto& x : result) {
|
||||
x = x.substr(0, truncate.value);
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(result, expected);
|
||||
tests.push_back({expected, result, test_file});
|
||||
tests.push_back({expected, result, test_file, false});
|
||||
}
|
||||
|
||||
void run_always_pass(const std::string& test_file) {
|
||||
c->run_test("goal_src/test/" + test_file);
|
||||
tests.push_back({{}, {}, test_file, true});
|
||||
}
|
||||
|
||||
void print_summary() {
|
||||
fmt::print("~~ Compiler Test Summary for {} tests... ~~\n", tests.size());
|
||||
int passed = 0;
|
||||
int passable = 0;
|
||||
int auto_pass = 0;
|
||||
for (auto& test : tests) {
|
||||
if (test.expected == test.actual) {
|
||||
fmt::print("[{:40}] PASS!\n", test.test_name);
|
||||
passed++;
|
||||
if (test.auto_pass) {
|
||||
auto_pass++;
|
||||
fmt::print("[{:40}] AUTO-PASS!\n", test.test_name);
|
||||
} else {
|
||||
fmt::print("[{:40}] FAIL!\n", test.test_name);
|
||||
fmt::print("expected:\n");
|
||||
for (auto& x : test.expected) {
|
||||
fmt::print(" \"{}\"\n", escaped_string(x));
|
||||
}
|
||||
fmt::print("result:\n");
|
||||
for (auto& x : test.actual) {
|
||||
fmt::print(" \"{}\"\n", escaped_string(x));
|
||||
passable++;
|
||||
if (test.expected == test.actual) {
|
||||
fmt::print("[{:40}] PASS!\n", test.test_name);
|
||||
passed++;
|
||||
} else {
|
||||
fmt::print("[{:40}] FAIL!\n", test.test_name);
|
||||
fmt::print("expected:\n");
|
||||
for (auto& x : test.expected) {
|
||||
fmt::print(" \"{}\"\n", escaped_string(x));
|
||||
}
|
||||
fmt::print("result:\n");
|
||||
for (auto& x : test.actual) {
|
||||
fmt::print(" \"{}\"\n", escaped_string(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt::print("Total: passed {}/{} tests\n", passed, tests.size());
|
||||
fmt::print("Total: passed {}/{} passable tests, {} auto-passed\n", passed, passable, auto_pass);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,7 +141,18 @@ TEST(CompilerAndRuntime, CompilerTests) {
|
||||
runner.run_test("test-goto-1.gc", {"3\n"});
|
||||
runner.run_test("test-defglobalconstant-1.gc", {"17\n"});
|
||||
runner.run_test("test-defglobalconstant-2.gc", {"18\n"});
|
||||
runner.run_test("test-simple-function-call.gc", {"30\n"});
|
||||
runner.run_test("test-application-lambda-1.gc", {"2\n"});
|
||||
runner.run_test("test-let-1.gc", {"30\n"});
|
||||
runner.run_test("test-let-star-1.gc", {"30\n"});
|
||||
runner.run_always_pass("test-string-constant-1.gc");
|
||||
|
||||
std::string expected = "\"test string!\"";
|
||||
runner.run_test("test-string-constant-2.gc", {expected}, expected.size());
|
||||
runner.run_test("test-defun-return-constant.gc", {"12\n"});
|
||||
runner.run_test("test-defun-return-symbol.gc", {"42\n"});
|
||||
runner.run_test("test-function-return-arg.gc", {"23\n"});
|
||||
runner.run_test("test-nested-function-call.gc", {"2\n"});
|
||||
compiler.shutdown_target();
|
||||
runtime_thread.join();
|
||||
runner.print_summary();
|
||||
|
||||
Reference in New Issue
Block a user