From c3d8112187255d24eaeb0d579e52b13e3df659fd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 15 May 2020 14:38:45 +0200 Subject: [PATCH] CMake: allow fine-tuning tests - The Python configuration tests sometimes need extra setup, so do that through a CMakeTests.txt file in the test directory. - Patch up existing tests: - grubcfg needs /tmp/calamares/etc/default to exist - rawfs won't work on FreeBSD because of differences in /proc --- CHANGES | 2 ++ .../CalamaresAddModuleSubdirectory.cmake | 19 ++++++++++++++++--- src/modules/grubcfg/tests/CMakeTests.txt | 12 ++++++++++++ src/modules/rawfs/tests/CMakeTests.txt | 8 ++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/modules/grubcfg/tests/CMakeTests.txt create mode 100644 src/modules/rawfs/tests/CMakeTests.txt diff --git a/CHANGES b/CHANGES index 0e8221bf0..ee9d29770 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ This release contains contributions from (alphabetically by first name): QML-based modules -- with a single `-DWITH_QML=OFF` at CMake time. This removes QML from Calamares' dependency footprint (but only saves 200kB in Calamares itself). + - Tests have been extended and now support a tests/CMakeTests.txt file + for fine-tuning tests for Python modules. ## Modules ## - No module changes yet diff --git a/CMakeModules/CalamaresAddModuleSubdirectory.cmake b/CMakeModules/CalamaresAddModuleSubdirectory.cmake index 1af520ca8..981ec4a01 100644 --- a/CMakeModules/CalamaresAddModuleSubdirectory.cmake +++ b/CMakeModules/CalamaresAddModuleSubdirectory.cmake @@ -126,10 +126,10 @@ function( calamares_add_module_subdirectory ) endif() message( "" ) # We copy over the lang directory, if any - if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" ) + if( IS_DIRECTORY "${_mod_dir}/lang" ) install_calamares_gettext_translations( ${SUBDIRECTORY} - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" + SOURCE_DIR "${_mod_dir}/lang" FILENAME ${SUBDIRECTORY}.mo RENAME calamares-${SUBDIRECTORY}.mo ) @@ -162,6 +162,16 @@ function( calamares_add_module_subdirectory ) # may try to do things to the running system. Needs work to make that a # safe thing to do. # + # If the module has a tests/ subdirectory with *.global and *.job + # files (YAML files holding global and job-configurations for + # testing purposes) then those files are used to drive additional + # tests. The files must be numbered (starting from 1) for this to work; + # 1.global and 1.job together make the configuration for test 1. + # + # If the module has a tests/CMakeLists.txt while it doesn't have its + # own CMakeLists.txt (e.g. a Python module), then the subdirectory + # for tests/ is added on its own. + # if ( BUILD_TESTING AND _mod_enabled AND _mod_testing ) add_test( NAME load-${SUBDIRECTORY} @@ -170,7 +180,7 @@ function( calamares_add_module_subdirectory ) ) # Try it with the tests/ configurations shipped with the module set( _count 1 ) - set( _testdir ${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/tests ) + set( _testdir ${_mod_dir}/tests ) while ( EXISTS "${_testdir}/${_count}.global" OR EXISTS "${_testdir}/${_count}.job" ) set( _dash_g "" ) set( _dash_j "" ) @@ -187,5 +197,8 @@ function( calamares_add_module_subdirectory ) ) math( EXPR _count "${_count} + 1" ) endwhile() + if ( EXISTS ${_testdir}/CMakeTests.txt AND NOT EXISTS ${_mod_dir}/CMakeLists.txt ) + include( ${_testdir}/CMakeTests.txt ) + endif() endif() endfunction() diff --git a/src/modules/grubcfg/tests/CMakeTests.txt b/src/modules/grubcfg/tests/CMakeTests.txt new file mode 100644 index 000000000..299fccf07 --- /dev/null +++ b/src/modules/grubcfg/tests/CMakeTests.txt @@ -0,0 +1,12 @@ +# Special cases for grubcfg configuration tests: +# - 2.global specifies /tmp/calamares as the rootMountPath, +# so we end up editing files there. Create the directory +# beforehand, so the test doesn't blow up. +set(_grub_root /tmp/calamares/etc/default) +set(_grub_file ${_grub_root}/bogus) + +add_test( + NAME make-grubcfg-dirs + COMMAND ${CMAKE_COMMAND} -E make_directory ${_grub_root} + ) +set_tests_properties(load-grubcfg-2 PROPERTIES DEPENDS make-grubcfg-dirs) diff --git a/src/modules/rawfs/tests/CMakeTests.txt b/src/modules/rawfs/tests/CMakeTests.txt new file mode 100644 index 000000000..44a7777c8 --- /dev/null +++ b/src/modules/rawfs/tests/CMakeTests.txt @@ -0,0 +1,8 @@ +# Special cases for rawfs tests +# +# - On FreeBSD, /proc/mounts doesn't exist (/proc is only about processes, +# and is rarely used). Expect the test to fail. + +if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set_tests_properties(load-rawfs-1 PROPERTIES WILL_FAIL TRUE) +endif()