mirror of
https://github.com/open-goal/jak-project.git
synced 2024-11-27 08:20:47 +00:00
lint: Clang format
This commit is contained in:
parent
83f2751795
commit
b99b63af65
@ -37,7 +37,7 @@ void CompilerTestRunner::run_static_test(inja::Environment& env,
|
||||
std::string& testCategory,
|
||||
const std::string& test_file,
|
||||
const std::vector<std::string>& expected,
|
||||
MatchParam<int> truncate) {
|
||||
MatchParam<int> truncate) {
|
||||
env.write(test_file, {}, test_file);
|
||||
run_test(testCategory, test_file, expected, truncate);
|
||||
}
|
||||
@ -54,14 +54,14 @@ void CompilerTestRunner::run_test(const std::string& test_category,
|
||||
}
|
||||
}
|
||||
|
||||
bool assertionFailed = false;
|
||||
EXPECT_EQ(result, expected) << (assertionFailed = true);
|
||||
bool assertionFailed = false;
|
||||
EXPECT_EQ(result, expected) << (assertionFailed = true);
|
||||
|
||||
if (assertionFailed) {
|
||||
std::string testFile = GoalTest::getGeneratedDir(test_category) + test_file;
|
||||
std::string failedFile = GoalTest::getFailedDir(test_category) + test_file;
|
||||
|
||||
GoalTest::createDirIfAbsent(GoalTest::getFailedDir(test_category));
|
||||
GoalTest::createDirIfAbsent(GoalTest::getFailedDir(test_category));
|
||||
|
||||
std::ifstream src(testFile, std::ios::binary);
|
||||
std::ofstream dst(failedFile, std::ios::binary);
|
||||
|
@ -27,7 +27,7 @@ struct CompilerTestRunner {
|
||||
std::string& testCategory,
|
||||
const std::string& test_file,
|
||||
const std::vector<std::string>& expected,
|
||||
MatchParam<int> truncate = {});
|
||||
MatchParam<int> truncate = {});
|
||||
|
||||
void run_test(const std::string& test_category,
|
||||
const std::string& test_file,
|
||||
|
@ -29,23 +29,26 @@
|
||||
|
||||
// We are using Google Test's paramaterized test feature
|
||||
// This allows us to define a single generic test, and pass in a whole bunch of values
|
||||
// See - https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#value-parameterized-tests
|
||||
// See -
|
||||
// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#value-parameterized-tests
|
||||
struct IntegerParam {
|
||||
// An index is needed to be explicitly set because I couldn't find a way to pull the test-index number from google's API
|
||||
// TODO - if you can find a way, please improve!
|
||||
// But this is needed so we can uniquely save the template files, especially if they error out
|
||||
// Why? - since you may choose to generate random values, it's nice for them to be stored after the tests complete. Some tests may be complex as well
|
||||
// An index is needed to be explicitly set because I couldn't find a way to pull the test-index
|
||||
// number from google's API
|
||||
// TODO - if you can find a way, please improve!
|
||||
// But this is needed so we can uniquely save the template files, especially if they error out
|
||||
// Why? - since you may choose to generate random values, it's nice for them to be stored after
|
||||
// the tests complete. Some tests may be complex as well
|
||||
int index;
|
||||
// Each integer test has a signed value, and can be represented as hex or an integral
|
||||
// Each integer test has a signed value, and can be represented as hex or an integral
|
||||
s64 val;
|
||||
bool hex;
|
||||
|
||||
IntegerParam(s64 val, bool hex = false, int index = 0) : val(val), hex(hex), index(index) {}
|
||||
|
||||
// This is used to generate the value that is passed into the template engine
|
||||
// and injected into the file of lisp code.
|
||||
// In most cases this will probably be a string but look into inja's capabilities
|
||||
// - https://github.com/pantor/inja
|
||||
// This is used to generate the value that is passed into the template engine
|
||||
// and injected into the file of lisp code.
|
||||
// In most cases this will probably be a string but look into inja's capabilities
|
||||
// - https://github.com/pantor/inja
|
||||
std::string toLisp() {
|
||||
// Append hex reader macro '#x'
|
||||
if (hex) {
|
||||
@ -54,9 +57,9 @@ struct IntegerParam {
|
||||
return std::to_string(val);
|
||||
}
|
||||
|
||||
// This is used by the test runner code to know what the expected value is
|
||||
// For a simple example like this, a single eval is all that's required, but for
|
||||
// more complex tests, this may not be the case.
|
||||
// This is used by the test runner code to know what the expected value is
|
||||
// For a simple example like this, a single eval is all that's required, but for
|
||||
// more complex tests, this may not be the case.
|
||||
std::string eval() {
|
||||
if (hex) {
|
||||
int64_t hexVal;
|
||||
@ -142,20 +145,22 @@ class ArithmeticTests : public testing::TestWithParam<IntegerParam> {
|
||||
static Compiler compiler;
|
||||
static GoalTest::CompilerTestRunner runner;
|
||||
|
||||
// Just to promote better test organization, supports nesting the test files 1 directory deep
|
||||
std::string testCategory = "arithmetic";
|
||||
inja::Environment env{GoalTest::getTemplateDir(testCategory), GoalTest::getGeneratedDir(testCategory)};
|
||||
// Just to promote better test organization, supports nesting the test files 1 directory deep
|
||||
std::string testCategory = "arithmetic";
|
||||
inja::Environment env{GoalTest::getTemplateDir(testCategory),
|
||||
GoalTest::getGeneratedDir(testCategory)};
|
||||
};
|
||||
|
||||
// You must initialize the static variables outside of the declaration, or you'll run into unresolved external errors
|
||||
// You must initialize the static variables outside of the declaration, or you'll run into
|
||||
// unresolved external errors
|
||||
std::thread ArithmeticTests::runtime_thread;
|
||||
Compiler ArithmeticTests::compiler;
|
||||
GoalTest::CompilerTestRunner ArithmeticTests::runner;
|
||||
|
||||
|
||||
// Finally, we define our generic test, given our custom class that represents our test inputs
|
||||
// we can generate the lisp file, and pass along the path to the test runner
|
||||
// If the test fails, the test runner will save the template file, with the expected/actual results into the `failed/` directory
|
||||
// If the test fails, the test runner will save the template file, with the expected/actual results
|
||||
// into the `failed/` directory
|
||||
TEST_P(ArithmeticTests, EvalIntegers) {
|
||||
IntegerParam param = GetParam();
|
||||
nlohmann::json data;
|
||||
@ -166,9 +171,11 @@ TEST_P(ArithmeticTests, EvalIntegers) {
|
||||
runner.run_test(testCategory, testFile, {param.eval()});
|
||||
}
|
||||
|
||||
// ValuesIn, is not the only way to use a parameterized test, but the most applicable for this example
|
||||
// You can actually get googletest to compute the permutations for you, which may be useful. Consult their docs.
|
||||
// - https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#value-parameterized-tests
|
||||
// ValuesIn, is not the only way to use a parameterized test, but the most applicable for this
|
||||
// example You can actually get googletest to compute the permutations for you, which may be useful.
|
||||
// Consult their docs.
|
||||
// -
|
||||
// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#value-parameterized-tests
|
||||
INSTANTIATE_TEST_SUITE_P(EvalIntegers,
|
||||
ArithmeticTests,
|
||||
testing::ValuesIn(genIntegerTests(4,
|
||||
@ -179,7 +186,7 @@ INSTANTIATE_TEST_SUITE_P(EvalIntegers,
|
||||
|
||||
TEST_F(ArithmeticTests, Addition) {
|
||||
runner.run_static_test(env, testCategory, "add-int-literals.static.gc", {"13\n"});
|
||||
runner.run_static_test(env, testCategory, "add-let.static.gc", {"7\n"});
|
||||
runner.run_static_test(env, testCategory, "add-let.static.gc", {"7\n"});
|
||||
}
|
||||
|
||||
TEST_F(ArithmeticTests, AddIntegerFunction) {
|
||||
@ -188,7 +195,7 @@ TEST_F(ArithmeticTests, AddIntegerFunction) {
|
||||
|
||||
TEST_F(ArithmeticTests, AddIntegerMultiple) {
|
||||
runner.run_static_test(env, testCategory, "add-int-multiple.static.gc", {"15\n"});
|
||||
runner.run_static_test(env, testCategory, "add-int-multiple-2.static.gc", {"15\n"});
|
||||
runner.run_static_test(env, testCategory, "add-int-multiple-2.static.gc", {"15\n"});
|
||||
}
|
||||
|
||||
TEST_F(ArithmeticTests, AddIntegerVariables) {
|
||||
@ -201,7 +208,7 @@ TEST_F(ArithmeticTests, AshFunction) {
|
||||
|
||||
TEST_F(ArithmeticTests, Division) {
|
||||
runner.run_static_test(env, testCategory, "divide-1.static.gc", {"6\n"});
|
||||
runner.run_static_test(env, testCategory, "divide-2.static.gc", {"7\n"});
|
||||
runner.run_static_test(env, testCategory, "divide-2.static.gc", {"7\n"});
|
||||
}
|
||||
|
||||
TEST_F(ArithmeticTests, IntegerSymbol) {
|
||||
@ -214,7 +221,7 @@ TEST_F(ArithmeticTests, Modulus) {
|
||||
|
||||
TEST_F(ArithmeticTests, Multiplication) {
|
||||
runner.run_static_test(env, testCategory, "multiply.static.gc", {"-12\n"});
|
||||
runner.run_static_test(env, testCategory, "multiply-let.static.gc", {"3\n"});
|
||||
runner.run_static_test(env, testCategory, "multiply-let.static.gc", {"3\n"});
|
||||
}
|
||||
|
||||
TEST_F(ArithmeticTests, NestedFunctionCall) {
|
||||
@ -227,6 +234,6 @@ TEST_F(ArithmeticTests, ShiftOperations) {
|
||||
|
||||
TEST_F(ArithmeticTests, Subtraction) {
|
||||
runner.run_static_test(env, testCategory, "subtract-1.static.gc", {"4\n"});
|
||||
runner.run_static_test(env, testCategory, "subtract-2.static.gc", {"4\n"});
|
||||
runner.run_static_test(env, testCategory, "subtract-let.static.gc", {"3\n"});
|
||||
runner.run_static_test(env, testCategory, "subtract-2.static.gc", {"4\n"});
|
||||
runner.run_static_test(env, testCategory, "subtract-let.static.gc", {"3\n"});
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ GoalTest::CompilerTestRunner CollectionTests::runner;
|
||||
|
||||
TEST_F(CollectionTests, Pairs) {
|
||||
runner.run_static_test(env, testCategory, "empty-pair.static.gc", {"()\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "pair-check.static.gc", {"#t#f\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "pair-check.static.gc", {"#t#f\n0\n"});
|
||||
}
|
||||
|
||||
TEST_F(CollectionTests, Lists) {
|
||||
@ -71,7 +71,8 @@ TEST_F(CollectionTests, InlineArray) {
|
||||
|
||||
TEST_F(CollectionTests, Operations) {
|
||||
runner.run_static_test(env, testCategory, "cons.static.gc", {"(a . b)\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "car-cdr-get.static.gc", {"ab\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "car-cdr-set.static.gc", {"(c . d)\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-car-cdr-set.static.gc", {"efgh\n((e . g) f . h)\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "car-cdr-get.static.gc", {"ab\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "car-cdr-set.static.gc", {"(c . d)\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-car-cdr-set.static.gc",
|
||||
{"efgh\n((e . g) f . h)\n0\n"});
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ TEST_F(ControlStatementTests, ConditionalCompilation) {
|
||||
|
||||
TEST_F(ControlStatementTests, Blocks) {
|
||||
runner.run_static_test(env, testCategory, "nested-blocks-1.static.gc", {"7\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-blocks-2.static.gc", {"8\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-blocks-3.static.gc", {"7\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-blocks-2.static.gc", {"8\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-blocks-3.static.gc", {"7\n"});
|
||||
}
|
||||
|
||||
TEST_F(ControlStatementTests, GoTo) {
|
||||
|
@ -58,12 +58,13 @@ GoalTest::CompilerTestRunner FloatTests::runner;
|
||||
|
||||
TEST_F(FloatTests, Constants) {
|
||||
runner.run_static_test(env, testCategory, "float.static.gc", {"1067316150\n"});
|
||||
runner.run_static_test(env, testCategory, "function-return-float-constant.static.gc", {"3.14149\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "function-return-float-constant.static.gc",
|
||||
{"3.14149\n0\n"});
|
||||
}
|
||||
|
||||
TEST_F(FloatTests, Operations) {
|
||||
runner.run_static_test(env, testCategory, "float-pow.static.gc", {"256\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "float-product.static.gc", {"120.0000\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "float-product.static.gc", {"120.0000\n0\n"});
|
||||
}
|
||||
|
||||
TEST_F(FloatTests, Symbols) {
|
||||
@ -72,5 +73,7 @@ TEST_F(FloatTests, Symbols) {
|
||||
|
||||
TEST_F(FloatTests, Functions) {
|
||||
runner.run_static_test(env, testCategory, "float-function.static.gc", {"10.152\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-float-functions.static.gc", {"i 1.4400 3.4000\nr 10.1523\ni 1.2000 10.1523\nr 17.5432\n17.543 10.152\n0\n"});
|
||||
runner.run_static_test(
|
||||
env, testCategory, "nested-float-functions.static.gc",
|
||||
{"i 1.4400 3.4000\nr 10.1523\ni 1.2000 10.1523\nr 17.5432\n17.543 10.152\n0\n"});
|
||||
}
|
||||
|
@ -58,22 +58,22 @@ GoalTest::CompilerTestRunner FunctionTests::runner;
|
||||
|
||||
TEST_F(FunctionTests, Definitions) {
|
||||
runner.run_static_test(env, testCategory, "defun-return-constant.static.gc", {"12\n"});
|
||||
runner.run_static_test(env, testCategory, "defun-return-symbol.static.gc", {"42\n"});
|
||||
runner.run_static_test(env, testCategory, "defun-return-symbol.static.gc", {"42\n"});
|
||||
}
|
||||
|
||||
TEST_F(FunctionTests, ReturnValue) {
|
||||
runner.run_static_test(env, testCategory, "return.static.gc", {"77\n"});
|
||||
runner.run_static_test(env, testCategory, "return.static.gc", {"77\n"});
|
||||
runner.run_static_test(env, testCategory, "return-arg.static.gc", {"23\n"});
|
||||
runner.run_static_test(env, testCategory, "return-colors.static.gc", {"77\n"});
|
||||
runner.run_static_test(env, testCategory, "return-colors.static.gc", {"77\n"});
|
||||
}
|
||||
|
||||
TEST_F(FunctionTests, Calling) {
|
||||
runner.run_static_test(env, testCategory, "nested-call.static.gc", {"2\n"});
|
||||
runner.run_static_test(env, testCategory, "nested-call.static.gc", {"2\n"});
|
||||
runner.run_static_test(env, testCategory, "inline-call.static.gc", {"44\n"});
|
||||
runner.run_static_test(env, testCategory, "simple-call.static.gc", {"30\n"});
|
||||
runner.run_static_test(env, testCategory, "simple-call.static.gc", {"30\n"});
|
||||
}
|
||||
|
||||
TEST_F(FunctionTests, Anonymous) {
|
||||
runner.run_static_test(env, testCategory, "declare-inline.static.gc", {"32\n"});
|
||||
runner.run_static_test(env, testCategory, "declare-inline.static.gc", {"32\n"});
|
||||
runner.run_static_test(env, testCategory, "lambda-1.static.gc", {"2\n"});
|
||||
}
|
||||
|
@ -66,5 +66,5 @@ TEST_F(LibraryTests, Protect) {
|
||||
|
||||
TEST_F(LibraryTests, Align) {
|
||||
runner.run_static_test(env, testCategory, "align16-1.static.gc", {"80\n"});
|
||||
runner.run_static_test(env, testCategory, "align16-2.static.gc", {"64\n"});
|
||||
runner.run_static_test(env, testCategory, "align16-2.static.gc", {"64\n"});
|
||||
}
|
||||
|
@ -58,11 +58,10 @@ GoalTest::CompilerTestRunner LogicTests::runner;
|
||||
|
||||
TEST_F(LogicTests, LogicalOperators) {
|
||||
runner.run_static_test(env, testCategory, "logand.static.gc", {"4\n"});
|
||||
runner.run_static_test(env, testCategory, "logior.static.gc", {"60\n"});
|
||||
runner.run_static_test(env, testCategory, "logxor.static.gc", {"56\n"});
|
||||
runner.run_static_test(env, testCategory, "logior.static.gc", {"60\n"});
|
||||
runner.run_static_test(env, testCategory, "logxor.static.gc", {"56\n"});
|
||||
}
|
||||
|
||||
TEST_F(LogicTests, Comparison) {
|
||||
runner.run_static_test(env, testCategory, "signed-int-compare.static.gc", {"12\n"});
|
||||
}
|
||||
|
@ -62,5 +62,5 @@ TEST_F(LoopRecurTests, DoTimes) {
|
||||
|
||||
TEST_F(LoopRecurTests, Factorial) {
|
||||
runner.run_static_test(env, testCategory, "factorial-recursive.static.gc", {"3628800\n"});
|
||||
runner.run_static_test(env, testCategory, "factorial-iterative.static.gc", {"3628800\n"});
|
||||
runner.run_static_test(env, testCategory, "factorial-iterative.static.gc", {"3628800\n"});
|
||||
}
|
||||
|
@ -58,18 +58,20 @@ GoalTest::CompilerTestRunner StringTests::runner;
|
||||
|
||||
TEST_F(StringTests, Constants) {
|
||||
// TODO - runner.run_static_test(env, testCategory, "string-constant-1.static.gc");
|
||||
std::string expected = "\"test string!\"";
|
||||
runner.run_static_test(env, testCategory, "string-constant-2.static.gc", {expected}, expected.size());
|
||||
std::string expected = "\"test string!\"";
|
||||
runner.run_static_test(env, testCategory, "string-constant-2.static.gc", {expected},
|
||||
expected.size());
|
||||
}
|
||||
|
||||
TEST_F(StringTests, Symbols) {
|
||||
runner.run_static_test(env, testCategory, "quote-symbol.static.gc", {"banana\n0\n"});
|
||||
std::string expected = "test-string";
|
||||
runner.run_static_test(env, testCategory, "string-symbol.static.gc", {expected}, expected.size());
|
||||
std::string expected = "test-string";
|
||||
runner.run_static_test(env, testCategory, "string-symbol.static.gc", {expected}, expected.size());
|
||||
}
|
||||
|
||||
TEST_F(StringTests, Formatting) {
|
||||
runner.run_static_test(env, testCategory, "format-reg-order.static.gc", {"test 1 2 3 4 5 6\n0\n"});
|
||||
runner.run_static_test(env, testCategory, "format-reg-order.static.gc",
|
||||
{"test 1 2 3 4 5 6\n0\n"});
|
||||
}
|
||||
|
||||
// expected =
|
||||
|
@ -58,7 +58,7 @@ GoalTest::CompilerTestRunner VariableTests::runner;
|
||||
|
||||
TEST_F(VariableTests, Globals) {
|
||||
runner.run_static_test(env, testCategory, "defglobalconstant-1.static.gc", {"17\n"});
|
||||
runner.run_static_test(env, testCategory, "defglobalconstant-2.static.gc", {"18\n"});
|
||||
runner.run_static_test(env, testCategory, "defglobalconstant-2.static.gc", {"18\n"});
|
||||
}
|
||||
|
||||
TEST_F(VariableTests, Definitions) {
|
||||
@ -67,6 +67,6 @@ TEST_F(VariableTests, Definitions) {
|
||||
|
||||
TEST_F(VariableTests, Let) {
|
||||
runner.run_static_test(env, testCategory, "let.static.gc", {"30\n"});
|
||||
runner.run_static_test(env, testCategory, "let-star.static.gc", {"30\n"});
|
||||
runner.run_static_test(env, testCategory, "mlet.static.gc", {"10\n"});
|
||||
runner.run_static_test(env, testCategory, "let-star.static.gc", {"30\n"});
|
||||
runner.run_static_test(env, testCategory, "mlet.static.gc", {"10\n"});
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ TEST_F(WithGameTests, All) {
|
||||
get_test_pass_string("string-type", 4));
|
||||
runner.run_static_test(env, testCategory, "test-new-string.gc",
|
||||
get_test_pass_string("new-string", 5));*/
|
||||
//runner.run_static_test(env, testCategory, "test-addr-of.gc", get_test_pass_string("addr-of", 2));
|
||||
// runner.run_static_test(env, testCategory, "test-addr-of.gc", get_test_pass_string("addr-of",
|
||||
// 2));
|
||||
runner.run_static_test(env, testCategory, "test-set-self.gc", {"#t\n0\n"});
|
||||
}
|
||||
|
@ -51,4 +51,3 @@ TEST(CompilerAndRuntime, AllowInline) {
|
||||
EXPECT_EQ(got_mult, 1);
|
||||
EXPECT_EQ(got_call, 1);
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
// Re-init failed folder
|
||||
std::string failedFolder = file_util::get_file_path({"test/goalc/source_generated/failed/"});
|
||||
// Re-init failed folder
|
||||
std::string failedFolder = file_util::get_file_path({"test/goalc/source_generated/failed/"});
|
||||
if (std::filesystem::exists(failedFolder)) {
|
||||
std::filesystem::remove_all(failedFolder);
|
||||
}
|
||||
std::filesystem::create_directory(failedFolder);
|
||||
std::filesystem::remove_all(failedFolder);
|
||||
}
|
||||
std::filesystem::create_directory(failedFolder);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue
Block a user