diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 11:06:29 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 19:35:53 +0200 |
commit | dca1ceb65a07c6d1a0bdbae1705ac5c90bacd929 (patch) | |
tree | b215e2ed0b64db57bbce48de32f93014481342c3 /tests | |
parent | 121b362fc7afa14217858e9188a6c858b687656c (diff) |
Use do_run_from_file() for test_regex
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/test_regex.in | 37 | ||||
-rw-r--r-- | tests/core/test_regex.out | 2 | ||||
-rw-r--r-- | tests/test_core.py | 41 |
3 files changed, 42 insertions, 38 deletions
diff --git a/tests/core/test_regex.in b/tests/core/test_regex.in new file mode 100644 index 00000000..a7ceb7a3 --- /dev/null +++ b/tests/core/test_regex.in @@ -0,0 +1,37 @@ +// This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm + #include <regex.h> + #include <stdio.h> + #include <stdlib.h> + + int main(void) + { + regex_t preg; + const char *string = "a very simple simple simple string"; + const char *pattern = "\\(sim[a-z]le\\) \\1"; + int rc; + size_t nmatch = 2; + regmatch_t pmatch[2]; + + if (0 != (rc = regcomp(&preg, pattern, 0))) { + printf("regcomp() failed, returning nonzero (%d)\n", rc); + exit(EXIT_FAILURE); + } + + if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { + printf("Failed to match '%s' with '%s',returning %d.\n", + string, pattern, rc); + } + else { + printf("With the whole expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], + pmatch[0].rm_so, pmatch[0].rm_eo - 1); + printf("With the sub-expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], + pmatch[1].rm_so, pmatch[1].rm_eo - 1); + } + regfree(&preg); + return 0; + } + diff --git a/tests/core/test_regex.out b/tests/core/test_regex.out new file mode 100644 index 00000000..f238d2e3 --- /dev/null +++ b/tests/core/test_regex.out @@ -0,0 +1,2 @@ +With the whole expression, a matched substring "simple simple" is found at position 7 to 19. +With the sub-expression, a matched substring "simple" is found at position 7 to 12.
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index 02d4cb6b..befd66ba 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1078,47 +1078,12 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_regex(self): - # This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm if self.emcc_args is None: return self.skip('needs emcc for libcextra') - src = r''' - #include <regex.h> - #include <stdio.h> - #include <stdlib.h> - int main(void) - { - regex_t preg; - const char *string = "a very simple simple simple string"; - const char *pattern = "\\(sim[a-z]le\\) \\1"; - int rc; - size_t nmatch = 2; - regmatch_t pmatch[2]; - - if (0 != (rc = regcomp(&preg, pattern, 0))) { - printf("regcomp() failed, returning nonzero (%d)\n", rc); - exit(EXIT_FAILURE); - } + test_path = path_from_root('tests', 'core', 'test_regex') + src, output = (test_path + s for s in ('.in', '.out')) - if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { - printf("Failed to match '%s' with '%s',returning %d.\n", - string, pattern, rc); - } - else { - printf("With the whole expression, " - "a matched substring \"%.*s\" is found at position %d to %d.\n", - pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], - pmatch[0].rm_so, pmatch[0].rm_eo - 1); - printf("With the sub-expression, " - "a matched substring \"%.*s\" is found at position %d to %d.\n", - pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], - pmatch[1].rm_so, pmatch[1].rm_eo - 1); - } - regfree(&preg); - return 0; - } - ''' - self.do_run(src, 'With the whole expression, a matched substring "simple simple" is found at position 7 to 19.\n' - 'With the sub-expression, a matched substring "simple" is found at position 7 to 12.') + self.do_run_from_file(src, output) def test_longjmp(self): src = r''' |