<criterion/criterion.h>

0

Witam
Brykam się z uruchomieniem testów.
Postępowałem zgodnie z:
https://criterion.readthedocs.io/en/master/setup.html
Nie było żadnych błęgów.
Przekleiłem prosty test:

#include <string.h>
#include <criterion/criterion.h>

Test(sample, test) {
    cr_expect(strlen("Test") == 4, "Expected \"Test\" to have a length of 4.");
    cr_expect(strlen("Hello") == 4, "This will always fail, why did I add this?");
    cr_assert(strlen("") == 0);
}

I otrzymuję błędy:

make all
Building file: ../src/Test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Test.d" -MT"src/Test.o" -o "src/Test.o" "../src/Test.cpp"
Finished building: ../src/Test.cpp

Building target: MyC++
Invoking: GCC C++ Linker
g++ -o "MyC++" ./src/MyC++.o ./src/Test.o
/usr/bin/ld: ./src/Test.o: in function sample_test_jmp()': /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:4: undefined reference to criterion_internal_test_setup'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_internal_test_main' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:4: undefined reference to criterion_internal_test_teardown'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_test_die' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:4: undefined reference to criterion_test_die'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_test_die' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:4: undefined reference to criterion_test_die'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_test_die' /usr/bin/ld: ./src/Test.o:/home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:4: more undefined references to criterion_test_die' follow
/usr/bin/ld: ./src/Test.o: in function sample_test_impl': /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:5: undefined reference to criterion_options'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_translate_assert_msg' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:5: undefined reference to cr_asprintf'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:5: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_send_assert' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:5: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_continue_test' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:5: undefined reference to cri_asserts_passed_incr'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_options' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:6: undefined reference to cr_translate_assert_msg'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_asprintf' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:6: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:6: undefined reference to criterion_send_assert'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:6: undefined reference to criterion_continue_test'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cri_asserts_passed_incr' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:7: undefined reference to criterion_options'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_translate_assert_msg' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:7: undefined reference to cr_asprintf'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:7: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_send_assert' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:7: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp undefined reference to criterion_abort_test' /usr/bin/ld: /home/bq666/Workspace/eclipse/MyC++/Debug/../src/Test.cpp:7: undefined reference to cri_asserts_passed_incr'
/usr/bin/ld: ./src/Test.o:(.rodata+0x10): undefined reference to cr_malloc' /usr/bin/ld: ./src/Test.o:(.rodata+0x18): undefined reference to cr_free'
/usr/bin/ld: ./src/Test.o:(.rodata+0x20): undefined reference to cr_calloc' /usr/bin/ld: ./src/Test.o:(.rodata+0x28): undefined reference to cr_realloc'
/usr/bin/ld: ./src/Test.o:(.rodata+0x30): undefined reference to cr_log' /usr/bin/ld: ./src/Test.o: in function criterion::sync()':
/usr/local/include/criterion/logging.h undefined reference to `cr_log'
collect2: error: ld returned 1 exit status
make: *** [makefile MyC++] Error 1
"make all" terminated with exit code 2. Build might be incomplete.

Pracuję na Eclipsie
Będę wdzięczny za nakierowanie gdzie szukać przyczyny błędów.
Pozdrawiam

2

Może trzeba zlinkować bibliotekę przy kompilacji?

1

To compile your tests with Criterion, you need to make sure to:

Add the include directory to the header search path
Install the library to your library search path
**Link Criterion to your executable.**

Tego ostatniego u Ciebie nie widzę. Jaki masz typ projektu w Eclipse ?

0
Bartłomiej Golenko napisał(a):

To compile your tests with Criterion, you need to make sure to:

Add the include directory to the header search path
Install the library to your library search path
**Link Criterion to your executable.**

Tego ostatniego u Ciebie nie widzę. Jaki masz typ projektu w Eclipse ?

Nie wiem czy tak mogę ale myślę że załączony obrazek wiecej powie. Eclipsa się dopiero uczę, tym bardziej C++ także wybaczcie jeśli możecie moją ułomność :)

screenshot-20190718200018.png

Ciekawe jest to dla mnie jeszcze to:
screenshot-20190718201541.png

Zastanawia mnie to czy w katalogu Criterion powinny być same headery ?
screenshot-20190718202103.png

I jeszcze przebieg instalacji Criterion jako załącznik.

0

W CLion to samo:
====================[ Build | C_C__ | Debug ]===================================
/opt/clion-2019.1.4/bin/cmake/linux/bin/cmake --build /home/bq666/Workspace/C_C++/cmake-build-debug --target C_C__ -- -j 8
Scanning dependencies of target C_C__
[ 33%] Building CXX object CMakeFiles/C_C__.dir/test.cpp.o
[ 66%] Linking CXX executable C_C__
/usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o: in function sample_test_jmp()': /home/bq666/Workspace/C_C++/test.cpp:4: undefined reference to criterion_internal_test_setup'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_internal_test_main' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:4: undefined reference to criterion_internal_test_teardown'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_test_die' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:4: undefined reference to criterion_test_die'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_test_die' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:4: undefined reference to criterion_test_die'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_test_die' /usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o:/home/bq666/Workspace/C_C++/test.cpp:4: more undefined references to criterion_test_die' follow
/usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o: in function sample_test_impl': /home/bq666/Workspace/C_C++/test.cpp:5: undefined reference to criterion_options'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_translate_assert_msg' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:5: undefined reference to cr_asprintf'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:5: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_send_assert' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:5: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_continue_test' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:5: undefined reference to cri_asserts_passed_incr'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_options' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:6: undefined reference to cr_translate_assert_msg'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_asprintf' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:6: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:6: undefined reference to criterion_send_assert'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:6: undefined reference to criterion_continue_test'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cri_asserts_passed_incr' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:7: undefined reference to criterion_options'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_translate_assert_msg' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:7: undefined reference to cr_asprintf'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to cr_asprintf_free' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:7: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_send_assert' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:7: undefined reference to cr_asprintf_free'
/usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp undefined reference to criterion_abort_test' /usr/bin/ld: /home/bq666/Workspace/C_C++/test.cpp:7: undefined reference to cri_asserts_passed_incr'
/usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o:(.rodata+0x10): undefined reference to cr_malloc' /usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o:(.rodata+0x18): undefined reference to cr_free'
/usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o:(.rodata+0x20): undefined reference to cr_calloc' /usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o:(.rodata+0x28): undefined reference to cr_realloc'
/usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o:(.rodata+0x30): undefined reference to cr_log' /usr/bin/ld: CMakeFiles/C_C__.dir/test.cpp.o: in function criterion::sync()':
/usr/local/include/criterion/logging.h undefined reference to `cr_log'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/C_C__.dir/build.make C_C__] Error 1
gmake[2]: *** [CMakeFiles/Makefile2 CMakeFiles/C_C__.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2 CMakeFiles/C_C__.dir/rule] Error 2
gmake: *** [Makefile C_C__] Error 2

1

Problemem nie jest IDE tylko konfiguracja projektu.
Jako, że używasz make to powinieneś dopisać w pliku Makefile odpowiednie wpisy, które zlinkują tą bibliotekę do twojego projektu.
title

Czyli musisz dodać -lcriterion oraz jesli ot koniczeczne -L<lokalizacja biblioteki>

0

Dzięki wielkie za pomoc. Chyba widze światelko w tulelu :)
U mnie to leci tak:

┗❯ cat test.c
#include <criterion/criterion.h>
Test(simple, test){
cr_assert(0, "Hello");
}

gcc -o test test.c -lcriterion
./test
./test: error while loading shared libraries: libcriterion.so.3: cannot open shared object file: No such file or directory

więc:
find / -name libcriterion.so.3 2>1
/usr/local/lib/libcriterion.so.3
gcc -o test test.c -L"/usr/local/lib/" -lcriterion
./test: error while loading shared libraries: libcriterion.so.3: cannot open shared object file: No such file or directory

drwxr-xr-x  2 root root    4096 Jul 18 20:32 <font color="#0087FF"> .</font>
drwxr-xr-x 12 root root    4096 Apr 26 04:06 <font color="#0087FF"> ..</font>
lrwxrwxrwx  1 root root      17 Jul 18 10:00 <font color="#00FFFF"> libcriterion.so</font>   <font color="#00D700"> libcriterion.so.3</font>
lrwxrwxrwx  1 root root      21 Jul 18 10:00 <font color="#00FFFF"> libcriterion.so.3</font>   <font color="#00D700"> libcriterion.so.3.1.0</font>
-rwxr-xr-x  1 root root 3640808 Jul 18 20:31 <font color="#00D700"> libcriterion.so.3.1.0</font>
lrwxrwxrwx  1 root root      38 Jun 27 13:29 <font color="#00FFFF"> libjpeg.so.9</font>   <font color="#00D700"> /usr/local/lib/libjpeg-x86_64.so.9.2.0</font>
-rwxr-xr-x  1 root root 1158206 Jun 27 13:29 <font color="#00D700"> libjpeg-x86_64.so.9.2.0</font>

Tak że na tym się zatrzymałem. Zastanawiam się czy to że te biblioteki są na roocie nie stanowi problemu ?
Zgóry dzięki za pomoc.

0

Co zwraca

ldd /usr/local/lib/libcriterion.so
0

ldd /usr/local/lib/libcriterion.so
linux-vdso.so.1 (0x00007ffc2ad61000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f44fdb45000)
librt.so.1 => /lib64/librt.so.1 (0x00007f44fdb3b000)
libanl.so.1 => /lib64/libanl.so.1 (0x00007f44fdb35000)
libc.so.6 => /lib64/libc.so.6 (0x00007f44fd96f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f44fdd27000)

0

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

działa !!! :)

WIELKIE DZIĘKI ZA POMOC, sam bym się tutaj wykończył :)

0

To już będzie ostatnie na czym mi zależy, jak połączyć:
https://www.eclipse.org/cdt/documentation.php
z Criterion poprzez TAP ?
doszedłem to tego jal zrobić tap
./test --tap=test.tap
i w eclipsie mam zaznaczone:
screenshot-20190719103916.png

Nie umiem wpisać tego --tap=test.tap żeby się mi to połączyło to raz a dwa nie umiem tego pliku test.cpp odpalić w eclipcie:
plik test.cpp:

#include <string.h>
#include <criterion/criterion.h>

Test(sample, test) {
    cr_expect(strlen("Test") == 4, "Expected \"Test\" to have a length of 4.");
    cr_expect(strlen("Hello") == 4, "This will always fail, why did I add this?");
    cr_assert(strlen("") == 0);
}

A komunikat eclipsa:
Error starting process.
Exec_tty error:Cannot run program "/home/bq666/Workspace/eclipse/MyTest/src/test.cpp": Unknown reason
Exec_tty error:Cannot run program "/home/bq666/Workspace/eclipse/MyTest/src/test.cpp": Unknown reason
Exec_tty error:Cannot run program "/home/bq666/Workspace/eclipse/MyTest/src/test.cpp": Unknown reason

1 użytkowników online, w tym zalogowanych: 0, gości: 1