def test_js_engine_path(self): # Test that running JS commands works for node, d8, and jsc and is not path dependent restore_and_set_up() sample_script = path_from_root('tests', 'print_args.js') # Fake some JS engines # Note that the path contains 'd8'. test_path = self.in_dir('fake', 'abcd8765') ensure_dir(test_path) jsengines = [('d8', config.V8_ENGINE), ('d8_g', config.V8_ENGINE), ('js', config.SPIDERMONKEY_ENGINE), ('node', config.NODE_JS), ('nodejs', config.NODE_JS)] for filename, engine in jsengines: try_delete(SANITY_FILE) if type(engine) is list: engine = engine[0] if not engine: print('WARNING: Not testing engine %s, not configured.' % (filename)) continue print(filename, engine) test_engine_path = os.path.join(test_path, filename) with open(test_engine_path, 'w') as f: f.write('#!/bin/sh\n') f.write('exec %s $@\n' % (engine)) make_executable(test_engine_path) out = self.run_js(sample_script, engine=test_engine_path, args=['--foo']) self.assertEqual('0: --foo', out.strip())
def make_fake_wasm_opt(filename, version): print('make_fake_wasm_opt: %s' % filename) ensure_dir(os.path.dirname(filename)) with open(filename, 'w') as f: f.write('#!/bin/sh\n') f.write('echo "wasm-opt version %s"\n' % version) f.write('echo "..."\n') make_executable(filename)
def make_fake_llc(filename, targets): """Create a fake llc that only handles --version and writes target list to stdout. """ print('make_fake_llc: %s' % filename) ensure_dir(os.path.dirname(filename)) with open(filename, 'w') as f: f.write('#!/bin/sh\n') f.write('echo "llc fake output\nRegistered Targets:\n%s"' % targets) make_executable(filename)
def make_fake_tool(filename, version, report_name=None): if not report_name: report_name = os.path.basename(filename) print('make_fake_tool: %s' % filename) ensure_dir(os.path.dirname(filename)) with open(filename, 'w') as f: f.write('#!/bin/sh\n') f.write('echo "%s version %s"\n' % (report_name, version)) f.write('echo "..."\n') f.write('exit 0\n') make_executable(filename)
def make_fake_clang(filename, version): """Create a fake clang that only handles --version --version writes to stdout (unlike -v which writes to stderr) """ print('make_fake_clang: %s' % filename) ensure_dir(os.path.dirname(filename)) with open(filename, 'w') as f: f.write('#!/bin/sh\n') f.write('echo "clang version %s"\n' % version) f.write('echo "..."\n') shutil.copyfile(filename, filename + '++') make_executable(filename) make_executable(filename + '++')
def test_node(self): NODE_WARNING = 'node version appears too old' NODE_WARNING_2 = 'cannot check node version' restore_and_set_up() # Clang should report the version number we expect, and emcc should not warn assert shared.check_node_version() output = self.check_working(EMCC) self.assertNotContained(NODE_WARNING, output) # Fake a different node version restore_and_set_up() with open(config_file, 'a') as f: f.write('NODE_JS = "' + self.in_dir('fake', 'nodejs') + '"') ensure_dir('fake') for version, succeed in [('v0.8.0', False), ('v4.1.0', False), ('v4.1.1', True), ('v4.2.3-pre', True), ('cheez', False)]: print(version, succeed) try_delete(SANITY_FILE) f = open(self.in_dir('fake', 'nodejs'), 'w') f.write('#!/bin/sh\n') f.write('''if [ $1 = "--version" ]; then echo "%s" else %s $@ fi ''' % (version, ' '.join(config.NODE_JS))) f.close() make_executable(self.in_dir('fake', 'nodejs')) if not succeed: if version[0] == 'v': self.check_working(EMCC, NODE_WARNING) else: self.check_working(EMCC, NODE_WARNING_2) else: output = self.check_working(EMCC) self.assertNotContained(NODE_WARNING, output)
def make_new_executable(name): open(os.path.join(temp_bin, name), 'w').close() make_executable(os.path.join(temp_bin, name))
def make_fake_lld(filename): print('make_fake_lld: %s' % filename) with open(filename, 'w') as f: f.write('#!/bin/sh\n') f.write('exit 0\n') make_executable(filename)