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

Fix WORKING_DIRECTORY for unit tests #523

Merged
merged 1 commit into from
Jun 15, 2024

Conversation

Bktero
Copy link

@Bktero Bktero commented Jun 12, 2024

Hello

I ran into a path-related issue with ctest in a project that fetches jsoncons.

The issue can be reproduced with the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)

project(test_jsoncons)

include(FetchContent)

FetchContent_Declare(jsoncons
        GIT_REPOSITORY https://github.com/danielaparker/jsoncons.git
        GIT_TAG v0.176.0
)

FetchContent_MakeAvailable(jsoncons)

enable_testing()

Then we can run the following commands:

% cmake -S . -B build -G Ninja
% cd build
% ninja 
% ctest  
Test project /home/pierre/temp/test_jsoncons/build
    Start 1: unit_tests
Failed to change working directory to /home/pierre/temp/test_jsoncons/test : No such file or directory
1/1 Test #1: unit_tests .......................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.00 sec

The following tests FAILED:
          1 - unit_tests (Not Run)
Errors while running CTest
Output from these tests are in: /home/pierre/temp/test_jsoncons/build/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.

Just in case, my compiler is:

% gcc --version
gcc (Debian 12.2.0-14) 12.2.0

This PR fixes this issue.

ctest still runs properly when the commands above are executed from the root of the jsoncons repository.

Note that these commands don't work when they are executed from the test directory. The first lines seems to foresee this possibilities. However, catch2 is not found when ninja runs: fatal error: catch/catch.hpp: No such file or directory. I have not attempted to address this issue, as it was present before my commit for this PR.

Best regards
Bktero

When jsoncons was fetched from another project, ctest failed because the path wasn't found
@danielaparker danielaparker merged commit 6f4839d into danielaparker:dev Jun 15, 2024
62 checks passed
@Bktero Bktero deleted the fix_unit_tests_workdir branch June 21, 2024 07:12
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

Successfully merging this pull request may close these issues.

None yet

2 participants