diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-12-20 12:26:29 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-12-20 12:26:29 +0100 |
commit | fe8d396980f18bf09ee2717817cd795130cf64d1 (patch) | |
tree | ada754952fba10d47caab89f57acbe65ab4c7e55 /unit_tests/shared.h | |
parent | 48c99e29ae38db79522fb2833f3144ae58c7a906 (diff) | |
download | lanes-fe8d396980f18bf09ee2717817cd795130cf64d1.tar.gz lanes-fe8d396980f18bf09ee2717817cd795130cf64d1.tar.bz2 lanes-fe8d396980f18bf09ee2717817cd795130cf64d1.zip |
Migrated unit tests to Catch2 v3.7.1
Diffstat (limited to '')
-rw-r--r-- | unit_tests/shared.h | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/unit_tests/shared.h b/unit_tests/shared.h index bf3a747..2a32269 100644 --- a/unit_tests/shared.h +++ b/unit_tests/shared.h | |||
@@ -20,6 +20,8 @@ class LuaState | |||
20 | 20 | ||
21 | LuaState(LuaState&& rhs_) = default; | 21 | LuaState(LuaState&& rhs_) = default; |
22 | 22 | ||
23 | public: | ||
24 | |||
23 | operator lua_State*() const { return L; } | 25 | operator lua_State*() const { return L; } |
24 | 26 | ||
25 | void stackCheck(int delta_) { STACK_CHECK(L, delta_); } | 27 | void stackCheck(int delta_) { STACK_CHECK(L, delta_); } |
@@ -35,6 +37,11 @@ class LuaState | |||
35 | LuaError loadString(std::string_view const& str_) const; | 37 | LuaError loadString(std::string_view const& str_) const; |
36 | [[nodiscard]] | 38 | [[nodiscard]] |
37 | LuaError loadFile(std::filesystem::path const& root_, std::string_view const& str_) const; | 39 | LuaError loadFile(std::filesystem::path const& root_, std::string_view const& str_) const; |
40 | void requireFailure(std::string_view const& script_); | ||
41 | void requireNotReturnedString(std::string_view const& script_, std::string_view const& unexpected_); | ||
42 | void requireReturnedString(std::string_view const& script_, std::string_view const& expected_); | ||
43 | void requireSuccess(std::string_view const& script_); | ||
44 | void requireSuccess(std::filesystem::path const& root_, std::string_view const& path_); | ||
38 | [[nodiscard]] | 45 | [[nodiscard]] |
39 | LuaError runChunk() const; | 46 | LuaError runChunk() const; |
40 | 47 | ||
@@ -45,9 +52,6 @@ class LuaState | |||
45 | } | 52 | } |
46 | }; | 53 | }; |
47 | 54 | ||
48 | #define LUA_EXPECT_SUCCESS(S_, WHAT_) { LuaState S{ std::move(S_) }; EXPECT_EQ(S.WHAT_, LuaError::OK) << S; } | ||
49 | #define LUA_EXPECT_FAILURE(S_, WHAT_) { LuaState S{ std::move(S_) }; EXPECT_NE(S.WHAT_, LuaError::OK) << S; } | ||
50 | |||
51 | // ################################################################################################# | 55 | // ################################################################################################# |
52 | 56 | ||
53 | enum class TestType | 57 | enum class TestType |
@@ -63,33 +67,17 @@ struct FileRunnerParam | |||
63 | TestType test; | 67 | TestType test; |
64 | }; | 68 | }; |
65 | 69 | ||
66 | class FileRunner : public ::testing::TestWithParam<FileRunnerParam> | 70 | class FileRunner : private LuaState |
67 | { | 71 | { |
68 | protected: | 72 | private: |
69 | LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } }; | ||
70 | std::string root; | ||
71 | 73 | ||
72 | ~FileRunner() override | 74 | std::string root; |
73 | { | ||
74 | lua_settop(L, 0); | ||
75 | } | ||
76 | void SetUp() override | ||
77 | { | ||
78 | lua_settop(L, 0); | ||
79 | } | ||
80 | 75 | ||
81 | void TearDown() override | 76 | public: |
82 | { | ||
83 | lua_settop(L, 0); | ||
84 | } | ||
85 | }; | ||
86 | 77 | ||
87 | // ################################################################################################# | 78 | FileRunner(std::string_view const& where_); |
88 | 79 | ||
89 | class UnitTestRunner : public FileRunner | 80 | void performTest(FileRunnerParam const& testParam_); |
90 | { | ||
91 | public: | ||
92 | UnitTestRunner(); | ||
93 | }; | 81 | }; |
94 | 82 | ||
95 | // ################################################################################################# | 83 | // ################################################################################################# |