diff options
author | Joel Kronqvist <joelkronqvist@proton.me> | 2024-04-07 10:53:40 +0300 |
---|---|---|
committer | Joel Kronqvist <joelkronqvist@proton.me> | 2024-04-07 10:53:40 +0300 |
commit | f975594e55bdc05ee436bc7bdcd6e09aec5357b1 (patch) | |
tree | e1ddb07ab967bbe9eb6a14865e7413b9b2e1ea0c /config-parser.c | |
parent | 1ef526c695df4b37aa184867fb5b62c93118aa02 (diff) | |
download | stdu-f975594e55bdc05ee436bc7bdcd6e09aec5357b1.tar.gz stdu-f975594e55bdc05ee436bc7bdcd6e09aec5357b1.zip |
Finished implementation for formatting for human readability
Diffstat (limited to 'config-parser.c')
-rw-r--r-- | config-parser.c | 26 |
1 files changed, 7 insertions, 19 deletions
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; |