introduce cmdtest into the project + basic tests

This commit is contained in:
anon 2024-11-30 12:52:01 +01:00
parent 741921d60c
commit c856b5ff90
6 changed files with 78 additions and 0 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
csope
source/lex.yy.c
main.plist
tmp-cmdtest-*
.cmdtest-filter

View File

@ -1,3 +1,5 @@
.PHONY: test
LIBS:=ncurses readline
CFLAGS += $(if $(SAN),-fsanitize=${SAN}) -Wno-unused-result
@ -46,3 +48,6 @@ clean:
-${RM} ${GENYACC}
-${RM} ${object}
-${RM} ${OUTPUT}
test:
cmdtest --fast

39
test/CMDTEST_main.rb Normal file
View File

@ -0,0 +1,39 @@
# NOTE: Kernel mode should be used accross the board,
# because system headers are volatile.
# Writting tests for them would be foolish.
# They could even introduce interfering
# symbols in the future by pure chance,
# if not completely ignored.
# The following variables are magick numbers based on `dummy_project/`.
$f_definition_line = 5
class CMDTEST_misc_batch < Cmdtest::Testcase
def test_no_arg
cmd "csope" do
stdout_equal /.+/
stderr_equal /.+/
exit_status 1
end
end
end
class CMDTEST_dummy_project < Cmdtest::Testcase
def setup
import_directory "test/dummy_project/", "./dummy_project/"
end
def test_find_f
cmd "csope -k -L -0 f -s dummy_project/" do
created_files ["cscope.out"]
stdout_equal /\A(.*\n){2}\Z/
end
end
def test_find_def_f
cmd "csope -k -L -1 f -s dummy_project/" do
created_files ["cscope.out"]
stdout_equal /\A.+#{$f_definition_line}.+\n\Z/
end
end
end

10
test/dummy_project/h.c Normal file
View File

@ -0,0 +1,10 @@
#include "h.h"
#include <stdlib.h>
double h(int i) {
if (i < 100000) {
return rand() % i;
} else {
return i / 10;
}
}

6
test/dummy_project/h.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef H_H
#define H_H
extern double h(int i);
#endif

16
test/dummy_project/main.c Normal file
View File

@ -0,0 +1,16 @@
// @BAKE gcc -o dummy.out main.c h.c
#include <stdlib.h>
#include "h.h"
int f(void) {
int r = 0;
for (int i = 0; i < 100; i++) {
r += (int)h(r);
}
return r;
}
signed main(void) {
return f();
}