diff options
-rw-r--r-- | tests/core/test_getopt.in | 45 | ||||
-rw-r--r-- | tests/core/test_getopt.out | 2 | ||||
-rw-r--r-- | tests/test_core.py | 48 |
3 files changed, 50 insertions, 45 deletions
diff --git a/tests/core/test_getopt.in b/tests/core/test_getopt.in new file mode 100644 index 00000000..1f03ef4e --- /dev/null +++ b/tests/core/test_getopt.in @@ -0,0 +1,45 @@ + + #pragma clang diagnostic ignored "-Winvalid-pp-token" + #include <unistd.h> + #include <stdlib.h> + #include <stdio.h> + + int + main(int argc, char *argv[]) + { + int flags, opt; + int nsecs, tfnd; + + nsecs = 0; + tfnd = 0; + flags = 0; + while ((opt = getopt(argc, argv, "nt:")) != -1) { + switch (opt) { + case 'n': + flags = 1; + break; + case 't': + nsecs = atoi(optarg); + tfnd = 1; + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", + argv[0]); + exit(EXIT_FAILURE); + } + } + + printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); + + if (optind >= argc) { + fprintf(stderr, "Expected argument after options\n"); + exit(EXIT_FAILURE); + } + + printf("name argument = %s\n", argv[optind]); + + /* Other code omitted */ + + exit(EXIT_SUCCESS); + } +
\ No newline at end of file diff --git a/tests/core/test_getopt.out b/tests/core/test_getopt.out new file mode 100644 index 00000000..d06da507 --- /dev/null +++ b/tests/core/test_getopt.out @@ -0,0 +1,2 @@ +flags=1; tfnd=1; optind=4 +name argument = foobar
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index 0f84c51f..a55f51a5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2542,52 +2542,10 @@ The current type of b is: 9 def test_getopt(self): if self.emcc_args is None: return self.skip('needs emcc for libc') - src = ''' - #pragma clang diagnostic ignored "-Winvalid-pp-token" - #include <unistd.h> - #include <stdlib.h> - #include <stdio.h> - - int - main(int argc, char *argv[]) - { - int flags, opt; - int nsecs, tfnd; - - nsecs = 0; - tfnd = 0; - flags = 0; - while ((opt = getopt(argc, argv, "nt:")) != -1) { - switch (opt) { - case 'n': - flags = 1; - break; - case 't': - nsecs = atoi(optarg); - tfnd = 1; - break; - default: /* '?' */ - fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\\n", - argv[0]); - exit(EXIT_FAILURE); - } - } - - printf("flags=%d; tfnd=%d; optind=%d\\n", flags, tfnd, optind); - - if (optind >= argc) { - fprintf(stderr, "Expected argument after options\\n"); - exit(EXIT_FAILURE); - } - - printf("name argument = %s\\n", argv[optind]); - - /* Other code omitted */ + test_path = path_from_root('tests', 'core', 'test_getopt') + src, output = (test_path + s for s in ('.in', '.out')) - exit(EXIT_SUCCESS); - } - ''' - self.do_run(src, 'flags=1; tfnd=1; optind=4\nname argument = foobar', args=['-t', '12', '-n', 'foobar']) + self.do_run_from_file(src, output, args=['-t', '12', '-n', 'foobar']) def test_getopt_long(self): if self.emcc_args is None: return self.skip('needs emcc for libc') |