aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/PaludisAddTest.cmake
blob: 104b2a9b342f4f4bcf65f520de6930596c74a97a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
include(CMakeParseArguments)

function(paludis_add_test test_name)
  set(options BASH GTEST PYTHON RUBY)
  set(single_value_args EBUILD_MODULE_SUFFIXES TEST_RUNNER)
  set(multiple_value_args LINK_LIBRARIES)

  cmake_parse_arguments(PAT "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})

  string(REGEX MATCH "_TEST" has_TEST ${test_name})
  if(NOT has_TEST)
    set(test_name ${test_name}_TEST)
  endif()

  if(PAT_GTEST AND NOT ENABLE_GTEST)
    return()
  endif()

  if(NOT PAT_BASH AND NOT PAT_PYTHON AND NOT PAT_RUBY)
    add_executable(${test_name}
                     "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.cc")
  endif()
  if(PAT_GTEST)
    target_include_directories(${test_name}
                               PRIVATE
                                 ${GTEST_INCLUDE_DIRS})
    target_link_libraries(${test_name}
                          PRIVATE
                            libpaludis
                            libpaludisutil
                            ${GTEST_BOTH_LIBRARIES}
                            ${CMAKE_THREAD_LIBS_INIT}
                            ${PAT_LINK_LIBRARIES})
  endif()

  set(pat_test_runner "${PROJECT_SOURCE_DIR}/paludis/util/run_test.sh")
  if(PAT_TEST_RUNNER)
    set(pat_test_runner "${PAT_TEST_RUNNER}")
  endif()

  set(pat_environment_variables)
  if(NOT "${PAT_EBUILD_MODULE_SUFFIXES}" STREQUAL "")
    set(pat_environment_variables PALUDIS_EBUILD_MODULE_SUFFIXES=${PAT_EBUILD_MODULE_SUFFIXES})
  endif()

  string(REGEX REPLACE "_TEST" "" pat_display_name ${test_name})

  set(pat_test_extension "")
  if(PAT_PYTHON)
    set(pat_test_extension ".py")
  elseif(PAT_RUBY)
    set(pat_test_extension ".rb")
  endif()

  if(PAT_BASH OR PAT_PYTHON OR PAT_RUBY)
    set(pat_test_binary_parent_directory "${CMAKE_CURRENT_SOURCE_DIR}")
  else()
    set(pat_test_binary_parent_directory "${CMAKE_CURRENT_BINARY_DIR}")
  endif()

  set(pat_test_binary
      "${pat_test_binary_parent_directory}/${test_name}${pat_test_extension}")

  math(EXPR version_major "${PROJECT_VERSION_MAJOR} * 100 + ${PROJECT_VERSION_MINOR}")

  # NOTE(compnerd) the trailing slash on the TEST_SCRIPT_DIR is important as
  # the harness will not add that for us
  add_test(NAME
             ${pat_display_name}
           COMMAND
             env -i HOME=${CMAKE_CURRENT_BINARY_DIR}
                    LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/paludis
                    PALUDIS_BYPASS_USERPRIV_CHECKS=YES
                    PALUDIS_DEFAULT_OUTPUT_CONF=${PROJECT_SOURCE_DIR}/paludis/environments/paludis/tests_output.conf
                    PALUDIS_DISTRIBUTION=gentoo
                    PALUDIS_DISTRIBUTIONS_DIR=${PROJECT_SOURCE_DIR}/paludis/distributions
                    PALUDIS_EAPIS_DIR=${PROJECT_SOURCE_DIR}/paludis/repositories/e/eapis
                    PALUDIS_EBUILD_DIR=${PROJECT_SOURCE_DIR}/paludis/repositories/e/ebuild
                    PALUDIS_EBUILD_DIR_FALLBACK=${CMAKE_BINARY_DIR}/paludis/repositories/e/ebuild
                    PALUDIS_ECHO_FUNCTIONS_DIR=${CMAKE_BINARY_DIR}/paludis/util
                    PALUDIS_EXTRA_EBUILD_MODULES_DIRS=${CMAKE_BINARY_DIR}/paludis/util
                    PALUDIS_FETCHERS_DIR=${PROJECT_SOURCE_DIR}/paludis/fetchers
                    PALUDIS_HOOKER_DIR=${PROJECT_SOURCE_DIR}/paludis
                    PALUDIS_NO_CHOWN=YES
                    PALUDIS_NO_GLOBAL_HOOKS=YES
                    PALUDIS_NO_GLOBAL_SETS=YES
                    PALUDIS_NO_XTERM_TITLES=YES
                    PALUDIS_PC_SLOT=${PALUDIS_PKG_CONFIG_SLOT}
                    PALUDIS_PYTHON_DIR=${PROJECT_SOURCE_DIR}/python
                    PALUDIS_SUFFIXES_FILE=${PROJECT_SOURCE_DIR}/paludis/repositories/e/ebuild_entries_suffixes.conf
                    PALUDIS_TMPDIR=${CMAKE_CURRENT_BINARY_DIR}
                    PYTHON=${PYTHON_EXECUTABLE}
                    PYTHONPATH=${CMAKE_BINARY_DIR}/python
                    RUBY=${RUBY_EXECUTABLE}
                    RUBYLIB=${CMAKE_BINARY_DIR}/ruby
                    SO_SUFFIX=${version_major}
                    SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}
                    TEST_SCRIPT_DIR=${CMAKE_CURRENT_SOURCE_DIR}/
                    TOP_BUILDDIR=${CMAKE_BINARY_DIR}
                    ${pat_environment_variables}
             "${BASH_EXECUTABLE}" ${pat_test_runner} "${pat_test_binary}")
endfunction()