MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / run_js

Function run_js

test/jsrun.py:86–127  ·  view source on GitHub ↗

Execute javascript code generated by tests, with possible timeout.

(filename, engine, args=None,
           stdin=None, stdout=PIPE, stderr=None, cwd=None, input=None,
           full_output=False, assert_returncode=0, skip_check=False,
           timeout=DEFAULT_TIMEOUT)

Source from the content-addressed store, hash-verified

84
85
86def run_js(filename, engine, args=None,
87 stdin=None, stdout=PIPE, stderr=None, cwd=None, input=None,
88 full_output=False, assert_returncode=0, skip_check=False,
89 timeout=DEFAULT_TIMEOUT):
90 """Execute javascript code generated by tests, with possible timeout."""
91 # We used to support True here but we no longer do. Assert here just in case.
92 assert type(assert_returncode) is int
93
94 if not os.path.exists(filename):
95 raise Exception('output file not found: ' + filename)
96
97 command = make_command(os.path.abspath(filename), engine, args)
98 if common.EMTEST_VERBOSE:
99 print(f"Running: '{shlex.join(command)}'")
100 try:
101 proc = subprocess.run(
102 command,
103 stdin=stdin,
104 stdout=stdout,
105 stderr=stderr,
106 input=input,
107 cwd=cwd,
108 timeout=timeout,
109 text=True)
110 except Exception:
111 # the failure may be because the engine is not present. show the proper
112 # error in that case
113 if not skip_check:
114 require_engine(engine)
115 # if we got here, then require_engine succeeded, so we can raise the original error
116 raise
117
118 out = ['' if o is None else o for o in (proc.stdout, proc.stderr)]
119 ret = '\n'.join(out) if full_output else out[0]
120
121 if assert_returncode == common.NON_ZERO:
122 if proc.returncode == 0:
123 raise CalledProcessError(proc.returncode, ' '.join(command), str(ret))
124 elif proc.returncode != assert_returncode:
125 raise CalledProcessError(proc.returncode, ' '.join(command), str(ret))
126
127 return ret

Callers 1

check_engineFunction · 0.85

Calls 7

make_commandFunction · 0.85
require_engineFunction · 0.85
existsMethod · 0.80
typeEnum · 0.50
printFunction · 0.50
joinMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected