Skip to content

Commit 6588f4c

Browse files
Adding tests for data structures
1 parent e4b892c commit 6588f4c

20 files changed

+1535
-21
lines changed

CMakeLists.txt

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ endif()
119119
# runcpp2
120120
# =========================================================================
121121

122-
add_executable(runcpp2
122+
add_library(runcpp2 STATIC
123123
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/Profile.cpp"
124124
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyInfo.cpp"
125125
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyLinkProperty.cpp"
@@ -139,18 +139,17 @@ add_executable(runcpp2
139139
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/ConfigParsing.cpp"
140140
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/DefaultYAMLs.c"
141141
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/DependenciesHelper.cpp"
142-
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/main.cpp"
143142
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/ParseUtil.cpp"
144143
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/PlatformUtil.cpp"
145-
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/runcpp2.cpp"
146144
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/StringUtil.cpp"
145+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/runcpp2.cpp"
147146
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/BuildsManager.cpp"
148147

149148
)
150149

151-
target_include_directories(runcpp2 PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
152-
153-
target_link_libraries(runcpp2 PRIVATE ssLogger ghc_filesystem System2 ryml::ryml dylib CppOverride)
150+
target_include_directories(runcpp2 PUBLIC "${CMAKE_CURRENT_LIST_DIR}/Include")
151+
target_link_libraries(runcpp2 PRIVATE ssLogger System2 CppOverride dylib)
152+
target_link_libraries(runcpp2 PUBLIC ghc_filesystem ryml::ryml)
154153

155154
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
156155
set(STANDARD_COMPILE_FLAGS "/utf-8;/W1;/DGHC_WIN_DISABLE_WSTRING_STORAGE_TYPE=1")
@@ -173,21 +172,16 @@ target_compile_options(runcpp2 PRIVATE ${STANDARD_COMPILE_FLAGS})
173172
# Define the version macro
174173
target_compile_definitions(runcpp2 PUBLIC RUNCPP2_VERSION="${RUNCPP2_PROJECT_VERSION}")
175174

176-
# TODO: Maybe move this to the UnitTests sub folder
177-
# Unit Tests
175+
add_executable(runcpp2_main "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/main.cpp")
176+
target_compile_options(runcpp2_main PRIVATE ${STANDARD_COMPILE_FLAGS})
177+
target_link_libraries(runcpp2_main PRIVATE runcpp2 ssLogger ghc_filesystem)
178+
set_target_properties(runcpp2_main PROPERTIES OUTPUT_NAME "runcpp2")
179+
178180
if(RUNCPP2_BUILD_TESTS)
179-
add_executable(BuildsManagerTest "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/BuildsManager.cpp"
180-
"${CMAKE_CURRENT_LIST_DIR}/Src/UnitTests/BuildsManagerTest.cpp")
181-
# "${CMAKE_CURRENT_LIST_DIR}/Src/UnitTests/BuildsManager/MockComponents.cpp")
182-
183-
target_include_directories(BuildsManagerTest PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
184-
target_compile_options(BuildsManagerTest PRIVATE "${STANDARD_COMPILE_FLAGS}")
185-
target_link_libraries(BuildsManagerTest PRIVATE ghc_filesystem CppOverride ssTest ssLogger)
186-
target_compile_definitions(BuildsManagerTest PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1)
187-
# set_target_properties(BuildsManagerTest PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
188-
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
189-
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
181+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Src/Tests")
190182
endif()
183+
# Unit Tests
184+
191185

192186

193187

Include/runcpp2/runcpp2.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ namespace runcpp2
5656

5757
void GetDefaultScriptInfo(std::string& scriptInfo);
5858

59+
void SetLogLevel(const std::string& logLevel);
60+
5961
PipelineResult StartPipeline( const std::string& scriptPath,
6062
const std::vector<Data::Profile>& profiles,
6163
const std::string& configPreferredProfile,

Src/Tests/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,36 @@ target_compile_definitions(BuildsManagerTest PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS
99
# set_target_properties(BuildsManagerTest PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
1010
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
1111
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
12+
13+
function(create_data_test TEST_NAME)
14+
add_executable("${TEST_NAME}" "${CMAKE_CURRENT_LIST_DIR}/Data/${TEST_NAME}.cpp")
15+
target_compile_definitions("${TEST_NAME}" PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1)
16+
target_link_libraries("${TEST_NAME}" PUBLIC runcpp2 ssTest)
17+
18+
endfunction()
19+
20+
create_data_test(FilePropertiesTest)
21+
create_data_test(FlagsOverrideInfoTest)
22+
create_data_test(DependencySourceTest)
23+
create_data_test(DependencyCommandsTest)
24+
create_data_test(FilesToCopyInfoTest)
25+
create_data_test(ProfilesCompilesFilesTest)
26+
create_data_test(ProfilesDefinesTest)
27+
create_data_test(DependencyLinkPropertyTest)
28+
create_data_test(FilesTypesInfoTest)
29+
create_data_test(ProfilesFlagsOverrideTest)
30+
create_data_test(StageInfoTest)
31+
create_data_test(DependencyInfoTest)
32+
create_data_test(ScriptInfoTest)
33+
create_data_test(ProfileTest)
34+
35+
if(WIN32)
36+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/RunAllTests.bat"
37+
"${CMAKE_CURRENT_BINARY_DIR}")
38+
else()
39+
file( CHMOD "${CMAKE_CURRENT_LIST_DIR}/RunAllTests.sh"
40+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
41+
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_LIST_DIR}/RunAllTests.sh"
42+
"${CMAKE_CURRENT_BINARY_DIR}/RunAllTests.sh")
43+
endif()
44+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "runcpp2/Data/DependencyCommands.hpp"
2+
#include "ssTest.hpp"
3+
#include "ryml.hpp"
4+
#include "c4/std/string.hpp"
5+
#include "runcpp2/runcpp2.hpp"
6+
7+
int main(int argc, char** argv)
8+
{
9+
runcpp2::SetLogLevel("Warning");
10+
11+
ssTEST_INIT_TEST_GROUP();
12+
13+
ssTEST("DependencyCommands Should Parse Valid YAML")
14+
{
15+
ssTEST_OUTPUT_SETUP
16+
(
17+
const char* yamlStr = R"(
18+
MSVC:
19+
- mkdir build
20+
- cd build
21+
- cmake ..
22+
GCC:
23+
- ./configure
24+
- make
25+
- make install
26+
)";
27+
28+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
29+
ryml::ConstNodeRef root = tree.rootref();
30+
31+
runcpp2::Data::DependencyCommands dependencyCommands;
32+
);
33+
34+
ssTEST_OUTPUT_EXECUTION
35+
(
36+
ryml::ConstNodeRef nodeRef = root;
37+
bool parseResult = dependencyCommands.ParseYAML_Node(nodeRef);
38+
);
39+
40+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should succeed", parseResult);
41+
42+
//Verify parsed values
43+
ssTEST_OUTPUT_ASSERT( "MSVC commands count",
44+
dependencyCommands.CommandSteps.at("MSVC").size() == 3);
45+
ssTEST_OUTPUT_ASSERT( "GCC commands count",
46+
dependencyCommands.CommandSteps.at("GCC").size() == 3);
47+
ssTEST_OUTPUT_ASSERT( "MSVC first command",
48+
dependencyCommands.CommandSteps.at("MSVC").at(0) == "mkdir build");
49+
ssTEST_OUTPUT_ASSERT( "GCC last command",
50+
dependencyCommands.CommandSteps.at("GCC").at(2) == "make install");
51+
52+
//Test ToString() and Equals()
53+
ssTEST_OUTPUT_EXECUTION
54+
(
55+
std::string yamlOutput = dependencyCommands.ToString("");
56+
ryml::Tree outputTree = ryml::parse_in_arena(ryml::to_csubstr(yamlOutput));
57+
58+
runcpp2::Data::DependencyCommands parsedOutput;
59+
nodeRef = outputTree.rootref();
60+
parsedOutput.ParseYAML_Node(nodeRef);
61+
);
62+
63+
ssTEST_OUTPUT_ASSERT( "Parsed output should equal original",
64+
dependencyCommands.Equals(parsedOutput));
65+
};
66+
67+
ssTEST_END_TEST_GROUP();
68+
return 0;
69+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#include "runcpp2/Data/DependencyInfo.hpp"
2+
#include "ssTest.hpp"
3+
#include "ryml.hpp"
4+
#include "c4/std/string.hpp"
5+
#include "runcpp2/runcpp2.hpp"
6+
7+
int main(int argc, char** argv)
8+
{
9+
runcpp2::SetLogLevel("Warning");
10+
11+
ssTEST_INIT_TEST_GROUP();
12+
13+
ssTEST("DependencyInfo Should Parse Valid YAML")
14+
{
15+
ssTEST_OUTPUT_SETUP
16+
(
17+
const char* yamlStr = R"(
18+
Name: MyLibrary
19+
Platforms:
20+
- Windows
21+
- Unix
22+
Source:
23+
Type: Git
24+
Value: https://github.com/user/mylibrary.git
25+
LibraryType: Shared
26+
IncludePaths:
27+
- include
28+
- src
29+
LinkProperties:
30+
Windows:
31+
MSVC:
32+
SearchLibraryNames:
33+
- mylib
34+
SearchDirectories:
35+
- lib/Debug
36+
- lib/Release
37+
ExcludeLibraryNames:
38+
- mylib_test
39+
AdditionalLinkOptions:
40+
- /NODEFAULTLIB
41+
Unix:
42+
GCC:
43+
SearchLibraryNames:
44+
- mylib
45+
SearchDirectories:
46+
- /usr/local/lib
47+
Setup:
48+
Windows:
49+
MSVC:
50+
- mkdir build
51+
- cd build
52+
Unix:
53+
GCC:
54+
- mkdir -p build
55+
- cd build
56+
Build:
57+
Windows:
58+
MSVC:
59+
- cmake ..
60+
- cmake --build .
61+
Unix:
62+
GCC:
63+
- cmake ..
64+
- make
65+
Cleanup:
66+
Windows:
67+
MSVC:
68+
- rmdir /s /q build
69+
Unix:
70+
GCC:
71+
- rm -rf build
72+
FilesToCopy:
73+
Windows:
74+
MSVC:
75+
- bin/Debug/mylib.dll
76+
- bin/Debug/mylib.pdb
77+
Unix:
78+
GCC:
79+
- lib/libmylib.so
80+
)";
81+
82+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
83+
ryml::ConstNodeRef root = tree.rootref();
84+
85+
runcpp2::Data::DependencyInfo dependencyInfo;
86+
);
87+
88+
ssTEST_OUTPUT_EXECUTION
89+
(
90+
ryml::ConstNodeRef nodeRef = root;
91+
bool parseResult = dependencyInfo.ParseYAML_Node(nodeRef);
92+
);
93+
94+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should succeed", parseResult);
95+
96+
//Verify basic fields
97+
ssTEST_OUTPUT_ASSERT("Name", dependencyInfo.Name == "MyLibrary");
98+
ssTEST_OUTPUT_ASSERT("Platforms count", dependencyInfo.Platforms.size() == 2);
99+
ssTEST_OUTPUT_ASSERT( "Library type",
100+
dependencyInfo.LibraryType ==
101+
runcpp2::Data::DependencyLibraryType::SHARED);
102+
ssTEST_OUTPUT_ASSERT("Include paths count", dependencyInfo.IncludePaths.size() == 2);
103+
104+
//Verify Source
105+
ssTEST_OUTPUT_ASSERT( "Source type",
106+
dependencyInfo.Source.Type ==
107+
runcpp2::Data::DependencySourceType::GIT);
108+
ssTEST_OUTPUT_ASSERT( "Source value",
109+
dependencyInfo.Source.Value ==
110+
"https://github.com/user/mylibrary.git");
111+
112+
//Verify Link Properties
113+
ssTEST_OUTPUT_SETUP
114+
(
115+
const runcpp2::Data::ProfileLinkProperty& msvcLink =
116+
dependencyInfo.LinkProperties.at("Windows").ProfileProperties.at("MSVC");
117+
);
118+
119+
ssTEST_OUTPUT_ASSERT("MSVC search lib count", msvcLink.SearchLibraryNames.size() == 1);
120+
ssTEST_OUTPUT_ASSERT("MSVC exclude lib", msvcLink.ExcludeLibraryNames.at(0) == "mylib_test");
121+
122+
//Verify Commands
123+
ssTEST_OUTPUT_ASSERT( "Setup commands count",
124+
dependencyInfo .Setup
125+
.at("Windows")
126+
.CommandSteps
127+
.at("MSVC")
128+
.size() == 2);
129+
130+
ssTEST_OUTPUT_ASSERT( "Build commands count",
131+
dependencyInfo .Build
132+
.at("Unix")
133+
.CommandSteps
134+
.at("GCC")
135+
.size() == 2);
136+
137+
//Verify Files to Copy
138+
ssTEST_OUTPUT_SETUP
139+
(
140+
const std::vector<std::string>& msvcDebugFiles =
141+
dependencyInfo.FilesToCopy.at("Windows").ProfileFiles.at("MSVC");
142+
);
143+
144+
ssTEST_OUTPUT_ASSERT("MSVC files count", msvcDebugFiles.size() == 2);
145+
ssTEST_OUTPUT_ASSERT("MSVC first file", msvcDebugFiles.at(0) == "bin/Debug/mylib.dll");
146+
147+
//Test ToString() and Equals()
148+
ssTEST_OUTPUT_EXECUTION
149+
(
150+
std::string yamlOutput = dependencyInfo.ToString("");
151+
ryml::Tree outputTree = ryml::parse_in_arena(ryml::to_csubstr(yamlOutput));
152+
153+
runcpp2::Data::DependencyInfo parsedOutput;
154+
nodeRef = outputTree.rootref();
155+
parsedOutput.ParseYAML_Node(nodeRef);
156+
);
157+
158+
ssTEST_OUTPUT_ASSERT( "Parsed output should equal original",
159+
dependencyInfo.Equals(parsedOutput));
160+
};
161+
162+
ssTEST_END_TEST_GROUP();
163+
return 0;
164+
}

0 commit comments

Comments
 (0)