diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | generate.py | 13 | ||||
| -rw-r--r-- | header.h | 5 | ||||
| -rw-r--r-- | helper.c | 6 | ||||
| -rw-r--r-- | prettier.py | 26 | ||||
| -rw-r--r-- | tmp.c | 3 |
6 files changed, 43 insertions, 17 deletions
@@ -1,7 +1,7 @@ FT_PRINTF_PATH = ../ft_printf CC = gcc -CCFLAGS = -Wall -Wextra -Wno-format +CCFLAGS = -Wall -Wextra LDFLAGS = -L$(FT_PRINTF_PATH) -lftprintf NAME = ft_printf_test @@ -25,12 +25,15 @@ quiet: all no_clear: all ./$(NAME) | $(PYTHON) prettier.py --no-clear +interactive: all + ./$(NAME) | $(PYTHON) prettier.py --interactive + raw: all ./$(NAME) all: $(NAME) -$(NAME): ft_printf_all $(OBJ) +$(NAME): ft_printf_all $(OBJ) header.h tests/tests.h $(CC) $(LDFLAGS) $(CCFLAGS) -o $@ $(OBJ) %.o: %.c diff --git a/generate.py b/generate.py index f119874..bbe4312 100644 --- a/generate.py +++ b/generate.py @@ -89,10 +89,19 @@ def generate_printf(): if __name__ == "__main__": options = parse_args() + nb_tests = options["n"] with open("generated.c", "w") as file: file.write("#include \"header.h\"\n\nvoid generated_test(void)\n{\n\t") - for _ in range(options["n"]): - file.write(generate_printf() + "\n\t") + while nb_tests > 0: + with open("tmp.c", "w") as tmp: + tmp.write("#include <stdio.h>\n#include \"header.h\"\nvoid t (){") + tmp_assert = generate_printf() + tmp.write(tmp_assert + "}") + ret = os.system("gcc -c -Wall -Wextra -Werror tmp.c > /dev/null 2>&1") + print(ret) + if ret == 0: + file.write(tmp_assert + "\n\t") + nb_tests -= 1 file.write("}\n") @@ -32,6 +32,7 @@ void test_setup(void); void test_tear_down(void); char *read_stdout_buf(void); +// # define DEBUG # define TEST_SEGFAULT(x) do { \ if ((pid = fork()) < 0) \ @@ -65,7 +66,7 @@ char *read_stdout_buf(void); if (!origin_signaled && user_signaled) \ print_signaled_ko(#__VA_ARGS__); \ else if (origin_signaled && user_signaled) \ - print_ok(); \ + print_ok(); \ else if (!origin_signaled && !user_signaled) { \ if (memcmp(origin_buf, user_buf, \ strlen(origin_buf) + 1) != 0) \ @@ -73,7 +74,7 @@ char *read_stdout_buf(void); else if (origin_ret != user_ret) \ print_ret_ko(#__VA_ARGS__); \ else \ - print_ok(); \ + print_ok(); \ } \ if (!origin_signaled) free(origin_buf); \ if (!user_signaled) free(user_buf); \ @@ -94,11 +94,11 @@ void ft_putstr_non_printable(char *str) printf("\\0"); else { - ft_putchar('\\'); + putchar('\\'); tmp = *cursor / 16; - ft_putchar(hex_symbols[tmp]); + putchar(hex_symbols[tmp]); tmp = *cursor % 16; - ft_putchar(hex_symbols[tmp]); + putchar(hex_symbols[tmp]); } cursor++; } diff --git a/prettier.py b/prettier.py index c58327d..439369c 100644 --- a/prettier.py +++ b/prettier.py @@ -21,11 +21,21 @@ def parse_args(): parser.add_argument("-l", "--no-log", help="disable result log", action="store_true") parser.add_argument("-c", "--no-clear", help="disable terminal clear before output") + parser.add_argument("-i", "--interactive", help="print fail as them come", + action="store_true") parser.add_argument("-f", "--output-file", help="output file name") return vars(parser.parse_args(sys.argv[1:])) -def parse(): +def print_log_ko(ko, options): + print(f"- [{red(ko['type'])}] ft_printf({ko['args']})") + if options["verbose"]: + print(" expected: ", ko["expected"]) + print(" actual: ", ko["actual"]) + print() + + +def parse(options): logs = { "ok": 0, "ko": 0, @@ -50,7 +60,11 @@ def parse(): "expected": m.group(3), "actual": m.group(4), }) - print(red("!"), end="") + if options["interactive"]: + print() + print_log_ko(logs["ko_info"][-1], options) + else: + print(red("!"), end="") return logs @@ -77,11 +91,7 @@ def print_logs(logs, options): infos = logs["ko_info"][:20] if options["quiet"] else logs["ko_info"] for ko in infos: - print(f"- [{red(ko['type'])}] ft_printf({ko['args']})") - if options["verbose"]: - print(" expected: ", ko["expected"]) - print(" actual: ", ko["actual"]) - print() + print_log_ko(ko, options) if options["quiet"] and logs["ko"] > 20: print("...") print("\nSee result.log for more information\n") @@ -92,7 +102,7 @@ if __name__ == "__main__": options = parse_args() if not options["no_clear"]: os.system("clear") - logs = parse() + logs = parse(options) print_logs(logs, options) if not options["no_log"]: write_logs(logs, options) @@ -0,0 +1,3 @@ +#include <stdio.h> +#include "header.h" +void t (){
\ No newline at end of file |
