From 1e69e89ff9e45951d4374a44ec892f9f6f91a956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sat, 1 Dec 2018 17:36:58 -0500 Subject: [PATCH] t: check a few cases of successful option parsing --- t/cli.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/t/cli.cc b/t/cli.cc index 33d5383..4198362 100644 --- a/t/cli.cc +++ b/t/cli.cc @@ -18,6 +18,34 @@ void check_read_comments() throw failure("parsed user comments did not match expectations"); } +void check_good_arguments() +{ + auto parse = [](std::vector args) { + ot::options opt; + ot::status rc = ot::parse_options(args.size(), const_cast(args.data()), opt); + if (rc.code != ot::st::ok) + throw failure("unexpected option parsing error"); + return opt; + }; + + ot::options opt; + opt = parse({"opustags", "--help", "x", "-o", "y"}); + if (!opt.print_help) + throw failure("did not catch --help"); + + opt = parse({"opustags", "x", "--output", "y", "-D", "-s", "X=Y Z"}); + if (opt.inplace != nullptr || opt.path_in != "x" || opt.path_out != "y" || !opt.delete_all || + opt.to_delete.size() != 1 || opt.to_delete[0] != "X=Y Z" || + opt.to_add.size() != 1 || opt.to_add[0] != "X=Y Z") + throw failure("unexpected option parsing result for case #1"); + + opt = parse({"opustags", "-S", "-y", "x", "-S", "-a", "x=y z", "-i"}); + if (opt.inplace == nullptr || opt.path_in != "x" || !opt.path_out.empty() || + !opt.set_all || !opt.overwrite || opt.to_delete.size() != 0 || + opt.to_add.size() != 1 || opt.to_add[0] != "x=y z") + throw failure("unexpected option parsing result for case #2"); +} + void check_bad_arguments() { auto error_case = [](std::vector args, const char* message, const std::string& name) { @@ -53,8 +81,9 @@ void check_bad_arguments() int main(int argc, char **argv) { - std::cout << "1..2\n"; + std::cout << "1..3\n"; run(check_read_comments, "check tags parsing"); + run(check_good_arguments, "check options parsing"); run(check_bad_arguments, "check options parsing errors"); return 0; }