From f975594e55bdc05ee436bc7bdcd6e09aec5357b1 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 7 Apr 2024 10:53:40 +0300 Subject: Finished implementation for formatting for human readability --- config-parser.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'config-parser.c') diff --git a/config-parser.c b/config-parser.c index cd97dc7..5e403f8 100644 --- a/config-parser.c +++ b/config-parser.c @@ -9,6 +9,8 @@ #include "minitest.h" #include "config-parser.h" +/* Returns a `Result` containing a dynamically allocated `Config` or a `char*` + * error message depending on the `success` field of the `Result`. */ Result parse_config(int argc, char* argv[]) { Result res; res.success = false; @@ -140,6 +142,7 @@ char* test_default_config() { mt_assert_eq(res.success, true); mt_assert_eq(conf->precision, 0); mt_assert_eq(conf->human_readable, false); + free(conf); return 0; } @@ -147,7 +150,6 @@ char* test_precision_parsing() { int argc; Result res; Config* conf; - char* error_msg; argc = 3; char* argv[] = { "stdu", "--precision", "3" }; @@ -165,7 +167,7 @@ char* test_precision_parsing() { res.success == false, "not specifying precision after `-p` didn't error" ); - free(error_msg); + free(res.result); argc = 4; char* argv3[] = { "stdu", "--precision", "1", "-p3" }; @@ -187,10 +189,7 @@ char* test_human_readability_parsing() { char* error_msg; argc = 2; - char* argv[] = { - "stdu", - "--human-readable" - }; + char* argv[] = { "stdu", "--human-readable" }; res = parse_config(argc, argv); conf = (Config*) res.result; mt_assert_eq(res.success, true); @@ -199,21 +198,10 @@ char* test_human_readability_parsing() { free(conf); argc = 3; - char* argv3[] = { - "stdu", - "-h", - "-h" - }; - res = parse_config(argc, argv3); + char* argv2[] = { "stdu", "-h", "-h" }; + res = parse_config(argc, argv2); error_msg = (char*) res.result; mt_assert_eq(res.success, false); - mt_assert( - strcmp( - error_msg, - "human readability can't be specified multiple times" - ), - "should error on double argument of human readability" - ); free(error_msg); return 0; -- cgit v1.2.3