open-source-parsers / jsoncpp

A C++ library for interacting with JSON.
Other
8.06k stars 2.63k forks source link

Tests write to source tree when invoked via CMake #1515

Open iskunk opened 11 months ago

iskunk commented 11 months ago

Describe the bug When the test suite is invoked via CMake in a regular out-of-source build configuration, and the source tree is read-only, the tests fail with

$ ctest --rerun-failed --output-on-failure
Test project /tmp/build/linux_jsoncpp_1.9.5/build
    Start 1: jsoncpp_readerwriter
1/2 Test #1: jsoncpp_readerwriter ................***Failed    0.09 sec
/tmp/build/linux_jsoncpp_1.9.5/build/bin/jsontestrunner_exe  --json-writer StyledWriter "/tmp/src/jsoncpp/1.9.5/test/data/legacy_test_string_unicode_04.json"
Failed to create 'input' actual file.
TESTING: /tmp/src/jsoncpp/1.9.5/test/data/legacy_test_string_unicode_04.json Traceback (most recent call last):
  File "/tmp/src/jsoncpp/1.9.5/src/jsontestrunner/../../test/runjsontests.py", line 189, in <module>
    main()
  File "/tmp/src/jsoncpp/1.9.5/src/jsontestrunner/../../test/runjsontests.py", line 174, in main
    runAllTests(jsontest_executable_path, input_path,
  File "/tmp/src/jsoncpp/1.9.5/src/jsontestrunner/../../test/runjsontests.py", line 125, in runAllTests
    open(base_path + '.process-output', 'wt', encoding = 'utf-8').write(process_output)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 30] Read-only file system: '/tmp/src/jsoncpp/1.9.5/test/data/legacy_test_string_unicode_04.process-output'

    Start 2: jsoncpp_readerwriter_json_checker
2/2 Test #2: jsoncpp_readerwriter_json_checker ...***Failed    0.09 sec
/tmp/build/linux_jsoncpp_1.9.5/build/bin/jsontestrunner_exe  --json-writer StyledWriter "/tmp/src/jsoncpp/1.9.5/test/data/legacy_test_string_unicode_04.json"
Failed to create 'input' actual file.
TESTING: /tmp/src/jsoncpp/1.9.5/test/data/legacy_test_string_unicode_04.json Traceback (most recent call last):
  File "/tmp/src/jsoncpp/1.9.5/src/jsontestrunner/../../test/runjsontests.py", line 189, in <module>
    main()
  File "/tmp/src/jsoncpp/1.9.5/src/jsontestrunner/../../test/runjsontests.py", line 174, in main
    runAllTests(jsontest_executable_path, input_path,
  File "/tmp/src/jsoncpp/1.9.5/src/jsontestrunner/../../test/runjsontests.py", line 125, in runAllTests
    open(base_path + '.process-output', 'wt', encoding = 'utf-8').write(process_output)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 30] Read-only file system: '/tmp/src/jsoncpp/1.9.5/test/data/legacy_test_string_unicode_04.process-output'

0% tests passed, 2 tests failed out of 2

Total Test time (real) =   0.18 sec

The following tests FAILED:
      1 - jsoncpp_readerwriter (Failed)
      2 - jsoncpp_readerwriter_json_checker (Failed)
Errors while running CTest

To Reproduce Mount the source tree read-only, configure and build via CMake, and then attempt to run the test suite (e.g. make test).

Expected behavior The test suite should read from the source tree, write to the build tree, and pass successfully.

(The tests already pass if they are allowed to write to the source tree.)

Desktop (please complete the following information):

Additional context It is critical that the normal build and test process not require writing to the source tree. Not only is mounting the source tree read-only a standard approach in production workflows, reproducible builds often rely on file timestamps in the source tree to set SOURCE_DATE_EPOCH to an appropriate value.