mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
Add --allow-run test code (#1504)
This commit is contained in:
parent
6c9695a528
commit
37e3db00a2
2 changed files with 29 additions and 2 deletions
|
@ -51,7 +51,8 @@ class Prompt(object):
|
|||
bytes_input,
|
||||
allow_write=False,
|
||||
allow_net=False,
|
||||
allow_env=False):
|
||||
allow_env=False,
|
||||
allow_run=False):
|
||||
"Returns (return_code, stdout, stderr)."
|
||||
cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]
|
||||
if allow_write:
|
||||
|
@ -60,6 +61,8 @@ class Prompt(object):
|
|||
cmd.append("--allow-net")
|
||||
if allow_env:
|
||||
cmd.append("--allow-env")
|
||||
if allow_run:
|
||||
cmd.append("--allow-run")
|
||||
return tty_capture(cmd, bytes_input)
|
||||
|
||||
def warm_up(self):
|
||||
|
@ -120,6 +123,24 @@ class Prompt(object):
|
|||
assert b'PermissionDenied: permission denied' in stderr
|
||||
assert b'Deno requests network access' in stderr
|
||||
|
||||
def test_run_yes(self):
|
||||
code, stdout, stderr = self.run('needsRun', b'y\n')
|
||||
assert code == 0
|
||||
assert stdout == b'hello'
|
||||
assert b'Deno requests access to run' in stderr
|
||||
|
||||
def test_run_arg(self):
|
||||
code, stdout, stderr = self.run('needsRun', b'', allow_run=True)
|
||||
assert code == 0
|
||||
assert stdout == b'hello'
|
||||
assert stderr == b''
|
||||
|
||||
def test_run_no(self):
|
||||
code, _stdout, stderr = self.run('needsRun', b'N\n')
|
||||
assert code == 1
|
||||
assert b'PermissionDenied: permission denied' in stderr
|
||||
assert b'Deno requests access to run' in stderr
|
||||
|
||||
|
||||
def permission_prompt_test(deno_exe):
|
||||
p = Prompt(deno_exe)
|
||||
|
@ -133,6 +154,9 @@ def permission_prompt_test(deno_exe):
|
|||
p.test_net_yes()
|
||||
p.test_net_arg()
|
||||
p.test_net_no()
|
||||
p.test_run_yes()
|
||||
p.test_run_arg()
|
||||
p.test_run_no()
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { args, listen, env, exit, makeTempDirSync } from "deno";
|
||||
import { args, listen, env, exit, makeTempDirSync, run } from "deno";
|
||||
|
||||
const name = args[1];
|
||||
const test = {
|
||||
|
@ -10,6 +10,9 @@ const test = {
|
|||
},
|
||||
needsNet: () => {
|
||||
listen("tcp", "127.0.0.1:4540");
|
||||
},
|
||||
needsRun: () => {
|
||||
run({ args: ["python", "-c", "import sys; sys.stdout.write('hello')"] });
|
||||
}
|
||||
}[name];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue