run-no-options.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 we still work with no options registered */
  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. const char *myname = argv[0];
  20. plan_tests(7);
  21. /* Simple short arg.*/
  22. ok1(!parse_args(&argc, &argv, "-a", NULL));
  23. /* Simple long arg.*/
  24. ok1(!parse_args(&argc, &argv, "--aaa", NULL));
  25. /* Extra arguments preserved. */
  26. ok1(parse_args(&argc, &argv, "extra", "args", NULL));
  27. ok1(argc == 3);
  28. ok1(argv[0] == myname);
  29. ok1(strcmp(argv[1], "extra") == 0);
  30. ok1(strcmp(argv[2], "args") == 0);
  31. /* parse_args allocates argv */
  32. free(argv);
  33. return exit_status();
  34. }