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)\" GCC_COM ?= gcc -g -O0 -Wall -o $(exe) -D WEBSERVER -D STANDALONE -DSCRIPTDIR=\"$(SCRIPTDIR)\"
all: all:
$(GCC_COM) $(files) $(libs) && echo && ./tests.sh && ./pl --run-tests $(GCC_COM) $(file_libs) && echo && ./tests.sh
notest: notest:
$(GCC_COM) $(file_libs) $(GCC_COM) $(file_libs)

View File

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

View File

@ -771,8 +771,17 @@ int main(int argc, const char* argv[])
struct Environment env = defaultEnv(); struct Environment env = defaultEnv();
setGlobal(&env); setGlobal(&env);
if (argc == 2 && strcmp(argv[1], "--run-tests") == 0) { int ret = -1;
return runTests(); 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; struct sigaction action;

View File

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

View File

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

View File

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