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

Define CMake/CTest tests #247

Merged
merged 1 commit into from
May 18, 2016
Merged

Conversation

robertmrk
Copy link
Contributor

In #241 @ChrisKitching described that tests on out of source builds fail because the test executable can't find the JSON files it needs. It's great that he noticed this and provided a fix for it, I totally missed this issue when I rewrote the CMake lists file.
In #242 the issue is fixed by installing the test executable and test files. There are two problems with this approach:

  1. The test executable is used only once by the users of the library. It's executed only after a successful build and never used again, so there is no need to install it on the system level.
  2. For executing the tests in out of source builds we don't need to copy any files at all. In CMake we can define tests with the source directory as their working directory, so tests will be able to find the JSON files no matter where the project is built.

In this PR I defined two CMake/CTest test configurations.

  • json_unit_default for running the default tests by executing
    json_unit without any arguments
  • json_unit_all for running all the tests by executing json_unit
    with the "*" argument

So the tests can be now executed by building the test target:

make test

or by running ctest in the build directory.

The tests can be selectively executed as well with ctest:

ctest -R json_unit_default

or

ctest -R json_unit_all

Instead of copying the test executable and the JSON files used by
the tests at install time, define CMake/CTest tests for running
the json_unit executable from any build directory with the project's
source directory as its working directory.

- call enable_testing in the main lists file to allow the definition
of tests
- remove install commands from the test directory's lists file
- define two tests
  - json_unit_default for running the default tests by executing
json_unit without any arguments
  - json_unit_all for running all the tests by executing json_unit
with the "*" argument
- update the AppVeyor configuration file to use the new testing method
@coveralls
Copy link

coveralls commented May 18, 2016

Coverage Status

Coverage remained the same at 99.954% when pulling 639d632 on robertmrk:feature/cmake-cleanup into 0a393b8 on nlohmann:develop.

@nlohmann nlohmann merged commit 25d60b7 into nlohmann:develop May 18, 2016
@nlohmann
Copy link
Owner

Thanks a lot! I am lacking Cmake experience, so I am happy about any contributions.

@nlohmann nlohmann added this to the Release 2.0.0 milestone May 18, 2016
@robertmrk
Copy link
Contributor Author

You're welcome. I'm glad I could help.

@robertmrk robertmrk deleted the feature/cmake-cleanup branch May 19, 2016 07:47
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

3 participants