From b99b63af659d3ff1b9b59b9b1ff20e6a5f29b16f Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Fri, 9 Oct 2020 13:24:55 -0400 Subject: [PATCH] lint: Clang format --- test/goalc/framework/test_runner.cpp | 8 ++-- test/goalc/framework/test_runner.h | 2 +- test/goalc/test_arithmetic.cpp | 63 ++++++++++++++------------ test/goalc/test_collections.cpp | 9 ++-- test/goalc/test_control_statements.cpp | 4 +- test/goalc/test_float.cpp | 9 ++-- test/goalc/test_functions.cpp | 12 ++--- test/goalc/test_library.cpp | 2 +- test/goalc/test_logic.cpp | 5 +- test/goalc/test_loop_recur.cpp | 2 +- test/goalc/test_strings.cpp | 12 +++-- test/goalc/test_variables.cpp | 6 +-- test/goalc/test_with_game.cpp | 3 +- test/test_compiler_and_runtime.cpp | 1 - test/test_main.cpp | 10 ++-- 15 files changed, 80 insertions(+), 68 deletions(-) diff --git a/test/goalc/framework/test_runner.cpp b/test/goalc/framework/test_runner.cpp index 5380394881..dd97c3abe3 100644 --- a/test/goalc/framework/test_runner.cpp +++ b/test/goalc/framework/test_runner.cpp @@ -37,7 +37,7 @@ void CompilerTestRunner::run_static_test(inja::Environment& env, std::string& testCategory, const std::string& test_file, const std::vector& expected, - MatchParam truncate) { + MatchParam 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); diff --git a/test/goalc/framework/test_runner.h b/test/goalc/framework/test_runner.h index 504134889f..4358e42a02 100644 --- a/test/goalc/framework/test_runner.h +++ b/test/goalc/framework/test_runner.h @@ -27,7 +27,7 @@ struct CompilerTestRunner { std::string& testCategory, const std::string& test_file, const std::vector& expected, - MatchParam truncate = {}); + MatchParam truncate = {}); void run_test(const std::string& test_category, const std::string& test_file, diff --git a/test/goalc/test_arithmetic.cpp b/test/goalc/test_arithmetic.cpp index 1d40d5d24f..a423a2693a 100644 --- a/test/goalc/test_arithmetic.cpp +++ b/test/goalc/test_arithmetic.cpp @@ -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 { 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"}); } diff --git a/test/goalc/test_collections.cpp b/test/goalc/test_collections.cpp index ecf54cb731..ac80aaf318 100644 --- a/test/goalc/test_collections.cpp +++ b/test/goalc/test_collections.cpp @@ -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"}); } diff --git a/test/goalc/test_control_statements.cpp b/test/goalc/test_control_statements.cpp index 46a502ba5c..75376b9247 100644 --- a/test/goalc/test_control_statements.cpp +++ b/test/goalc/test_control_statements.cpp @@ -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) { diff --git a/test/goalc/test_float.cpp b/test/goalc/test_float.cpp index 000a6e3fff..9770313a3f 100644 --- a/test/goalc/test_float.cpp +++ b/test/goalc/test_float.cpp @@ -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"}); } diff --git a/test/goalc/test_functions.cpp b/test/goalc/test_functions.cpp index 83b20b8ad3..8e048cdab5 100644 --- a/test/goalc/test_functions.cpp +++ b/test/goalc/test_functions.cpp @@ -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"}); } diff --git a/test/goalc/test_library.cpp b/test/goalc/test_library.cpp index ea18da0fc5..b3a9078ca8 100644 --- a/test/goalc/test_library.cpp +++ b/test/goalc/test_library.cpp @@ -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"}); } diff --git a/test/goalc/test_logic.cpp b/test/goalc/test_logic.cpp index 3aa4ed807b..0057f7b5e6 100644 --- a/test/goalc/test_logic.cpp +++ b/test/goalc/test_logic.cpp @@ -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"}); } - \ No newline at end of file diff --git a/test/goalc/test_loop_recur.cpp b/test/goalc/test_loop_recur.cpp index cc0a7b41fb..cbe9c68f6d 100644 --- a/test/goalc/test_loop_recur.cpp +++ b/test/goalc/test_loop_recur.cpp @@ -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"}); } diff --git a/test/goalc/test_strings.cpp b/test/goalc/test_strings.cpp index 12e6e0db80..fff413a03f 100644 --- a/test/goalc/test_strings.cpp +++ b/test/goalc/test_strings.cpp @@ -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 = diff --git a/test/goalc/test_variables.cpp b/test/goalc/test_variables.cpp index 88a1b46510..6c6d093377 100644 --- a/test/goalc/test_variables.cpp +++ b/test/goalc/test_variables.cpp @@ -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"}); } diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index 3f0a4e8d53..20da36bf65 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -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"}); } diff --git a/test/test_compiler_and_runtime.cpp b/test/test_compiler_and_runtime.cpp index 9033aa9994..c2efb2ea31 100644 --- a/test/test_compiler_and_runtime.cpp +++ b/test/test_compiler_and_runtime.cpp @@ -51,4 +51,3 @@ TEST(CompilerAndRuntime, AllowInline) { EXPECT_EQ(got_mult, 1); EXPECT_EQ(got_call, 1); } - diff --git a/test/test_main.cpp b/test/test_main.cpp index 18d44c8300..234ece8fef 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -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(); } \ No newline at end of file