run-no-options.c 738 B

123456789101112131415161718192021222324252627282930313233
  1. /* Make sure we still work with no options registered */
  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. const char *myname = argv[0];
  12. plan_tests(7);
  13. /* Simple short arg.*/
  14. ok1(!parse_args(&argc, &argv, "-a", NULL));
  15. /* Simple long arg.*/
  16. ok1(!parse_args(&argc, &argv, "--aaa", NULL));
  17. /* Extra arguments preserved. */
  18. ok1(parse_args(&argc, &argv, "extra", "args", NULL));
  19. ok1(argc == 3);
  20. ok1(argv[0] == myname);
  21. ok1(strcmp(argv[1], "extra") == 0);
  22. ok1(strcmp(argv[2], "args") == 0);
  23. /* parse_args allocates argv */
  24. free(argv);
  25. return exit_status();
  26. }