diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-04 20:44:29 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-04 20:44:29 -0800 |
commit | 08e7619a88c246baf022a9cfdeafc21db068b9d0 (patch) | |
tree | 674bd9c6f3b262d4454b34a16ab7aabf508e648d | |
parent | 51fbd38572cb1cd01950c038e7d7ab9fed8cac2a (diff) |
sanity check for compiler engine in test runner
-rw-r--r-- | src/compiler.js | 2 | ||||
-rw-r--r-- | tests/hello_world.js | 73 | ||||
-rw-r--r-- | tests/runner.py | 14 |
3 files changed, 87 insertions, 2 deletions
diff --git a/src/compiler.js b/src/compiler.js index 90f05cf0..94085c3f 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -8,7 +8,7 @@ try { } catch(e) {} -// The environment setup code appears both here and in shell.js, because it can't be shared. Keep them in sync! +// The environment setup code appears here, in shell.js, and in tests/hello_world.js because it can't be shared. Keep them in sync! // *** Environment setup code *** var arguments_ = []; diff --git a/tests/hello_world.js b/tests/hello_world.js new file mode 100644 index 00000000..3fd19d53 --- /dev/null +++ b/tests/hello_world.js @@ -0,0 +1,73 @@ +// *** Environment setup code *** +var arguments_ = []; + +var ENVIRONMENT_IS_NODE = typeof process === 'object'; +var ENVIRONMENT_IS_WEB = typeof window === 'object'; +var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE; + +if (ENVIRONMENT_IS_NODE) { + // Expose functionality in the same simple way that the shells work + print = function(x) { + process['stdout'].write(x + '\n'); + }; + printErr = function(x) { + process['stderr'].write(x + '\n'); + }; + + var nodeFS = require('fs'); + + read = function(filename) { + var ret = nodeFS['readFileSync'](filename).toString(); + if (!ret && filename[0] != '/') { + filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + ret = nodeFS['readFileSync'](filename).toString(); + } + return ret; + }; + + arguments_ = process['argv'].slice(2); + +} else if (ENVIRONMENT_IS_SHELL) { + // Polyfill over SpiderMonkey/V8 differences + if (!this['read']) { + read = function(f) { snarf(f) }; + } + + if (!this['arguments']) { + arguments_ = scriptArgs; + } else { + arguments_ = arguments; + } + +} else if (ENVIRONMENT_IS_WEB) { + printErr = function(x) { + console.log(x); + }; + + read = function(url) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, false); + xhr.send(null); + return xhr.responseText; + }; + + if (this['arguments']) { + arguments_ = arguments; + } +} else { + throw 'Unknown runtime environment. Where are we?'; +} + +function globalEval(x) { + eval.call(null, x); +} + +if (!this['load']) { + load = function(f) { + globalEval(read(f)); + }; +} +// *** Environment setup code *** + +print('hello, world!'); + diff --git a/tests/runner.py b/tests/runner.py index f1357012..828e5b8e 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -4990,9 +4990,21 @@ else: if __name__ == '__main__': sys.argv = [sys.argv[0]] + ['-v'] + sys.argv[1:] # Verbose output by default - # TODO: check for js engines ([] or out of []) + + # Sanity checks + + try: + check = run_js(COMPILER_ENGINE, path_from_root('tests', 'hello_world.js')) + except Exception, e: + check = str(e) + if check != 'hello, world!\n': + print 'WARNING: The JavaScript shell used for compiling (%s) does not seem to work. Check ~/.emscripten. Output:\n---\n\n%s\n\n---\n' % (str(COMPILER_ENGINE), check) + for cmd in [CLANG, LLVM_DIS]: if not os.path.exists(cmd) and not os.path.exists(cmd + '.exe'): # .exe extension required for Windows print 'WARNING: Cannot find', cmd + + # Go + unittest.main() |