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

json_unit runs forever when executed in build directory #319

Closed
tboede opened this issue Sep 26, 2016 · 8 comments
Closed

json_unit runs forever when executed in build directory #319

tboede opened this issue Sep 26, 2016 · 8 comments
Milestone

Comments

@tboede
Copy link

tboede commented Sep 26, 2016

It seems to me like a bug that json_unit runs forever when I build the project in a separate build directory with

cmake ../json
make

and then try to execute

./test/json_unit

in the build directory.
I would expected it to run the tests and print a result when done which it indeed does if it was build and executed in the source directory.

When I sent an interrupt signal to the running program it terminates with following output:

json_unit is a Catch v1.5.6 host application.
Run with -? for options

-------------------------------------------------------------------------------
constructors
  create a JSON value from an input stream
  std::ifstream
-------------------------------------------------------------------------------
/home/tim/Projekte/github/json/test/src/unit-constructor1.cpp:42
...............................................................................

/home/tim/Projekte/github/json/test/src/unit-constructor1.cpp:1305: FAILED:
due to a fatal error condition:
  SIGINT - Terminal interrupt signal

===============================================================================
test cases:   11 |   10 passed | 1 failed
assertions: 3938 | 3937 passed | 1 failed

A look at line 1305 in unit-constructor1.cpp

        SECTION("std::ifstream")
        {
            std::ifstream f("test/data/json_tests/pass1.json");
            json j(f);
        }

shows that the input stream test wants to load a file from a subdirectory which doesn't exists in the build directory.

To fix this I added following to 'test/CMakeLists.txt' in the source directory :

string(COMPARE NOTEQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" JSON_HAS_SEPARATE_BUILDDIR)

if(${JSON_HAS_SEPARATE_BUILDDIR})

file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/data" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")

endif()

Now test/data will be copied from the source directory to the build directory when they are not the same.

After rebuilding json_unit finally prints:

===============================================================================
All tests passed (8644 assertions in 33 test cases)
@tboede tboede changed the title json_unit hangs when executed in build directory json_unit runs forever when executed in build directory Sep 26, 2016
@tboede tboede mentioned this issue Sep 28, 2016
@nlohmann
Copy link
Owner

nlohmann commented Oct 6, 2016

I can confirm your observation, but the tests can be executed successfully with ctest:

mkdir build
cd build
cmake ..
make
ctest

which executes with

Test project /Users/niels/Documents/Repositories/json/build
    Start 1: json_unit_default
1/2 Test #1: json_unit_default ................   Passed    8.10 sec
    Start 2: json_unit_all
2/2 Test #2: json_unit_all ....................   Passed  136.44 sec

100% tests passed, 0 tests failed out of 2

Total Test time (real) = 144.54 sec

I don't think PR #320 is necessary. What do you think @tboede?

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Oct 6, 2016
@tboede
Copy link
Author

tboede commented Oct 6, 2016

@nlohmann yes with ctest it works because it reads the files from the source directory.
Well, then it's my fault i thought the tests should be run by execute them manually.

@nlohmann
Copy link
Owner

nlohmann commented Oct 6, 2016

Currently, Cmake is not mentioned in the README file, but is only called by AppVeyor. Do you think extending the REAMDE makes sense to describe the proper Cmake way?

@tboede
Copy link
Author

tboede commented Oct 6, 2016

Maybe "make check" in the Test section should be replaced with "ctest", it seems that there is no "check" rule in the Makefile anymore.

@nlohmann
Copy link
Owner

nlohmann commented Oct 6, 2016

There is a make check. I shall add a section to the README to also mention cmake/ctest.

nlohmann added a commit that referenced this issue Oct 6, 2016
@tboede
Copy link
Author

tboede commented Oct 6, 2016

Yeah, i see the rule is in the prebuilt Makefile in the source directory which was of course not available when I tried to run make check in the separate build directory.

@tboede
Copy link
Author

tboede commented Oct 6, 2016

I think this issue can be closed now.

@tboede tboede closed this as completed Oct 6, 2016
@nlohmann nlohmann added improvement and removed state: please discuss please discuss the issue or vote for your favorite option labels Oct 6, 2016
@nlohmann
Copy link
Owner

nlohmann commented Oct 6, 2016

Thanks for reporting!

@nlohmann nlohmann added this to the Release 2.0.6 milestone Oct 6, 2016
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