generated from threeal/cmake-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: split tests based on context (#156)
* test: split `test_download_package.cmake` into several files Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * test: split `test_build_package.cmake` into several files Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * test: simplify `test_install_package.cmake` file Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * test: rename `test_project_integration.cmake` Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> --------- Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
- Loading branch information
Showing
13 changed files
with
564 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/CDeps.cmake) | ||
|
||
set(CMAKE_GENERATOR "Unix Makefiles") | ||
|
||
set(CDEPS_ROOT .cdeps) | ||
file(REMOVE_RECURSE .cdeps) | ||
|
||
section("it should fail to build a package " | ||
"because it has not been downloaded") | ||
assert_fatal_error( | ||
CALL cdeps_build_package pkg | ||
MESSAGE "CDeps: pkg must be downloaded before building") | ||
endsection() | ||
|
||
file(WRITE .cdeps/pkg/src/CMakeLists.txt | ||
"cmake_minimum_required(VERSION 3.5)\n" | ||
"project(pkg LANGUAGES CXX)\n" | ||
"add_executable(main main.cpp)\n") | ||
|
||
file(WRITE .cdeps/pkg/src/main.cpp | ||
"#include <iostream>\n" | ||
"\n" | ||
"int main() {\n" | ||
" std::cout << \"Hello World!\\n\";\n" | ||
"}\n") | ||
|
||
file(WRITE .cdeps/pkg/src.lock "pkg github.com/user/pkg main") | ||
|
||
section("it should build a package") | ||
cdeps_build_package(pkg) | ||
|
||
section("it should output the build directory variable") | ||
assert(DEFINED pkg_BUILD_DIR) | ||
assert(pkg_BUILD_DIR STREQUAL .cdeps/pkg/build) | ||
endsection() | ||
|
||
section("it should generate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES "^pkg github.com.user.pkg main") | ||
endsection() | ||
|
||
section("it should build to the build directory") | ||
assert(EXISTS .cdeps/pkg/build/CMakeCache.txt) | ||
endsection() | ||
|
||
section("it should build the correct targets") | ||
assert(EXISTS .cdeps/pkg/build/main) | ||
assert_execute_process(.cdeps/pkg/build/main OUTPUT "Hello World!") | ||
endsection() | ||
endsection() | ||
|
||
section("it should not rebuild the package") | ||
block() | ||
set(CMAKE_COMMAND invalid) | ||
cdeps_build_package(pkg) | ||
endblock() | ||
|
||
section("it should maintain the lock file") | ||
file(READ .cdeps/pkg/src.lock CONTENT) | ||
assert(CONTENT MATCHES "^pkg github.com.user.pkg main") | ||
endsection() | ||
|
||
section("it should maintain the build directory") | ||
assert(EXISTS .cdeps/pkg/build/CMakeCache.txt) | ||
endsection() | ||
endsection() | ||
|
||
section("it should rebuild the package because of an invalidated lock file") | ||
file(REMOVE_RECURSE .cdeps/pkg/build) | ||
file(APPEND .cdeps/pkg/build.lock " invalidated") | ||
|
||
cdeps_build_package(pkg) | ||
|
||
section("it should regenerate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES "^pkg github.com.user.pkg main") | ||
endsection() | ||
|
||
section("it should rebuild to the build directory") | ||
assert(EXISTS .cdeps/pkg/build/CMakeCache.txt) | ||
endsection() | ||
endsection() | ||
|
||
section("it should fail to rebuild the package " | ||
"because of a corrupted source file") | ||
file(READ .cdeps/pkg/src/main.cpp ORIGINAL_MAIN_CPP) | ||
file(WRITE .cdeps/pkg/src/main.cpp corrupted) | ||
file(APPEND .cdeps/pkg/build.lock " invalidated") | ||
|
||
assert_fatal_error( | ||
CALL cdeps_build_package pkg | ||
MESSAGE "CDeps: Failed to build pkg:") | ||
|
||
section("it should remove the lock file") | ||
assert(NOT EXISTS .cdeps/pkg/build.lock) | ||
endsection() | ||
|
||
section("it should remove the build directory") | ||
assert(NOT EXISTS .cdeps/pkg/build) | ||
endsection() | ||
|
||
file(WRITE .cdeps/pkg/src/main.cpp "${ORIGINAL_MAIN_CPP}") | ||
endsection() | ||
|
||
section("it should fail to reconfigure the package " | ||
"because of a corrupted CMakelists file") | ||
file(READ .cdeps/pkg/src/CMakeLists.txt ORIGINAL_CMAKELISTS_TXT) | ||
file(WRITE .cdeps/pkg/src/CMakeLists.txt corrupted) | ||
|
||
assert_fatal_error( | ||
CALL cdeps_build_package pkg | ||
MESSAGE "CDeps: Failed to configure pkg:") | ||
|
||
section("it should remove the lock file") | ||
assert(NOT EXISTS .cdeps/pkg/build.lock) | ||
endsection() | ||
|
||
section("it should remove the build directory") | ||
assert(NOT EXISTS .cdeps/pkg/build) | ||
endsection() | ||
|
||
file(WRITE .cdeps/pkg/src/CMakeLists.txt "${ORIGINAL_CMAKELISTS_TXT}") | ||
endsection() | ||
|
||
section("it should rebuild the package after a failure") | ||
cdeps_build_package(pkg) | ||
|
||
section("it should regenerate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES "^pkg github.com.user.pkg main") | ||
endsection() | ||
|
||
section("it should rebuild to the build directory") | ||
assert(EXISTS .cdeps/pkg/build/CMakeCache.txt) | ||
endsection() | ||
endsection() | ||
|
||
file(REMOVE_RECURSE .cdeps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/CDeps.cmake) | ||
|
||
set(CDEPS_ROOT .cdeps) | ||
file(REMOVE_RECURSE .cdeps) | ||
|
||
file(WRITE .cdeps/pkg/src/CMakeLists.txt | ||
"cmake_minimum_required(VERSION 3.5)\n" | ||
"project(pkg LANGUAGES NONE)\n" | ||
"set(GENERATOR \"\${CMAKE_GENERATOR}\" CACHE STRING \"\" FORCE)\n") | ||
|
||
file(WRITE .cdeps/pkg/src.lock "pkg github.com/user/pkg main") | ||
|
||
section("it should build a package with the default generator") | ||
cdeps_build_package(pkg) | ||
|
||
section("it should generate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES [^GENERATOR]) | ||
endsection() | ||
endsection() | ||
|
||
section("it should fail to rebuild the package " | ||
"because of an invalid parent generator") | ||
block() | ||
set(CMAKE_GENERATOR invalid) | ||
assert_fatal_error( | ||
CALL cdeps_build_package pkg | ||
MESSAGE "CDeps: Failed to configure pkg:") | ||
endblock() | ||
|
||
section("it should remove the lock file") | ||
assert(NOT EXISTS .cdeps/pkg/build.lock) | ||
endsection() | ||
endsection() | ||
|
||
section("it should rebuild the package with the parent generator") | ||
block() | ||
set(CMAKE_GENERATOR "Unix Makefiles") | ||
cdeps_build_package(pkg) | ||
endblock() | ||
|
||
section("it should regenerate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES "GENERATOR Unix Makefiles$") | ||
endsection() | ||
|
||
section("it should rebuild with the correct generator") | ||
assert_execute_process( | ||
COMMAND ${CMAKE_COMMAND} -L -N .cdeps/pkg/build | ||
OUTPUT "GENERATOR:STRING=Unix Makefiles") | ||
endsection() | ||
endsection() | ||
|
||
section("it should fail to rebuild the package " | ||
"because of an invalid specified generator") | ||
block() | ||
assert_fatal_error( | ||
CALL cdeps_build_package pkg GENERATOR invalid | ||
MESSAGE "CDeps: Failed to configure pkg:") | ||
endblock() | ||
|
||
section("it should remove the lock file") | ||
assert(NOT EXISTS .cdeps/pkg/build.lock) | ||
endsection() | ||
endsection() | ||
|
||
section("it should rebuild the package with the specified generator") | ||
cdeps_build_package(pkg GENERATOR "Unix Makefiles") | ||
|
||
section("it should regenerate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES "GENERATOR Unix Makefiles$") | ||
endsection() | ||
|
||
section("it should rebuild with the correct generator") | ||
assert_execute_process( | ||
COMMAND ${CMAKE_COMMAND} -L -N .cdeps/pkg/build | ||
OUTPUT "GENERATOR:STRING=Unix Makefiles") | ||
endsection() | ||
endsection() | ||
|
||
file(REMOVE_RECURSE .cdeps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/CDeps.cmake) | ||
|
||
set(CDEPS_ROOT .cdeps) | ||
file(REMOVE_RECURSE .cdeps) | ||
|
||
file(WRITE .cdeps/pkg/src/CMakeLists.txt | ||
"cmake_minimum_required(VERSION 3.5)\n" | ||
"project(pkg LANGUAGES NONE)\n" | ||
"set(FIRST_OPTION \"first\" CACHE STRING \"\")\n" | ||
"set(SECOND_OPTION \"second\" CACHE STRING \"\")\n") | ||
|
||
file(WRITE .cdeps/pkg/src.lock "pkg github.com/user/pkg main") | ||
|
||
section("it should build a package without options") | ||
cdeps_build_package(pkg) | ||
|
||
section("it should generate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES [^OPTIONS]) | ||
endsection() | ||
|
||
section("it should build with the correct options") | ||
assert_execute_process( | ||
COMMAND ${CMAKE_COMMAND} -L -N .cdeps/pkg/build | ||
OUTPUT "FIRST_OPTION:STRING=first.+SECOND_OPTION:STRING=second") | ||
endsection() | ||
endsection() | ||
|
||
section("it should rebuild the package with the specified options") | ||
cdeps_build_package(pkg OPTIONS FIRST_OPTION=pertama SECOND_OPTION=kedua) | ||
|
||
section("it should regenerate the lock file") | ||
file(READ .cdeps/pkg/build.lock CONTENT) | ||
assert(CONTENT MATCHES "OPTIONS FIRST_OPTION=pertama;SECOND_OPTION=kedua$") | ||
endsection() | ||
|
||
section("it should rebuild with the correct options") | ||
assert_execute_process( | ||
COMMAND ${CMAKE_COMMAND} -L -N .cdeps/pkg/build | ||
OUTPUT "FIRST_OPTION:STRING=pertama.+SECOND_OPTION:STRING=kedua") | ||
endsection() | ||
endsection() | ||
|
||
file(REMOVE_RECURSE .cdeps) |
Oops, something went wrong.