0

I've playing around with cpp20, lately I've been trying to create some tests for my project, but every time I try to test anything related to strings I'd get a SIGSEGV signal.

This is an example of my tests

#include <catch2/catch_all.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <string>

using Catch::Matchers::ContainsSubstring;
using Catch::Matchers::EndsWith;

import mod;

TEST_CASE("true") {
  REQUIRE(1 == 1);
}

TEST_CASE("matcher") {
  REQUIRE_THAT("epa la arepa", EndsWith("arepa"));
}

This is the output I'm getting

[build] Build finished with exit code 0
[proc] Executing command: /usr/bin/ctest -j34 -C Debug -T test --output-on-failure
[ctest]    Site: Siel
[ctest]    Build name: Linux-g++-11
[ctest] Test project /home/siel/dev/learncpp20/profc++/build
[ctest]     Start 1: true
[ctest]     Start 2: matcher
[ctest] 1/2 Test #1: true .............................   Passed    0.00 sec
[ctest] 2/2 Test #2: matcher ..........................***Exception: SegFault  0.00 sec
[ctest] Filters: matcher
[ctest] Randomness seeded to: 367308665
[ctest] 
[ctest] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ctest] tests is a Catch2 v3.0.0-preview.5 host application.
[ctest] Run with -? for options
[ctest] 
[ctest] -------------------------------------------------------------------------------
[ctest] matcher
[ctest] -------------------------------------------------------------------------------
[ctest] /home/siel/dev/learncpp20/profc++/test/test_func.cpp:27
[ctest] ...............................................................................
[ctest] 
[ctest] /home/siel/dev/learncpp20/profc++/test/test_func.cpp:27: FAILED:
[ctest] due to a fatal error condition:
[ctest]   SIGSEGV - Segmentation violation signal
[ctest] 
[ctest] ===============================================================================
[ctest] test cases: 1 | 1 failed
[ctest] assertions: 1 | 1 failed
[ctest] 
[ctest] 
[ctest] 
[ctest] 50% tests passed, 1 tests failed out of 2
[ctest] 
[ctest] Total Test time (real) =   0.00 sec
[ctest] 
[ctest] The following tests FAILED:
[ctest]       2 - matcher (SEGFAULT)
[ctest] Errors while running CTest
[ctest] CTest finished with return code 8

This is a link to a public repo with this basic example: https://github.com/Siel/cpp_tests

Any ideas?

--EDIT

This is the output of 'cmake --build build --verbose'

❯ cmake --build build --verbose
/usr/bin/cmake -S/home/siel/dev/learncpp20/profc++ -B/home/siel/dev/learncpp20/profc++/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/siel/dev/learncpp20/profc++/build/CMakeFiles /home/siel/dev/learncpp20/profc++/build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
/usr/bin/make -f CMakeFiles/initial.dir/build.make CMakeFiles/initial.dir/depend
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
cd /home/siel/dev/learncpp20/profc++/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/siel/dev/learncpp20/profc++ /home/siel/dev/learncpp20/profc++ /home/siel/dev/learncpp20/profc++/build /home/siel/dev/learncpp20/profc++/build /home/siel/dev/learncpp20/profc++/build/CMakeFiles/initial.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
/usr/bin/make -f CMakeFiles/initial.dir/build.make CMakeFiles/initial.dir/build
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
make[2]: Nothing to be done for 'CMakeFiles/initial.dir/build'.
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
[  3%] Built target initial
/usr/bin/make -f lib/Catch2/src/CMakeFiles/Catch2.dir/build.make lib/Catch2/src/CMakeFiles/Catch2.dir/depend
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
cd /home/siel/dev/learncpp20/profc++/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/siel/dev/learncpp20/profc++ /home/siel/dev/learncpp20/profc++/lib/Catch2/src /home/siel/dev/learncpp20/profc++/build /home/siel/dev/learncpp20/profc++/build/lib/Catch2/src /home/siel/dev/learncpp20/profc++/build/lib/Catch2/src/CMakeFiles/Catch2.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
/usr/bin/make -f lib/Catch2/src/CMakeFiles/Catch2.dir/build.make lib/Catch2/src/CMakeFiles/Catch2.dir/build
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
make[2]: Nothing to be done for 'lib/Catch2/src/CMakeFiles/Catch2.dir/build'.
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
[ 93%] Built target Catch2
/usr/bin/make -f lib/Catch2/src/CMakeFiles/Catch2WithMain.dir/build.make lib/Catch2/src/CMakeFiles/Catch2WithMain.dir/depend
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
cd /home/siel/dev/learncpp20/profc++/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/siel/dev/learncpp20/profc++ /home/siel/dev/learncpp20/profc++/lib/Catch2/src /home/siel/dev/learncpp20/profc++/build /home/siel/dev/learncpp20/profc++/build/lib/Catch2/src /home/siel/dev/learncpp20/profc++/build/lib/Catch2/src/CMakeFiles/Catch2WithMain.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
/usr/bin/make -f lib/Catch2/src/CMakeFiles/Catch2WithMain.dir/build.make lib/Catch2/src/CMakeFiles/Catch2WithMain.dir/build
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
make[2]: Nothing to be done for 'lib/Catch2/src/CMakeFiles/Catch2WithMain.dir/build'.
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
[ 96%] Built target Catch2WithMain
/usr/bin/make -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/depend
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
cd /home/siel/dev/learncpp20/profc++/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/siel/dev/learncpp20/profc++ /home/siel/dev/learncpp20/profc++ /home/siel/dev/learncpp20/profc++/build /home/siel/dev/learncpp20/profc++/build /home/siel/dev/learncpp20/profc++/build/CMakeFiles/tests.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
/usr/bin/make -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/build
make[2]: Entering directory '/home/siel/dev/learncpp20/profc++/build'
make[2]: Nothing to be done for 'CMakeFiles/tests.dir/build'.
make[2]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
[100%] Built target tests
make[1]: Leaving directory '/home/siel/dev/learncpp20/profc++/build'
/usr/bin/cmake -E cmake_progress_start /home/siel/dev/learncpp20/profc++/build/CMakeFiles 0

This is the full log after a cmake clean: https://gist.github.com/Siel/afadbcfdeae3f74c7cb1f70b457b89d8

Siel347
  • 1
  • 2
  • Don't check the `build` directory into source control... – Alex Reinking May 26 '22 at 16:50
  • Will remove it, just pushed everything without actually thinking about it. – Siel347 May 26 '22 at 16:54
  • Also C++20 modules are still not supported by CMake, and _certainly_ not by CMake 3.0.0, which your CMakeLists.txt claims to support. – Alex Reinking May 26 '22 at 16:55
  • The modules are working. – Siel347 May 26 '22 at 16:57
  • 1
    They only _happen_ to in such a simple example. See the open issues here: https://gitlab.kitware.com/cmake/cmake/-/issues/18355 – Alex Reinking May 26 '22 at 16:59
  • Thank you for your comment, I'm pushing myself also to learn cmake and wasn't aware of that. might that be related to the Seg-fault I'm getting with some tests? – Siel347 May 26 '22 at 17:03
  • I'm still investigating, but probably not. I thought you should know that, though, since you'll otherwise waste a lot of time trying to make something work that just... won't. At least not for a few more CMake versions. – Alex Reinking May 26 '22 at 17:07
  • My only experience with Cmake has been on already working projects, this is the first time I've tried to setup a project by myself. That just make clearer to me that there are a lot of things I still need to learn. hehe – Siel347 May 26 '22 at 17:10
  • Yeah, when I try to build locally, I get errors like `main.cpp:1:8: fatal error: module 'mod' not found`. Can you run `cmake --build build --verbose` and post the output? I'd like to see the exact compiler command lines you're getting. – Alex Reinking May 26 '22 at 18:03
  • I just updated the original post, thanks! – Siel347 May 26 '22 at 18:28
  • Sorry, your output doesn't contain any actual compiler commands. See all the `Nothing to be done for ...` messages? Try building from scratch or passing `--clean-first` to `cmake --build`. – Alex Reinking May 26 '22 at 18:30
  • The gist contains the full output https://gist.github.com/Siel/afadbcfdeae3f74c7cb1f70b457b89d8 – Siel347 May 26 '22 at 18:34
  • What is profc++? Have you tried using a standard compiler (gcc/clang etc.). Also have you tried to run your tests from gdb? – arved Jun 17 '22 at 13:07

0 Answers0