aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/fnmatch.c79
-rw-r--r--tests/core/fnmatch.out23
-rw-r--r--tests/core/test_alloca.in13
-rw-r--r--tests/test_core.py9
-rw-r--r--tests/test_other.py20
5 files changed, 137 insertions, 7 deletions
diff --git a/tests/core/fnmatch.c b/tests/core/fnmatch.c
new file mode 100644
index 00000000..ebdb2009
--- /dev/null
+++ b/tests/core/fnmatch.c
@@ -0,0 +1,79 @@
+// Begin test_fnmatch.cpp
+#include <fnmatch.h>
+#include <iostream>
+#include <vector>
+#include <string>
+
+using namespace std;
+
+class TestCase {
+public:
+ TestCase(const string& pattern, const string& testString, int flags, int expected) :
+ pattern(pattern),
+ testString(testString),
+ flags(flags),
+ expected(expected)
+ {}
+ string pattern;
+ string testString;
+ int flags;
+ int expected;
+};
+
+int main()
+{
+ vector<TestCase> testCases;
+
+ testCases.push_back(TestCase("*","anything",0,0));
+ testCases.push_back(TestCase("*.txt","readme.txt",0,0));
+ testCases.push_back(TestCase("*.txt","readme.info",0,FNM_NOMATCH));
+ testCases.push_back(TestCase("*.t?t","readme.txt",0,0));
+ testCases.push_back(TestCase("*.t?t","readme.tot",0,0));
+ testCases.push_back(TestCase("*.t?t","readme.txxt",0,FNM_NOMATCH));
+ testCases.push_back(TestCase("[a-g]1","c1",0,0));
+ testCases.push_back(TestCase("[a-g]1","i1",0,FNM_NOMATCH));
+ testCases.push_back(TestCase("[!a-g]1","i1",0,0));
+ testCases.push_back(TestCase("a\\*","anything",0,FNM_NOMATCH));
+ testCases.push_back(TestCase("a\\*","a*",0,0));
+ testCases.push_back(TestCase("a\\*","a*",FNM_NOESCAPE,FNM_NOMATCH));
+ testCases.push_back(TestCase("a\\*","a\\*",FNM_NOESCAPE,0));
+ testCases.push_back(TestCase("*readme","/etc/readme",0,0));
+ testCases.push_back(TestCase("*readme","/etc/readme",FNM_PATHNAME,FNM_NOMATCH));
+ testCases.push_back(TestCase("/*/readme","/etc/readme",FNM_PATHNAME,0));
+ testCases.push_back(TestCase("*readme","/etc/.readme",0,0));
+ testCases.push_back(TestCase("*readme",".readme",FNM_PERIOD,FNM_NOMATCH));
+ testCases.push_back(TestCase("*.readme","/etc/.readme",FNM_PERIOD,0));
+ testCases.push_back(TestCase("*.readme","/etc/.readme",FNM_PERIOD|FNM_PATHNAME,FNM_NOMATCH));
+ testCases.push_back(TestCase("/*/.readme","/etc/.readme",FNM_PERIOD|FNM_PATHNAME,0));
+ testCases.push_back(TestCase("ReAdME","readme",0,FNM_NOMATCH));
+
+ bool pass = true;
+
+ for (vector<TestCase>::const_iterator it = testCases.begin(); it != testCases.end(); ++it)
+ {
+ int result = fnmatch(it->pattern.c_str(), it->testString.c_str(), it->flags);
+ if (result == it->expected)
+ cout << "Pass: ";
+ else
+ {
+ cout << "Fail: ";
+ pass = false;
+ }
+
+ cout << "fnmatch(" << it->pattern << ", " << it->testString << ", "
+ << it->flags << ") returned " << result << ", expected "
+ << it->expected << endl;
+ }
+
+ if (pass)
+ {
+ cout << "All tests passed." << endl;
+ return 0;
+ }
+ else
+ {
+ cout << "Some tests failed." << endl;
+ return 1;
+ }
+}
+
diff --git a/tests/core/fnmatch.out b/tests/core/fnmatch.out
new file mode 100644
index 00000000..303f7449
--- /dev/null
+++ b/tests/core/fnmatch.out
@@ -0,0 +1,23 @@
+Pass: fnmatch(*, anything, 0) returned 0, expected 0
+Pass: fnmatch(*.txt, readme.txt, 0) returned 0, expected 0
+Pass: fnmatch(*.txt, readme.info, 0) returned 1, expected 1
+Pass: fnmatch(*.t?t, readme.txt, 0) returned 0, expected 0
+Pass: fnmatch(*.t?t, readme.tot, 0) returned 0, expected 0
+Pass: fnmatch(*.t?t, readme.txxt, 0) returned 1, expected 1
+Pass: fnmatch([a-g]1, c1, 0) returned 0, expected 0
+Pass: fnmatch([a-g]1, i1, 0) returned 1, expected 1
+Pass: fnmatch([!a-g]1, i1, 0) returned 0, expected 0
+Pass: fnmatch(a\*, anything, 0) returned 1, expected 1
+Pass: fnmatch(a\*, a*, 0) returned 0, expected 0
+Pass: fnmatch(a\*, a*, 2) returned 1, expected 1
+Pass: fnmatch(a\*, a\*, 2) returned 0, expected 0
+Pass: fnmatch(*readme, /etc/readme, 0) returned 0, expected 0
+Pass: fnmatch(*readme, /etc/readme, 1) returned 1, expected 1
+Pass: fnmatch(/*/readme, /etc/readme, 1) returned 0, expected 0
+Pass: fnmatch(*readme, /etc/.readme, 0) returned 0, expected 0
+Pass: fnmatch(*readme, .readme, 4) returned 1, expected 1
+Pass: fnmatch(*.readme, /etc/.readme, 4) returned 0, expected 0
+Pass: fnmatch(*.readme, /etc/.readme, 5) returned 1, expected 1
+Pass: fnmatch(/*/.readme, /etc/.readme, 5) returned 0, expected 0
+Pass: fnmatch(ReAdME, readme, 0) returned 1, expected 1
+All tests passed.
diff --git a/tests/core/test_alloca.in b/tests/core/test_alloca.in
index bfad3324..d115880f 100644
--- a/tests/core/test_alloca.in
+++ b/tests/core/test_alloca.in
@@ -1,9 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
-int main() {
- char *pc;
- pc = (char *)alloca(5);
- printf("z:%d*%d*\n", pc > 0, (int)pc);
+int main(int argc, char **argv) {
+ char *pc, *pc2;
+ assert(argc == 1);
+ pc = (char *)alloca(4+argc);
+ assert(((int)pc) % 4 == 0);
+ pc2 = (char *)alloca(4+argc);
+ assert(((int)pc2) % 4 == 0);
+ printf("z:%d*%d*%d*\n", pc > 0, (int)pc, (int)pc2);
return 0;
}
diff --git a/tests/test_core.py b/tests/test_core.py
index 458e04fb..a884ea75 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1486,7 +1486,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
def test_segfault(self):
if self.emcc_args is None: return self.skip('SAFE_HEAP without ta2 means we check types too, which hide segfaults')
- if Settings.ASM_JS: return self.skip('asm does not support safe heap')
+ if os.environ.get('EMCC_FAST_COMPILER') == '1' and '-O2' not in self.emcc_args: return self.skip('todo in non-jsopts-enabled fastcomp')
Settings.SAFE_HEAP = 1
@@ -1606,6 +1606,8 @@ 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_alloca(self):
+ if Settings.USE_TYPED_ARRAYS != 2: return self.skip('non-ta2 may have unaligned allocas')
+
test_path = path_from_root('tests', 'core', 'test_alloca')
src, output = (test_path + s for s in ('.in', '.out'))
@@ -3703,6 +3705,11 @@ ok
self.do_run_from_file(src, output)
+ def test_fnmatch(self):
+ test_path = path_from_root('tests', 'core', 'fnmatch')
+ src, output = (test_path + s for s in ('.c', '.out'))
+ self.do_run_from_file(src, output)
+
def test_sscanf(self):
if self.emcc_args is None: return self.skip('needs emcc for libc')
if not self.is_le32(): return self.skip('le32 needed for accurate math')
diff --git a/tests/test_other.py b/tests/test_other.py
index 00c42418..b2fc4cf6 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -1721,7 +1721,7 @@ f.close()
(path_from_root('tools', 'test-js-optimizer-asm-regs.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-output.js')).read(),
['asm', 'registerize']),
(path_from_root('tools', 'test-js-optimizer-asm-regs-min.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-min-output.js')).read(),
- ['asm', 'registerize']),
+ ['asm', 'registerize', 'minifyLocals']),
(path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(),
['asm', 'simplifyExpressions']),
(path_from_root('tools', 'test-js-optimizer-asm-last.js'), open(path_from_root('tools', 'test-js-optimizer-asm-last-output.js')).read(),
@@ -2221,7 +2221,6 @@ mergeInto(LibraryManager.library, {
process.communicate()
assert(os.path.isfile(outdir + 'hello_world.obj'))
-
def test_doublestart_bug(self):
open('code.cpp', 'w').write(r'''
#include <stdio.h>
@@ -2253,3 +2252,20 @@ Module["preRun"].push(function () {
assert output.count('This should only appear once.') == 1, '\n'+output
+ def test_module_print(self):
+ open('code.cpp', 'w').write(r'''
+#include <stdio.h>
+int main(void) {
+ printf("123456789\n");
+ return 0;
+}
+''')
+
+ open('pre.js', 'w').write(r'''
+var Module = { print: function(x) { throw '<{(' + x + ')}>' } };
+''')
+
+ Popen([PYTHON, EMCC, 'code.cpp', '--pre-js', 'pre.js']).communicate()
+ output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
+ assert r'<{(123456789)}>' in output, output
+