run-correct-reporting.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2011 Rusty Russell
  3. *
  4. * This program is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License as published by the Free Software
  6. * Foundation; either version 2 of the License, or (at your option) any later
  7. * version. See LICENSE for more details.
  8. */
  9. /* Make sure when multiple equivalent options, correct one is used for errors */
  10. #include <ccan/tap/tap.h>
  11. #include <stdlib.h>
  12. #include <ccan/opt/opt.c>
  13. #include <ccan/opt/usage.c>
  14. #include <ccan/opt/helpers.c>
  15. #include <ccan/opt/parse.c>
  16. #include "utils.h"
  17. int main(int argc, char *argv[])
  18. {
  19. plan_tests(12);
  20. /* --aaa without args. */
  21. opt_register_arg("-a|--aaa", test_arg, NULL, "aaa", "");
  22. ok1(!parse_args(&argc, &argv, "--aaa", NULL));
  23. ok1(strstr(err_output, ": --aaa: requires an argument"));
  24. free(err_output);
  25. err_output = NULL;
  26. ok1(!parse_args(&argc, &argv, "-a", NULL));
  27. ok1(strstr(err_output, ": -a: requires an argument"));
  28. free(err_output);
  29. err_output = NULL;
  30. /* Multiple */
  31. opt_register_arg("--bbb|-b|-c|--ccc", test_arg, NULL, "aaa", "");
  32. ok1(!parse_args(&argc, &argv, "--bbb", NULL));
  33. ok1(strstr(err_output, ": --bbb: requires an argument"));
  34. free(err_output);
  35. err_output = NULL;
  36. ok1(!parse_args(&argc, &argv, "-b", NULL));
  37. ok1(strstr(err_output, ": -b: requires an argument"));
  38. free(err_output);
  39. err_output = NULL;
  40. ok1(!parse_args(&argc, &argv, "-c", NULL));
  41. ok1(strstr(err_output, ": -c: requires an argument"));
  42. free(err_output);
  43. err_output = NULL;
  44. ok1(!parse_args(&argc, &argv, "--ccc", NULL));
  45. ok1(strstr(err_output, ": --ccc: requires an argument"));
  46. free(err_output);
  47. err_output = NULL;
  48. /* parse_args allocates argv */
  49. free(argv);
  50. return exit_status();
  51. }