Skip to content

Commit 2e15200

Browse files
committed
add metatests for test failure
1 parent 2ab4dde commit 2e15200

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,19 @@ ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_LIBRARY_PREFIX}cliffi_test${CMA
616616
set_tests_properties(repl_smoketest PROPERTIES PASS_REGULAR_EXPRESSION "Function returned: 3")
617617
set_tests_properties(repl_smoketest PROPERTIES PASS_REGULAR_EXPRESSION "Function returned: 7")
618618

619+
add_test(NAME repl_metatest_tests_fail_on_bad_input
620+
COMMAND cliffi --repltest
621+
thisisnotagoodcommand \n
622+
should_not_reach_here = 1 \n
623+
)
624+
set_tests_properties(repl_metatest_tests_fail_on_bad_input PROPERTIES WILL_FAIL TRUE) # this test is expected to fail
625+
626+
add_test(NAME repl_metatest_tests_fail_on_segfault
627+
COMMAND cliffi --repltest
628+
null_pointer = -P 0 \n
629+
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_LIBRARY_PREFIX}cliffi_test${CMAKE_SHARED_LIBRARY_SUFFIX} i increment_at_pointer null_pointer \n
630+
)
631+
set_tests_properties(repl_metatest_tests_fail_on_segfault PROPERTIES WILL_FAIL TRUE) # this test is expected to fail
619632

620633
add_test(NAME repl_test_globals #
621634
COMMAND cliffi --repltest

cliffi_testlib.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ double multiply(double a, double b) {
2626
}
2727

2828
// A function that takes a pointer to an integer, increments it, and returns the result
29-
int increment_at_pointer(int* a) {
30-
if (a) {
31-
(*a)++;
32-
return *a;
33-
}
34-
return 0;
29+
int increment_at_pointer(int* a) { //deliberately unsafe
30+
(*a)++;
31+
return *a;
3532
}
3633

3734
int* get_array_of_int(int a, size_t size) {

0 commit comments

Comments
 (0)