Skip to content
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

Running Tests with Local install of nihtest #5

Closed
bkmgit opened this issue Jul 3, 2023 · 2 comments
Closed

Running Tests with Local install of nihtest #5

bkmgit opened this issue Jul 3, 2023 · 2 comments

Comments

@bkmgit
Copy link
Contributor

bkmgit commented Jul 3, 2023

Am trying to install nihtest in a local folder without using a virtual environment to replicate a packaging build.
Is there some way to modify the configuration to enable the tests to run?

Modified CMakeLists.txt

cmake_minimum_required(VERSION 3.12)

# Also update version in nihtest/__main__.py and pyproject.toml
project(nihtest
        VERSION 1.1.1
        DESCRIPTION "NiH testing framework"
        HOMEPAGE_URL "https://github.com/nih-at/nihtest"
        LANGUAGES C)

enable_testing()

find_package(Python3 REQUIRED COMPONENTS Interpreter)


set(NIHTEST /home/user458/python-nihtest/nihtest-1.1.1/cbuild/test_dir/bin/nihtest)

file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/nihtest/*.py)

add_custom_command(
        OUTPUT ${NIHTEST}
        COMMAND python -m pip install -q --disable-pip-version-check ${CMAKE_SOURCE_DIR} -t test_dir
        DEPENDS ${SOURCES}
)

add_custom_target(mynihtest ALL DEPENDS ${NIHTEST})

# TODO: target for wheel
add_subdirectory(tests)

Modified tests/CMakeLists.txt

cmake_minimum_required(VERSION 3.12)

project(nihtest
        VERSION 0.1.0
        DESCRIPTION "NiH testing framework"
        HOMEPAGE_URL "https://github.com/nih-at/nihtest"
        LANGUAGES C)

set(TEST_PROGRAMS
  can-preload
  comparator
  false
  true
  echo
  cat
  getenv
  file
)

foreach(PROGRAM ${TEST_PROGRAMS})
  add_executable(nihtest-${PROGRAM} ${PROGRAM}.c)
endforeach()

ADD_LIBRARY(ineffective-remove MODULE ineffective-remove.c)
TARGET_LINK_LIBRARIES(ineffective-remove ${CMAKE_DL_LIBS})

# Tests for helper programs
add_test(NAME true COMMAND nihtest-true)
add_test(NAME false COMMAND nihtest-false)
set_tests_properties(false PROPERTIES WILL_FAIL TRUE)
add_test(NAME echo COMMAND nihtest-echo "This test was successful.")
set_tests_properties(echo PROPERTIES PASS_REGULAR_EXPRESSION "This test was successful.")
add_test(NAME cat COMMAND nihtest-cat ${CMAKE_CURRENT_SOURCE_DIR}/success.txt)
set_tests_properties(cat PROPERTIES PASS_REGULAR_EXPRESSION "This is a successful test.")
add_test(NAME getenv-defined COMMAND nihtest-getenv "DEFINED")
set_tests_properties(getenv-defined PROPERTIES ENVIRONMENT DEFINED="This is a successful test.")
set_tests_properties(getenv-defined PROPERTIES PASS_REGULAR_EXPRESSION "DEFINED=\"This is a successful test.\"")
add_test(NAME getenv-undefined COMMAND nihtest-getenv "UNDEFINED")
set_tests_properties(getenv-undefined PROPERTIES PASS_REGULAR_EXPRESSION "UNDEFINED=<null>")

file(GLOB TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.test)
foreach(FULL_CASE IN LISTS TESTS)
  get_filename_component(CASE ${FULL_CASE} NAME)
  add_test(NAME ${CASE} COMMAND python ${NIHTEST} --verbose ${CMAKE_CURRENT_SOURCE_DIR}/${CASE}
           WORKING_DIRECTORY /home/user458/python-nihtest/nihtest-1.1.1/cbuild/test_dir )
  set_tests_properties(${CASE} PROPERTIES SKIP_RETURN_CODE 77)
  set_tests_properties(${CASE} PROPERTIES ENVIRONMENT PATH=/home/user458/python-nihtest/nihtest-1.1.1/cbuild/test_dir/bin:$ENV{PATH})
  set_tests_properties(${CASE} PROPERTIES ENVIRONMENT PYTHONPATH=/home/user458/python-nihtest/nihtest-1.1.1/cbuild/test_dir:$ENV{PYTHONPATH})
endforeach()

# for testing the "features" keyword
set(HAVE_TEST_EXISTING_FEATURE 1)
set(HAVE_TEST_MISSING_FEATURE 0)

configure_file(nihtest.conf.in ${CMAKE_CURRENT_BINARY_DIR}/nihtest.conf @ONLY) # for *.tests
configure_file(nihtest-conf.in ${CMAKE_CURRENT_BINARY_DIR}/nihtest-conf @ONLY) # for *.input

enable_testing()

# TODO: testing depends on venv

After copying nihtest.conf and nihtest-conf to /home/user458/python-nihtest/nihtest-1.1.1/cbuild/test_dir the tests fail with messages such as:

Start 45: stdin-file-pass.test
45/50 Test #45: stdin-file-pass.test ................***Failed    0.21 sec
/home/user458/python-nihtest/nihtest-1.1.1/cbuild/test_dir/bin/nihtest: can't find program nihtest

Any suggestions on how this might be overcome?

@bkmgit
Copy link
Contributor Author

bkmgit commented Jul 9, 2023

Got this to run, though needed to call nihtest through a bash script, could not do it through CMake directly, though maybe there is a better way to do this. Updated CMakeLists.txt

cmake_minimum_required(VERSION 3.12)

# Also update version in nihtest/__main__.py and pyproject.toml
project(nihtest
        VERSION 1.1.0
        DESCRIPTION "NiH testing framework"
        HOMEPAGE_URL "https://github.com/nih-at/nihtest"
        LANGUAGES C)

enable_testing()

find_package(Python3 REQUIRED COMPONENTS Interpreter)

#set(VENV ${CMAKE_BINARY_DIR}/venv)
if (WIN32)
    #set(VENV_BIN_DIR ${VENV}/Scripts)
    #set(VENV_PYTHON ${VENV_BIN_DIR}/python.exe)
else ()  # assume Linux
    #set(VENV_BIN_DIR ${VENV}/bin)
    #set(VENV_PYTHON ${VENV_BIN_DIR}/python)
endif ()

#set(NIHTEST ${VENV_BIN_DIR}/nihtest)

file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/nihtest/*.py)

#add_custom_command(
        #OUTPUT ${NIHTEST}
        #COMMAND ${Python3_EXECUTABLE} -m venv ${VENV}
        #COMMAND ${VENV_BIN_DIR}/pip install -q --disable-pip-version-check ${CMAKE_SOURCE_DIR}
        #DEPENDS ${SOURCES}
#)

#add_custom_target(venv ALL #DEPENDS ${NIHTEST})

# TODO: target for wheel

add_subdirectory(tests)

Updated tests/CMakeLists.txt

cmake_minimum_required(VERSION 3.12)

project(nihtest
        VERSION 0.1.0
        DESCRIPTION "NiH testing framework"
        HOMEPAGE_URL "https://github.com/nih-at/nihtest"
        LANGUAGES C)

set(TEST_PROGRAMS
  can-preload
  comparator
  false
  true
  echo
  cat
  getenv
  file
)

foreach(PROGRAM ${TEST_PROGRAMS})
  add_executable(nihtest-${PROGRAM} ${PROGRAM}.c)
endforeach()

ADD_LIBRARY(ineffective-remove MODULE ineffective-remove.c)
TARGET_LINK_LIBRARIES(ineffective-remove ${CMAKE_DL_LIBS})

# Tests for helper programs
add_test(NAME true COMMAND nihtest-true)
add_test(NAME false COMMAND nihtest-false)
set_tests_properties(false PROPERTIES WILL_FAIL TRUE)
add_test(NAME echo COMMAND nihtest-echo "This test was successful.")
set_tests_properties(echo PROPERTIES PASS_REGULAR_EXPRESSION "This test was successful.")
add_test(NAME cat COMMAND nihtest-cat ${CMAKE_CURRENT_SOURCE_DIR}/success.txt)
set_tests_properties(cat PROPERTIES PASS_REGULAR_EXPRESSION "This is a successful test.")
add_test(NAME getenv-defined COMMAND nihtest-getenv "DEFINED")
set_tests_properties(getenv-defined PROPERTIES ENVIRONMENT DEFINED="This is a successful test.")
set_tests_properties(getenv-defined PROPERTIES PASS_REGULAR_EXPRESSION "DEFINED=\"This is a successful test.\"")
add_test(NAME getenv-undefined COMMAND nihtest-getenv "UNDEFINED")
set_tests_properties(getenv-undefined PROPERTIES PASS_REGULAR_EXPRESSION "UNDEFINED=<null>")

file(GLOB TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.test)
foreach(FULL_CASE IN LISTS TESTS)
  get_filename_component(CASE ${FULL_CASE} NAME)
  add_test(NAME ${CASE} COMMAND bash /builddir/build/BUILD/nihtest-1.1.0/check.sh ${CASE})
  set_tests_properties(${CASE} PROPERTIES SKIP_RETURN_CODE 77)
  #  set_tests_properties(${CASE} PROPERTIES ENVIRONMENT "PYTHONPATH=/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/lib64/python3.12/site-packages:/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/lib/python3.12/site-packages:$ENV{PYTHONPATH}")
endforeach()

# for testing the "features" keyword
set(HAVE_TEST_EXISTING_FEATURE 1)
set(HAVE_TEST_MISSING_FEATURE 0)

configure_file(nihtest.conf.in ${CMAKE_CURRENT_BINARY_DIR}/nihtest.conf @ONLY) # for *.tests
configure_file(nihtest-conf.in ${CMAKE_CURRENT_BINARY_DIR}/nihtest-conf @ONLY) # for *.input

enable_testing()

# TODO: testing depends on venv

Updated tests/nihtest.conf.in

[settings]
features-files = @PROJECT_BINARY_DIR@/config.h
test-input-directories = @CMAKE_CURRENT_SOURCE_DIR@
program-directories = @PROJECT_BINARY_DIR@
    @VENV_BIN_DIR@

[environment]
PYTHONPATH=/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/lib64/python3.12/site-packages:/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/lib/python3.12/site-packages

check.sh

PATH=/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/bin:/builddir/.local/bin:/builddir/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin PYTHONPATH=/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/lib64/python3.12/site-packages:/builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/lib/python3.12/site-packages: /usr/bin/python3 /builddir/build/BUILDROOT/python-nihtest-1.1.0-1.fc39.x86_64/usr/bin/nihtest -v $1 

@dillof
Copy link
Member

dillof commented Jul 19, 2023

Glad you could solve your problem.

@dillof dillof closed this as completed Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants