mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 23:59:59 -05:00
43c6c1a9f5
* use subclass of unittest.TestCase for all test cases * allow to run single test file (eg. python tools/integration_tests.py) * test filtering (via --pattern/-p CLI flag) * use common CLI parser for all tests: usage: test.py [-h] [--failfast] [--verbose] [--executable EXECUTABLE] [--release] [--pattern PATTERN] [--build-dir BUILD_DIR] optional arguments: -h, --help show this help message and exit --failfast, -f Stop on first failure --verbose, -v Verbose output --executable EXECUTABLE Use external executable of Deno --release Test against release executable --pattern PATTERN, -p PATTERN Run tests that match provided pattern --build-dir BUILD_DIR Deno build directory * respect NO_COLOR variable
144 lines
4.8 KiB
Python
Executable file
144 lines
4.8 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import os
|
|
import unittest
|
|
|
|
from test_util import DenoTestCase, run_tests
|
|
from util import tty_capture
|
|
|
|
PERMISSIONS_PROMPT_TEST_TS = "tools/permission_prompt_test.ts"
|
|
|
|
PROMPT_PATTERN = b'⚠️'
|
|
FIRST_CHECK_FAILED_PATTERN = b'First check failed'
|
|
PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'
|
|
|
|
|
|
@unittest.skipIf(os.name == 'nt', "Unable to test tty on Windows")
|
|
class BasePromptTest(object):
|
|
def _run_deno(self, flags, args, bytes_input):
|
|
"Returns (return_code, stdout, stderr)."
|
|
cmd = [self.deno_exe, "run"] + flags + [PERMISSIONS_PROMPT_TEST_TS
|
|
] + args
|
|
return tty_capture(cmd, bytes_input)
|
|
|
|
def test_allow_flag(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
["--allow-" + test_type], ["needs" + test_type.capitalize()], b'')
|
|
assert code == 0
|
|
assert not PROMPT_PATTERN in stderr
|
|
assert not FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert not PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_yes_yes(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'y\ny\n')
|
|
assert code == 0
|
|
assert PROMPT_PATTERN in stderr
|
|
assert not FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert not PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_yes_no(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'y\nn\n')
|
|
assert code == 1
|
|
assert PROMPT_PATTERN in stderr
|
|
assert not FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_no_no(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'n\nn\n')
|
|
assert code == 1
|
|
assert PROMPT_PATTERN in stderr
|
|
assert FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_no_yes(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'n\ny\n')
|
|
assert code == 0
|
|
|
|
assert PROMPT_PATTERN in stderr
|
|
assert FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert not PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_allow(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'a\n')
|
|
assert code == 0
|
|
assert PROMPT_PATTERN in stderr
|
|
assert not FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert not PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_deny(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'd\n')
|
|
assert code == 1
|
|
assert PROMPT_PATTERN in stderr
|
|
assert FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_unrecognized_option(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
[], ["needs" + test_type.capitalize()], b'e\na\n')
|
|
assert code == 0
|
|
assert PROMPT_PATTERN in stderr
|
|
assert not FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert not PERMISSION_DENIED_PATTERN in stderr
|
|
assert b'Unrecognized option' in stderr
|
|
|
|
def test_no_prompt(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
["--no-prompt"], ["needs" + test_type.capitalize()], b'')
|
|
assert code == 1
|
|
assert not PROMPT_PATTERN in stderr
|
|
assert FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
def test_no_prompt_allow(self):
|
|
test_type = self.test_type
|
|
code, stdout, stderr = self._run_deno(
|
|
["--no-prompt", "--allow-" + test_type],
|
|
["needs" + test_type.capitalize()], b'')
|
|
assert code == 0
|
|
assert not PROMPT_PATTERN in stderr
|
|
assert not FIRST_CHECK_FAILED_PATTERN in stdout
|
|
assert not PERMISSION_DENIED_PATTERN in stderr
|
|
|
|
|
|
class ReadPromptTest(DenoTestCase, BasePromptTest):
|
|
test_type = "read"
|
|
|
|
|
|
class WritePromptTest(DenoTestCase, BasePromptTest):
|
|
test_type = "write"
|
|
|
|
|
|
class EnvPromptTest(DenoTestCase, BasePromptTest):
|
|
test_type = "env"
|
|
|
|
|
|
class NetPromptTest(DenoTestCase, BasePromptTest):
|
|
test_type = "net"
|
|
|
|
|
|
class RunPromptTest(DenoTestCase, BasePromptTest):
|
|
test_type = "run"
|
|
|
|
|
|
def permission_prompt_tests():
|
|
return BasePromptTest.__subclasses__()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_tests()
|