From f712c615ce5ae3e073ccb7eb215689f98866659b Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Fri, 9 Oct 2020 19:37:09 -0400 Subject: [PATCH] Fix remaining failing tests --- test/CMakeLists.txt | 7 ++- test/goalc/CMakeLists.txt | 3 +- .../with_game}/test-build-game.gc | 0 test/goalc/test_compiler.cpp | 11 ++++ test/goalc/test_functions.cpp | 39 ++++++++++++++ test/goalc/test_with_game.cpp | 7 +++ test/test_compiler_and_runtime.cpp | 53 ------------------- test/test_main.cpp | 3 +- 8 files changed, 64 insertions(+), 59 deletions(-) rename {goal_src/test => test/goalc/source_templates/with_game}/test-build-game.gc (100%) create mode 100644 test/goalc/test_compiler.cpp delete mode 100644 test/test_compiler_and_runtime.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9c9e92e326..299930c765 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,10 +15,9 @@ add_executable(goalc-test test_emitter_xmm32.cpp test_emitter_integer_math.cpp test_common_util.cpp - test_compiler_and_runtime.cpp test_deftype.cpp - ${GOALC_TEST_FRAMEWORK_SOURCES} - ${GOALC_TEST_CASES}) + ${GOALC_TEST_FRAMEWORK_SOURCES} + ${GOALC_TEST_CASES}) enable_testing() @@ -26,7 +25,7 @@ IF (WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # TODO - split out these declarations for platform specific includes - target_link_libraries(goalc-test cross_sockets listener mman goos common_util runtime compiler type_system gtest) + target_link_libraries(goalc-test cross_sockets goos common_util listener runtime compiler type_system gtest mman) ELSE() target_link_libraries(goalc-test cross_sockets goos common_util listener runtime compiler type_system gtest) ENDIF() diff --git a/test/goalc/CMakeLists.txt b/test/goalc/CMakeLists.txt index b8ac6b67c6..e5e374b193 100644 --- a/test/goalc/CMakeLists.txt +++ b/test/goalc/CMakeLists.txt @@ -2,6 +2,7 @@ set(GOALC_TEST_CASES "goalc/test_arithmetic.cpp" + "goalc/test_compiler.cpp" "goalc/test_control_statements.cpp" "goalc/test_collections.cpp" "goalc/test_float.cpp" @@ -15,7 +16,7 @@ set(GOALC_TEST_CASES "goalc/test_strings.cpp" "goalc/test_symbols.cpp" "goalc/test_variables.cpp" - # TODO - Failing! "goalc/test_with_game.cpp" + "goalc/test_with_game.cpp" ) set(GOALC_TEST_FRAMEWORK_SOURCES diff --git a/goal_src/test/test-build-game.gc b/test/goalc/source_templates/with_game/test-build-game.gc similarity index 100% rename from goal_src/test/test-build-game.gc rename to test/goalc/source_templates/with_game/test-build-game.gc diff --git a/test/goalc/test_compiler.cpp b/test/goalc/test_compiler.cpp new file mode 100644 index 0000000000..81bc1b7720 --- /dev/null +++ b/test/goalc/test_compiler.cpp @@ -0,0 +1,11 @@ +#include +#include + +#include "gtest/gtest.h" +#include "game/runtime.h" +#include "goalc/listener/Listener.h" +#include "goalc/compiler/Compiler.h" + +TEST(CompilerAndRuntime, ConstructCompiler) { + Compiler compiler; +} \ No newline at end of file diff --git a/test/goalc/test_functions.cpp b/test/goalc/test_functions.cpp index 8e048cdab5..2ba12fcad4 100644 --- a/test/goalc/test_functions.cpp +++ b/test/goalc/test_functions.cpp @@ -77,3 +77,42 @@ TEST_F(FunctionTests, Anonymous) { runner.run_static_test(env, testCategory, "declare-inline.static.gc", {"32\n"}); runner.run_static_test(env, testCategory, "lambda-1.static.gc", {"2\n"}); } + +TEST_F(FunctionTests, InlineIsInline) { + auto code = compiler.get_goos().reader.read_from_file( + {"test/goalc/source_templates/functions/declare-inline.static.gc"}); + auto compiled = compiler.compile_object_file("test-code", code, true); + EXPECT_EQ(compiled->functions().size(), 2); + auto& ir = compiled->top_level_function().code(); + bool got_mult = false; + for (auto& x : ir) { + EXPECT_EQ(dynamic_cast(x.get()), nullptr); + auto as_im = dynamic_cast(x.get()); + if (as_im) { + EXPECT_EQ(as_im->get_kind(), IntegerMathKind::IMUL_32); + got_mult = true; + } + } + EXPECT_TRUE(got_mult); +} + +TEST_F(FunctionTests, AllowInline) { + auto code = compiler.get_goos().reader.read_from_file( + {"test/goalc/source_templates/functions/inline-call.static.gc"}); + auto compiled = compiler.compile_object_file("test-code", code, true); + EXPECT_EQ(compiled->functions().size(), 2); + auto& ir = compiled->top_level_function().code(); + int got_mult = 0; + int got_call = 0; + for (auto& x : ir) { + if (dynamic_cast(x.get())) { + got_call++; + } + auto as_im = dynamic_cast(x.get()); + if (as_im && as_im->get_kind() == IntegerMathKind::IMUL_32) { + got_mult++; + } + } + EXPECT_EQ(got_mult, 1); + EXPECT_EQ(got_call, 1); +} diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index 20da36bf65..3daf11b176 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -27,6 +27,13 @@ struct WithGameParam { class WithGameTests : public testing::TestWithParam { public: static void SetUpTestSuite() { + try { + compiler.run_test_no_load("test/goalc/source_templates/with_game/test-build-game.gc"); + } catch (std::exception& e) { + fprintf(stderr, "caught exception %s\n", e.what()); + EXPECT_TRUE(false); + } + runtime_thread = std::thread((GoalTest::runtime_with_kernel)); runner.c = &compiler; } diff --git a/test/test_compiler_and_runtime.cpp b/test/test_compiler_and_runtime.cpp deleted file mode 100644 index c2efb2ea31..0000000000 --- a/test/test_compiler_and_runtime.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include - -#include "gtest/gtest.h" -#include "game/runtime.h" -#include "goalc/listener/Listener.h" -#include "goalc/compiler/Compiler.h" - -TEST(CompilerAndRuntime, ConstructCompiler) { - Compiler compiler; -} - -// TODO -move these into another file? -TEST(CompilerAndRuntime, InlineIsInline) { - Compiler compiler; - auto code = - compiler.get_goos().reader.read_from_file({"goal_src", "test", "test-declare-inline.gc"}); - auto compiled = compiler.compile_object_file("test-code", code, true); - EXPECT_EQ(compiled->functions().size(), 2); - auto& ir = compiled->top_level_function().code(); - bool got_mult = false; - for (auto& x : ir) { - EXPECT_EQ(dynamic_cast(x.get()), nullptr); - auto as_im = dynamic_cast(x.get()); - if (as_im) { - EXPECT_EQ(as_im->get_kind(), IntegerMathKind::IMUL_32); - got_mult = true; - } - } - EXPECT_TRUE(got_mult); -} - -TEST(CompilerAndRuntime, AllowInline) { - Compiler compiler; - auto code = - compiler.get_goos().reader.read_from_file({"goal_src", "test", "test-inline-call.gc"}); - auto compiled = compiler.compile_object_file("test-code", code, true); - EXPECT_EQ(compiled->functions().size(), 2); - auto& ir = compiled->top_level_function().code(); - int got_mult = 0; - int got_call = 0; - for (auto& x : ir) { - if (dynamic_cast(x.get())) { - got_call++; - } - auto as_im = dynamic_cast(x.get()); - if (as_im && as_im->get_kind() == IntegerMathKind::IMUL_32) { - got_mult++; - } - } - EXPECT_EQ(got_mult, 1); - EXPECT_EQ(got_call, 1); -} diff --git a/test/test_main.cpp b/test/test_main.cpp index 234ece8fef..950521c20b 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -1,6 +1,7 @@ #include "gtest/gtest.h" -#include +#include "common/util/FileUtil.h" + #include int main(int argc, char** argv) {