-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP #846 Initial idea for unit tests for ModLibrary #919
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,27 @@ | |
#include <tuple> | ||
#include <vector> | ||
|
||
struct Filesystem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to self, move/rename when done, discuss with Nikolai |
||
{ | ||
using IsDirectoryFuncT = | ||
bool (*)(const std::filesystem::path& p, std::error_code& ec); | ||
using ExistsFuncT = | ||
bool (*)(const std::filesystem::path& p, std::error_code& ec) noexcept; | ||
using DirectoryIterateCallbackFuncT = | ||
bool (*)(const std::filesystem::path& p, void* user_data) noexcept; | ||
using DirectoryIterateFuncT = void (*)( | ||
const std::filesystem::path& p, | ||
std::filesystem::directory_options options, | ||
std::error_code& ec, | ||
DirectoryIterateCallbackFuncT callback, | ||
void* user_data) noexcept; | ||
|
||
IsDirectoryFuncT f_is_directory; | ||
ExistsFuncT f_exists; | ||
DirectoryIterateFuncT f_directory_iterate; | ||
}; | ||
|
||
extern const Filesystem gNativeFilesystemHandle; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we could extend this for other purposes |
||
|
||
namespace rigel::data | ||
{ | ||
|
@@ -57,7 +78,7 @@ class ModLibrary | |
std::vector<ModStatus> initialSelection); | ||
|
||
void updateGamePath(std::filesystem::path gamePath); | ||
void rescan(); | ||
void rescan(const Filesystem& fsHandle = gNativeFilesystemHandle); | ||
|
||
[[nodiscard]] std::vector<std::filesystem::path> enabledModPaths() const; | ||
[[nodiscard]] const std::string& modDirName(int index) const; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
add_executable(tests | ||
test_main.cpp | ||
test_array_view.cpp | ||
test_duke_script_loader.cpp | ||
test_elevator.cpp | ||
test_high_score_list.cpp | ||
test_json_utils.cpp | ||
test_letter_collection.cpp | ||
test_physics_system.cpp | ||
test_player.cpp | ||
test_rng.cpp | ||
test_spike_ball.cpp | ||
test_string_utils.cpp | ||
test_timing.cpp | ||
# test_array_view.cpp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to self: so that I can compile faster, remove these when ready |
||
# test_duke_script_loader.cpp | ||
# test_elevator.cpp | ||
# test_high_score_list.cpp | ||
# test_json_utils.cpp | ||
# test_letter_collection.cpp | ||
# test_physics_system.cpp | ||
# test_player.cpp | ||
# test_rng.cpp | ||
# test_spike_ball.cpp | ||
# test_string_utils.cpp | ||
# test_timing.cpp | ||
|
||
test_mod_library.cpp | ||
) | ||
|
||
target_link_libraries(tests | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <base/warnings.hpp> | ||
#include <data/mod_library.hpp> | ||
|
||
RIGEL_DISABLE_WARNINGS | ||
#include <catch.hpp> | ||
RIGEL_RESTORE_WARNINGS | ||
|
||
#include <cstdio> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did I leave this here? |
||
|
||
TEST_CASE("Mod library rescan") | ||
{ | ||
namespace fs = std::filesystem; | ||
|
||
rigel::data::ModLibrary ml{"/tmp", {}, {}}; | ||
|
||
Filesystem mockFsHandle{ | ||
[](const std::filesystem::path& p, std::error_code& ec) noexcept -> bool | ||
{ return true; }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foolish mocks, but I just wanted a proof of concept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even without Gmock we can mock these nicely, we can use some static arrays of booleans and iterate through them with a counter (similar to WillOnce/WillRepeteadely) I think we can also hack the directory iteration function for all the calls we need (similarly with an array and counter) since we expect that one to be called twice - doable |
||
[](const std::filesystem::path& p, std::error_code& ec) noexcept -> bool | ||
{ return true; }, | ||
[]( | ||
const std::filesystem::path& p, | ||
std::filesystem::directory_options options, | ||
std::error_code& ec, | ||
Filesystem::DirectoryIterateCallbackFuncT callback, | ||
void* user_data) noexcept { | ||
}}; | ||
|
||
ml.rescan(mockFsHandle); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self: adapt to this code base's style guide (sorry! was in a rush for a Proof of Concept)