diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-02 04:21:43 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-02 05:08:52 +0100 |
| commit | de0a7f5d17807506f177b5dc90a6d9ccdb679435 (patch) | |
| tree | 5fd93e471219070754b5cfff6c497eb7ff9c3325 | |
| parent | 29387bf2bcc964a572a4bb267b13e685ca20d643 (diff) | |
| download | ft_printf_test-de0a7f5d17807506f177b5dc90a6d9ccdb679435.tar.gz ft_printf_test-de0a7f5d17807506f177b5dc90a6d9ccdb679435.tar.bz2 ft_printf_test-de0a7f5d17807506f177b5dc90a6d9ccdb679435.zip | |
Moved tests in tests/, improved prettier with arguments
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | header.h | 49 | ||||
| -rw-r--r-- | helper.c | 3 | ||||
| -rw-r--r-- | main.c | 3 | ||||
| -rw-r--r-- | prettier.py | 47 | ||||
| -rw-r--r-- | tests/moulitest_tests.c (renamed from moulitest_tests.c) | 3 | ||||
| -rw-r--r-- | tests/pft_tests.c (renamed from pft_tests.c) | 2 | ||||
| -rw-r--r-- | tests/tests.h | 52 |
10 files changed, 108 insertions, 63 deletions
@@ -3,3 +3,4 @@ ft_printf_test *.o *.ghc *.dSYM +result.log @@ -9,7 +9,7 @@ PYTHON = python3 RM = rm -f MAKE = make -j4 -SRC = main.c helper.c pft_tests.c moulitest_tests.c +SRC = main.c helper.c tests/pft_tests.c tests/moulitest_tests.c OBJ = $(SRC:.c=.o) run: run_pretty @@ -17,6 +17,12 @@ run: run_pretty run_pretty: all ./$(NAME) | $(PYTHON) prettier.py +run_pretty_verbose: + ./$(NAME) | $(PYTHON) prettier.py --verbose + +run_pretty_quiet: + ./$(NAME) | $(PYTHON) prettier.py --quiet + run_raw: all ./$(NAME) @@ -16,3 +16,6 @@ or modify the `FT_PRINTF_PATH` variable in the Makefile - `> make run`: run the tests in a pretty format - `> make run_raw`: run the tests in a ugly but parsable format +- `> make run_prettier_verbose`: to show a more verbose output +- `> make run_prettier_quiet`: to show a more quiet output +- `> python3 prettier -h`: show prettier options @@ -8,8 +8,6 @@ # include <string.h> # include <stdbool.h> -# define BUF_SIZE 2048 * 10 - int pid; bool signaled; static bool origin_signaled = false; @@ -31,53 +29,6 @@ void test_setup(void); void test_tear_down(void); char *read_stdout_buf(void); -void test_pft_nacked(void); -void test_pft_percent(void); -void test_pft_string(void); -void test_pft_int_i(void); -void test_pft_int_d(void); -void test_ptf_uint(void); -void test_ptf_hex_low(void); -void test_ptf_hex_up(void); -void test_pft_ptr(void); -void test_pft_char(void); - -void test_moulitest_00(void); -void test_moulitest_01(void); -void test_moulitest_02(void); -void test_moulitest_03(void); -void test_moulitest_04(void); -void test_moulitest_05(void); -void test_moulitest_06(void); -void test_moulitest_09(void); -void test_moulitest_12(void); -void test_moulitest_14(void); -void test_moulitest_15(void); -void test_moulitest_16(void); -void test_moulitest_18(void); -void test_moulitest_40(void); -void test_moulitest_41(void); -void test_moulitest_42(void); -void test_moulitest_43(void); -void test_moulitest_45(void); -void test_moulitest_50(void); -void test_moulitest_51(void); -void test_moulitest_52(void); -void test_moulitest_60(void); -void test_moulitest_61(void); -void test_moulitest_69(void); -void test_moulitest_70(void); -void test_moulitest_71(void); -void test_moulitest_72(void); -void test_moulitest_73(void); -void test_moulitest_74(void); -void test_moulitest_79(void); -void test_moulitest_90(void); -void test_moulitest_91(void); -void test_moulitest_wildcard_01(void); -void test_moulitest_wildcard_02(void); -void test_moulitest_wildcard_03(void); - # define TEST_SEGFAULT(x) do { \ if ((pid = fork()) < 0) \ exit(EXIT_FAILURE); \ @@ -2,7 +2,7 @@ #include <unistd.h> #include "header.h" -/* #define BUF_SIZE (1 << 10) */ +#define BUF_SIZE (1 << 10) int pipefd[2]; int saved_stdout = -1; @@ -34,6 +34,7 @@ void test_tear_down(void) close(pipefd[0]); close(pipefd[1]); } + fflush(stdout); } #include <fcntl.h> @@ -1,8 +1,11 @@ #include <stdio.h> #include "header.h" +#include "tests/tests.h" int main(int argc, char **argv) { + (void)argc; + (void)argv; test_pft_nacked(); test_pft_percent(); test_pft_string(); diff --git a/prettier.py b/prettier.py index f12978f..9425f80 100644 --- a/prettier.py +++ b/prettier.py @@ -1,19 +1,33 @@ import sys +import argparse + def green(*strings): return "".join([f"\033[32m{s}\033[0m" for s in strings]) + def red(*strings): return "".join([f"\033[31m{s}\033[0m" for s in strings]) +def parse_args(): + parser = argparse.ArgumentParser( prog="ft_printf test", description="A ~quicker tester for ft_printf") + parser.add_argument("-v", "--verbose", + help="increase verbosity", action="store_true") + parser.add_argument("-q", "--quiet", + help="decrease vebosity", action="store_true") + parser.add_argument("-l", "--no-log", + help="disable result log", action="store_true") + parser.add_argument("-f", "--output-file", help="output file name") + return vars(parser.parse_args(sys.argv[1:])) + + def parse(): logs = { "ok": 0, "ko": 0, "ko_info": [] } - for line in sys.stdin: line = line.strip() if line.find("[OK]") != -1: @@ -31,22 +45,37 @@ def parse(): return logs -# def write_logs(logs): +def write_logs(logs, options): + filename = "result.log" + if options["output_file"] is not None: + filename = options["output_file"] + with open(filename, "w") as log_file: + for ko in logs["ko_info"]: + log_file.write("- " + ko["msg"] + "\n") + log_file.write(" " + ko["expected"] + "\n") + log_file.write(" " + ko["actual"] + "\n\n") + -def print_logs(logs): +def print_logs(logs, options): total_str = f"\n\nTotal {green('OK: ', logs['ok'])} {red('KO: ', logs['ko'])}" print(total_str) print("=" * (len(total_str) - len(green("")) * 2 - len(red("")) * 2 - 2)) + if options["quiet"]: + return for ko in logs["ko_info"]: - print(ko["msg"]) - print(" ", ko["expected"]) - print(" ", ko["actual"]) - print() + print("-", ko["msg"]) + if options["verbose"]: + print(" ", ko["expected"]) + print(" ", ko["actual"]) + print() + print("\nSee result.log for more information\n") if __name__ == "__main__": print() + options = parse_args() logs = parse() - # write_logs(logs) - print_logs(logs) + print_logs(logs, options) + if not options["no_log"]: + write_logs(logs, options) diff --git a/moulitest_tests.c b/tests/moulitest_tests.c index 546cf62..296f0ed 100644 --- a/moulitest_tests.c +++ b/tests/moulitest_tests.c @@ -1,5 +1,5 @@ #include <limits.h> -#include "header.h" +#include "../header.h" void test_moulitest_00(void) @@ -189,7 +189,6 @@ void test_moulitest_43(void) ASSERT_PRINTF("%hhu, %hhu", 0, UCHAR_MAX + 42); ASSERT_PRINTF("%hhx, %hhx", 0, UCHAR_MAX + 42); ASSERT_PRINTF("%hhX, %hhX", 0, UCHAR_MAX + 42); - ASSERT_PRINTF("%hhD, %hhD", 0, USHRT_MAX); } void test_moulitest_45(void) diff --git a/pft_tests.c b/tests/pft_tests.c index 0dea3bb..dad1153 100644 --- a/pft_tests.c +++ b/tests/pft_tests.c @@ -1,4 +1,4 @@ -#include "header.h" +#include "../header.h" void test_pft_nacked(void) { diff --git a/tests/tests.h b/tests/tests.h new file mode 100644 index 0000000..6484d20 --- /dev/null +++ b/tests/tests.h @@ -0,0 +1,52 @@ +#ifndef FT_PRINTF_TEST_TESTS_H +# define FT_PRINTF_TEST_TESTS_H + +void test_pft_nacked(void); +void test_pft_percent(void); +void test_pft_string(void); +void test_pft_int_i(void); +void test_pft_int_d(void); +void test_ptf_uint(void); +void test_ptf_hex_low(void); +void test_ptf_hex_up(void); +void test_pft_ptr(void); +void test_pft_char(void); + +void test_moulitest_00(void); +void test_moulitest_01(void); +void test_moulitest_02(void); +void test_moulitest_03(void); +void test_moulitest_04(void); +void test_moulitest_05(void); +void test_moulitest_06(void); +void test_moulitest_09(void); +void test_moulitest_12(void); +void test_moulitest_14(void); +void test_moulitest_15(void); +void test_moulitest_16(void); +void test_moulitest_18(void); +void test_moulitest_40(void); +void test_moulitest_41(void); +void test_moulitest_42(void); +void test_moulitest_43(void); +void test_moulitest_45(void); +void test_moulitest_50(void); +void test_moulitest_51(void); +void test_moulitest_52(void); +void test_moulitest_60(void); +void test_moulitest_61(void); +void test_moulitest_69(void); +void test_moulitest_70(void); +void test_moulitest_71(void); +void test_moulitest_72(void); +void test_moulitest_73(void); +void test_moulitest_74(void); +void test_moulitest_79(void); +void test_moulitest_90(void); +void test_moulitest_91(void); +void test_moulitest_wildcard_01(void); +void test_moulitest_wildcard_02(void); +void test_moulitest_wildcard_03(void); + + +#endif |
