run-correct-reporting.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Make sure when multiple equivalent options, correct one is used for errors */
  2. #include <ccan/tap/tap.h>
  3. #include <stdlib.h>
  4. #include <ccan/opt/opt.c>
  5. #include <ccan/opt/usage.c>
  6. #include <ccan/opt/helpers.c>
  7. #include <ccan/opt/parse.c>
  8. #include "utils.h"
  9. int main(int argc, char *argv[])
  10. {
  11. plan_tests(12);
  12. /* --aaa without args. */
  13. opt_register_arg("-a|--aaa", test_arg, NULL, "aaa", "");
  14. ok1(!parse_args(&argc, &argv, "--aaa", NULL));
  15. ok1(strstr(err_output, ": --aaa: requires an argument"));
  16. free(err_output);
  17. err_output = NULL;
  18. ok1(!parse_args(&argc, &argv, "-a", NULL));
  19. ok1(strstr(err_output, ": -a: requires an argument"));
  20. free(err_output);
  21. err_output = NULL;
  22. /* Multiple */
  23. opt_register_arg("--bbb|-b|-c|--ccc", test_arg, NULL, "aaa", "");
  24. ok1(!parse_args(&argc, &argv, "--bbb", NULL));
  25. ok1(strstr(err_output, ": --bbb: requires an argument"));
  26. free(err_output);
  27. err_output = NULL;
  28. ok1(!parse_args(&argc, &argv, "-b", NULL));
  29. ok1(strstr(err_output, ": -b: requires an argument"));
  30. free(err_output);
  31. err_output = NULL;
  32. ok1(!parse_args(&argc, &argv, "-c", NULL));
  33. ok1(strstr(err_output, ": -c: requires an argument"));
  34. free(err_output);
  35. err_output = NULL;
  36. ok1(!parse_args(&argc, &argv, "--ccc", NULL));
  37. ok1(strstr(err_output, ": --ccc: requires an argument"));
  38. free(err_output);
  39. err_output = NULL;
  40. /* parse_args allocates argv */
  41. free(argv);
  42. return exit_status();
  43. }