summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-06 23:12:25 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:35:52 +0200
commit63646b8d11d323c4fe575058135c8c63b814b007 (patch)
tree24c9416d49d426f66870af2966004cd72acd13d0
parent5fb26f6d5aac562cc875720ca4d1ab9c1acd6a2a (diff)
Use do_run_from_file() for test_strings
-rw-r--r--tests/core/test_strings.in53
-rw-r--r--tests/core/test_strings.out13
-rw-r--r--tests/test_core.py60
3 files changed, 71 insertions, 55 deletions
diff --git a/tests/core/test_strings.in b/tests/core/test_strings.in
new file mode 100644
index 00000000..6c7e2366
--- /dev/null
+++ b/tests/core/test_strings.in
@@ -0,0 +1,53 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ int main(int argc, char **argv)
+ {
+ int x = 5, y = 9, magic = 7; // fool compiler with magic
+ memmove(&x, &y, magic-7); // 0 should not crash us
+
+ int xx, yy, zz;
+ char s[32];
+ int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s);
+ printf("%d:%d,%d,%d,%s\n", cc, xx, yy, zz, s);
+
+ printf("%d\n", argc);
+ puts(argv[1]);
+ puts(argv[2]);
+ printf("%d\n", atoi(argv[3])+2);
+ const char *foolingthecompiler = "\rabcd";
+ printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D!
+ printf("%s\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
+ printf("/* a comment */\n"); // Should not break the generated code!
+ printf("// another\n"); // Should not break the generated code!
+
+ char* strdup_val = strdup("test");
+ printf("%s\n", strdup_val);
+ free(strdup_val);
+
+ {
+ char *one = "one 1 ONE !";
+ char *two = "two 2 TWO ?";
+ char three[1024];
+ memset(three, '.', 1024);
+ three[50] = 0;
+ strncpy(three + argc, one + (argc/2), argc+1);
+ strncpy(three + argc*3, two + (argc/3), argc+2);
+ printf("waka %s\n", three);
+ }
+
+ {
+ char *one = "string number one top notch";
+ char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO";
+ char three[1000];
+ strcpy(three, &one[argc*2]);
+ char *four = strcat(three, &two[argc*3]);
+ printf("cat |%s|\n", three);
+ printf("returned |%s|\n", four);
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strings.out b/tests/core/test_strings.out
new file mode 100644
index 00000000..ddf9aee7
--- /dev/null
+++ b/tests/core/test_strings.out
@@ -0,0 +1,13 @@
+4:10,177,543,def
+4
+wowie
+too
+76
+5
+(null)
+/* a comment */
+// another
+test
+waka ....e 1 O...wo 2 T................................
+cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
+returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO| \ No newline at end of file
diff --git a/tests/test_core.py b/tests/test_core.py
index 36807381..e77ddbbf 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -920,65 +920,15 @@ 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_strings(self):
- src = '''
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- int main(int argc, char **argv)
- {
- int x = 5, y = 9, magic = 7; // fool compiler with magic
- memmove(&x, &y, magic-7); // 0 should not crash us
-
- int xx, yy, zz;
- char s[32];
- int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s);
- printf("%d:%d,%d,%d,%s\\n", cc, xx, yy, zz, s);
-
- printf("%d\\n", argc);
- puts(argv[1]);
- puts(argv[2]);
- printf("%d\\n", atoi(argv[3])+2);
- const char *foolingthecompiler = "\\rabcd";
- printf("%d\\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D!
- printf("%s\\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
- printf("/* a comment */\\n"); // Should not break the generated code!
- printf("// another\\n"); // Should not break the generated code!
-
- char* strdup_val = strdup("test");
- printf("%s\\n", strdup_val);
- free(strdup_val);
-
- {
- char *one = "one 1 ONE !";
- char *two = "two 2 TWO ?";
- char three[1024];
- memset(three, '.', 1024);
- three[50] = 0;
- strncpy(three + argc, one + (argc/2), argc+1);
- strncpy(three + argc*3, two + (argc/3), argc+2);
- printf("waka %s\\n", three);
- }
-
- {
- char *one = "string number one top notch";
- char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO";
- char three[1000];
- strcpy(three, &one[argc*2]);
- char *four = strcat(three, &two[argc*3]);
- printf("cat |%s|\\n", three);
- printf("returned |%s|\\n", four);
- }
+ test_path = path_from_root('tests', 'core', 'test_strings')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
for named in (0, 1):
print named
+
Settings.NAMED_GLOBALS = named
- self.do_run(src, '''4:10,177,543,def\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\nwaka ....e 1 O...wo 2 T................................
-cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
-returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|''', ['wowie', 'too', '74'])
+ self.do_run_from_file(src, output, ['wowie', 'too', '74'])
+
if self.emcc_args == []:
gen = open(self.in_dir('src.cpp.o.js')).read()
assert ('var __str1;' in gen) == named