Skip to content

Commit

Permalink
Process test results with printf output that's not terminated by a ne…
Browse files Browse the repository at this point in the history
…wline (#111)
  • Loading branch information
ryanplusplus authored Apr 18, 2024
1 parent 84e8968 commit 6399a13
Show file tree
Hide file tree
Showing 9 changed files with 3,065 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/process_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def truncate(text, maxlength=500):

def process_results(filepath):
output = {"version": 2, "status": "pass", "message": None, "tests": []}
pattern = r"(?m)^((?P<file>.*test_.*\.c):\d+:(?P<name>\w+):(?:\033\[\d+m)?(?P<status>PASS|FAIL)(?:\033\[\d+m)?(?:: (?P<message>.*))?)$"
pattern = r"(?m)^.*?((?P<file>test_.*\.c):\d+:(?P<name>\w+):(?:\033\[\d+m)?(?P<status>PASS|FAIL)(?:\033\[\d+m)?(?:: (?P<message>.*))?)$"
text = filepath.read_text()
# remove text "Compiling tests.out"
text = text[20:]
Expand Down
20 changes: 20 additions & 0 deletions tests/printf-output-with-no-newline/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 2,
"status": "pass",
"message": null,
"tests": [
{
"name": "test_add",
"status": "pass",
"output": "no newline"
},
{
"name": "test_sub",
"status": "pass"
},
{
"name": "test_mul",
"status": "pass"
}
]
}
37 changes: 37 additions & 0 deletions tests/printf-output-with-no-newline/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
### If you wish to use extra libraries (math.h for instance),
### add their flags here (-lm in our case) in the "LIBS" variable.

LIBS = -lm

###
CFLAGS = -std=c99
CFLAGS += -g
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -pedantic
CFLAGS += -Werror
CFLAGS += -Wmissing-declarations
CFLAGS += -DUNITY_SUPPORT_64 -DUNITY_OUTPUT_COLOR

ASANFLAGS = -fsanitize=address
ASANFLAGS += -fno-common
ASANFLAGS += -fno-omit-frame-pointer

.PHONY: test
test: tests.out
@./tests.out

.PHONY: memcheck
memcheck: ./*.c ./*.h
@echo Compiling $@
@$(CC) $(ASANFLAGS) $(CFLAGS) test-framework/unity.c ./*.c -o memcheck.out $(LIBS)
@./memcheck.out
@echo "Memory check passed"

.PHONY: clean
clean:
rm -rf *.o *.out *.out.dSYM

tests.out: ./*.c ./*.h
@echo Compiling $@
@$(CC) $(CFLAGS) test-framework/unity.c ./*.c -o tests.out $(LIBS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#include "printf_output_with_no_newline.h"

int add(int x, int y)
{
printf("no newline");
return x + y;
}

int sub(int x, int y)
{
return x - y;
}

int mul(int x, int y)
{
return x * y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef PRINTF_OUTPUT_WITH_NO_NEWLINE_H
#define PRINTF_OUTPUT_WITH_NO_NEWLINE_H

int add(int x, int y);
int sub(int x, int y);
int mul(int x, int y);

#endif
Loading

0 comments on commit 6399a13

Please sign in to comment.