aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-02-03 18:51:29 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-02-03 18:51:29 -0800
commit42a910da1fab3bb5d793e5ca3d9ede9244781255 (patch)
treeee1e1a4d3a9ef57c13746b32641605e858daad3c /tests
parent0e2d5b6ed1e97e3c8ab07b53d9e5534c10f294af (diff)
parentd779fe7e6ad05ef1a9ba70d3f160c4f87878d997 (diff)
Merge pull request #825 from juj/std
Std
Diffstat (limited to 'tests')
-rw-r--r--tests/hello_cxx03.cpp10
-rw-r--r--tests/hello_cxx11.cpp10
-rwxr-xr-xtests/runner.py38
3 files changed, 56 insertions, 2 deletions
diff --git a/tests/hello_cxx03.cpp b/tests/hello_cxx03.cpp
new file mode 100644
index 00000000..d6cc766a
--- /dev/null
+++ b/tests/hello_cxx03.cpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+#if __cplusplus != 199711L
+#error By default, if no -std is specified, emscripten should be compiling with -std=c++03!
+#endif
+
+int main( int argc, const char *argv[] ) {
+ printf("Hello world!\\n");
+ return 0;
+}
diff --git a/tests/hello_cxx11.cpp b/tests/hello_cxx11.cpp
new file mode 100644
index 00000000..cfce039a
--- /dev/null
+++ b/tests/hello_cxx11.cpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+#if __cplusplus != 201103L
+#error This file should be compiled with -std=c++11!
+#endif
+
+int main( int argc, const char *argv[] ) {
+ printf("Hello world!\\n");
+ return 0;
+}
diff --git a/tests/runner.py b/tests/runner.py
index ce04ab39..66936e5a 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -238,7 +238,10 @@ process(sys.argv[1])
os.remove(f + '.o')
except:
pass
- args = [Building.COMPILER, '-emit-llvm'] + COMPILER_OPTS + Building.COMPILER_TEST_OPTS + \
+ compiler_flags = ['-emit-llvm']
+ if not f.endswith('.c'):
+ compiler_flags = compiler_flags + ['-std=c++03']
+ args = [Building.COMPILER] + compiler_flags + COMPILER_OPTS + Building.COMPILER_TEST_OPTS + \
['-I', dirname, '-I', os.path.join(dirname, 'include')] + \
map(lambda include: '-I' + include, includes) + \
['-c', f, '-o', f + '.o']
@@ -3494,7 +3497,7 @@ def process(filename):
case 'b':
case 'c':
return p-1;
- case 0xfffffff1:
+ case -15:
return p+1;
}
return p;
@@ -3509,6 +3512,25 @@ def process(filename):
'''
self.do_run(src, '*96,97,98,-14,-14,101*')
+ # By default, when user has not specified a -std flag, Emscripten should always build .cpp files using the C++03 standard,
+ # i.e. as if "-std=c++03" had been passed on the command line. On Linux with Clang 3.2 this is the case, but on Windows
+ # with Clang 3.2 -std=c++11 has been chosen as default, because of
+ # < jrose> clb: it's deliberate, with the idea that for people who don't care about the standard, they should be using the "best" thing we can offer on that platform
+ def test_cxx03_do_run(self):
+ src = '''
+ #include <stdio.h>
+
+ #if __cplusplus != 199711L
+ #error By default, if no -std is specified, emscripten should be compiling with -std=c++03!
+ #endif
+
+ int main( int argc, const char *argv[] ) {
+ printf("Hello world!\\n");
+ return 0;
+ }
+ '''
+ self.do_run(src, 'Hello world!')
+
def test_bigswitch(self):
if Settings.RELOOP: return self.skip('TODO: switch in relooper, issue #781')
@@ -8425,6 +8447,18 @@ f.close()
assert process.returncode is not 0, 'Trying to compile a nonexisting file should return with a nonzero error code!'
assert os.path.exists('this_output_file_should_never_exist.js') == False, 'Emcc should not produce an output file when build fails!'
+ def test_cxx03(self):
+ for compiler in [EMCC, EMXX]:
+ process = Popen([PYTHON, compiler, path_from_root('tests', 'hello_cxx03.cpp')], stdout=PIPE, stderr=PIPE)
+ process.communicate()
+ assert process.returncode is 0, 'By default, emscripten should build using -std=c++03!'
+
+ def test_cxx11(self):
+ for compiler in [EMCC, EMXX]:
+ process = Popen([PYTHON, compiler, '-std=c++11', path_from_root('tests', 'hello_cxx11.cpp')], stdout=PIPE, stderr=PIPE)
+ process.communicate()
+ assert process.returncode is 0, 'User should be able to specify custom -std= on the command line!'
+
def test_Os(self):
for opt in ['s', '0']:
output = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-O' + opt], stdout=PIPE, stderr=PIPE).communicate()