Fix some busted tests.

Better styling of native test printing.
Add `detail` parameter to runTests().
This commit is contained in:
Sage Vaillancourt 2022-03-25 16:11:20 -04:00 committed by Sage Vaillancourt
parent 59c6ff50b5
commit 502b9349fe
7 changed files with 44 additions and 10 deletions

View File

@ -12,7 +12,7 @@ mkfile_dir := $(dir $(mkfile_path))
GCC_COM ?= gcc -g -O0 -Wall -o $(exe) -D WEBSERVER -D STANDALONE -DSCRIPTDIR=\"$(SCRIPTDIR)\"
all:
$(GCC_COM) $(files) $(libs) && echo && ./tests.sh && ./pl --run-tests
$(GCC_COM) $(file_libs) && echo && ./tests.sh
notest:
$(GCC_COM) $(file_libs)

View File

@ -346,7 +346,7 @@ fnn(segfault, "seg", "Induces a segfault.")
}
// Returns number of failures
int runTests()
int runTests(int detailed)
{
printf("::NATIVE TESTS::\n");
int failureCount = 0;
@ -355,9 +355,9 @@ int runTests()
struct helpText h = helpTexts[hi];
if (h.tests) {
char result[1024];
// if (h.testCount == 0) {
// printf("`%s` is untested.\n", h.symbol);
// }
if (detailed && h.testCount > 0) {
printf(" `%s` ", h.symbol);
}
for (int ti = 0; ti < h.testCount; ti += 2) {
const char* test = h.tests[ti];
const char* expected = h.tests[ti + 1];
@ -371,8 +371,15 @@ int runTests()
printf("%s\n", test);
printf("Expected '%s' but received '%s'\n", expected, result);
} else {
if (detailed) {
printf("✓");
}
passCount++;
}
deleteEnv(&env);
}
if (detailed && h.testCount > 0) {
printf("\n");
}
}
}

View File

@ -48,6 +48,6 @@ char* getHelp(const char* symbol);
void printColored(const char* code);
int runTests();
int runTests(int detailed);
#endif

View File

@ -771,8 +771,17 @@ int main(int argc, const char* argv[])
struct Environment env = defaultEnv();
setGlobal(&env);
if (argc == 2 && strcmp(argv[1], "--run-tests") == 0) {
return runTests();
int ret = -1;
if (argc == 2) {
if (strcmp(argv[1], "--run-tests") == 0) {
ret = runTests(0);
} else if (strcmp(argv[1], "--run-tests=detailed") == 0) {
ret = runTests(1);
}
}
if (ret != -1) {
deleteEnv(global());
return ret;
}
struct sigaction action;

View File

@ -26,8 +26,17 @@ Object charAt(Object* params, int length, struct Environment* env)
Object at = params[1];
char* c = malloc(sizeof(char) * 2);
c[0] = string.string[at.number];
c[1] = '\0';
for (int i = 0; i < at.number; i++) {
if (string.string[i] == '\0') {
c[0] = '\0';
string.string = c;
return string;
}
}
c[0] = string.string[at.number];
string.string = c;
return string;
}
@ -89,6 +98,9 @@ Object at(Object* params, int length, struct Environment* env)
Object rest(Object* params, int length, struct Environment* env)
{
Object list = params[0];
if (!isListy(list)) {
return errorObject(NOT_A_LIST);
}
Object ret = listObject();
Object* l = &list;

View File

@ -85,7 +85,7 @@ fn(rest,
"Get the tail of a list. All but the first element.",
"(rest (1 2 3))", "( 2 3 )",
"(rest ())", "( )",
"(rest \"string\")", "( )",
"(rest \"string\")", "NOT_A_LIST",
);
/// LIST => LIST

View File

@ -269,3 +269,9 @@ fi
echo "$TOTAL_FAILS Tests Failed"
echo ""
if $VALGRIND; then
$VALCOM ./pl --run-tests=detailed
else
./pl --run-tests
fi