mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
Remove TTY tests - dead code (#3229)
This commit is contained in:
parent
3c2399e437
commit
8f571ef166
11 changed files with 234 additions and 754 deletions
|
@ -111,7 +111,6 @@ test(function osPid(): void {
|
|||
assert(Deno.pid > 0);
|
||||
});
|
||||
|
||||
// See complete tests in tools/is_tty_test.py
|
||||
test(function osIsTTYSmoke(): void {
|
||||
console.log(Deno.isTTY());
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// TODO(ry) Make this file test-only. Somehow it's very difficult to export
|
||||
// methods to tests/integration_tests.rs and tests/tty_tests.rs if this
|
||||
// is enabled...
|
||||
// methods to tests/integration_tests.rs if this is enabled...
|
||||
// #![cfg(test)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
|
|
@ -2,42 +2,46 @@
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate tempfile;
|
||||
mod util;
|
||||
use util::*;
|
||||
|
||||
#[test]
|
||||
fn test_pattern_match() {
|
||||
assert!(util::pattern_match("foo[BAR]baz", "foobarbaz", "[BAR]"));
|
||||
assert!(!util::pattern_match("foo[BAR]baz", "foobazbar", "[BAR]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn benchmark_test() {
|
||||
run_python_script("tools/benchmark_test.py")
|
||||
util::run_python_script("tools/benchmark_test.py")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deno_dir_test() {
|
||||
let g = http_server();
|
||||
run_python_script("tools/deno_dir_test.py");
|
||||
let g = util::http_server();
|
||||
util::run_python_script("tools/deno_dir_test.py");
|
||||
drop(g);
|
||||
}
|
||||
|
||||
// TODO(#2933): Rewrite this test in rust.
|
||||
#[test]
|
||||
fn fetch_test() {
|
||||
let g = http_server();
|
||||
run_python_script("tools/fetch_test.py");
|
||||
let g = util::http_server();
|
||||
util::run_python_script("tools/fetch_test.py");
|
||||
drop(g);
|
||||
}
|
||||
|
||||
// TODO(#2933): Rewrite this test in rust.
|
||||
#[test]
|
||||
fn fmt_test() {
|
||||
let g = http_server();
|
||||
run_python_script("tools/fmt_test.py");
|
||||
let g = util::http_server();
|
||||
util::run_python_script("tools/fmt_test.py");
|
||||
drop(g);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn js_unit_tests() {
|
||||
let g = http_server();
|
||||
let mut deno = deno_cmd()
|
||||
.current_dir(root_path())
|
||||
let g = util::http_server();
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::root_path())
|
||||
.arg("run")
|
||||
.arg("--reload")
|
||||
.arg("--allow-run")
|
||||
|
@ -54,29 +58,29 @@ fn js_unit_tests() {
|
|||
// TODO(#2933): Rewrite this test in rust.
|
||||
#[test]
|
||||
fn repl_test() {
|
||||
run_python_script("tools/repl_test.py")
|
||||
util::run_python_script("tools/repl_test.py")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setup_test() {
|
||||
run_python_script("tools/setup_test.py")
|
||||
util::run_python_script("tools/setup_test.py")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn target_test() {
|
||||
run_python_script("tools/target_test.py")
|
||||
util::run_python_script("tools/target_test.py")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn util_test() {
|
||||
run_python_script("tools/util_test.py")
|
||||
util::run_python_script("tools/util_test.py")
|
||||
}
|
||||
|
||||
macro_rules! itest(
|
||||
($name:ident {$( $key:ident: $value:expr,)*}) => {
|
||||
#[test]
|
||||
fn $name() {
|
||||
(CheckOutputIntegrationTest {
|
||||
(util::CheckOutputIntegrationTest {
|
||||
$(
|
||||
$key: $value,
|
||||
)*
|
||||
|
@ -607,3 +611,215 @@ itest!(top_level_for_await_ts {
|
|||
args: "top_level_for_await.ts",
|
||||
output: "top_level_for_await.out",
|
||||
});
|
||||
|
||||
mod util {
|
||||
use deno_cli::colors::strip_ansi_codes;
|
||||
pub use deno_cli::test_util::*;
|
||||
use os_pipe::pipe;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use tempfile::TempDir;
|
||||
|
||||
lazy_static! {
|
||||
static ref DENO_DIR: TempDir = { TempDir::new().expect("tempdir fail") };
|
||||
}
|
||||
|
||||
pub fn deno_cmd() -> Command {
|
||||
let mut c = Command::new(deno_exe_path());
|
||||
c.env("DENO_DIR", DENO_DIR.path());
|
||||
c
|
||||
}
|
||||
|
||||
pub fn run_python_script(script: &str) {
|
||||
let output = Command::new("python")
|
||||
.env("DENO_DIR", DENO_DIR.path())
|
||||
.current_dir(root_path())
|
||||
.arg(script)
|
||||
.arg(format!("--executable={}", deno_exe_path().display()))
|
||||
.env("DENO_BUILD_PATH", target_dir())
|
||||
.output()
|
||||
.expect("failed to spawn script");
|
||||
if !output.status.success() {
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||
panic!(
|
||||
"{} executed with failing error code\n{}{}",
|
||||
script, stdout, stderr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CheckOutputIntegrationTest {
|
||||
pub args: &'static str,
|
||||
pub output: &'static str,
|
||||
pub input: Option<&'static str>,
|
||||
pub exit_code: i32,
|
||||
pub check_stderr: bool,
|
||||
pub http_server: bool,
|
||||
}
|
||||
|
||||
impl CheckOutputIntegrationTest {
|
||||
pub fn run(&self) {
|
||||
let args = self.args.split_whitespace();
|
||||
let root = root_path();
|
||||
let deno_exe = deno_exe_path();
|
||||
println!("root path {}", root.display());
|
||||
println!("deno_exe path {}", deno_exe.display());
|
||||
|
||||
let http_server_guard = if self.http_server {
|
||||
Some(http_server())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let (mut reader, writer) = pipe().unwrap();
|
||||
let tests_dir = root.join("cli").join("tests");
|
||||
let mut command = deno_cmd();
|
||||
command.args(args);
|
||||
command.current_dir(&tests_dir);
|
||||
command.stdin(Stdio::piped());
|
||||
command.stderr(Stdio::null());
|
||||
|
||||
if self.check_stderr {
|
||||
let writer_clone = writer.try_clone().unwrap();
|
||||
command.stderr(writer_clone);
|
||||
}
|
||||
|
||||
command.stdout(writer);
|
||||
|
||||
let mut process = command.spawn().expect("failed to execute process");
|
||||
|
||||
if let Some(input) = self.input {
|
||||
let mut p_stdin = process.stdin.take().unwrap();
|
||||
write!(p_stdin, "{}", input).unwrap();
|
||||
}
|
||||
|
||||
// Very important when using pipes: This parent process is still
|
||||
// holding its copies of the write ends, and we have to close them
|
||||
// before we read, otherwise the read end will never report EOF. The
|
||||
// Command object owns the writers now, and dropping it closes them.
|
||||
drop(command);
|
||||
|
||||
let mut actual = String::new();
|
||||
reader.read_to_string(&mut actual).unwrap();
|
||||
|
||||
let status = process.wait().expect("failed to finish process");
|
||||
let exit_code = status.code().unwrap();
|
||||
|
||||
drop(http_server_guard);
|
||||
|
||||
actual = strip_ansi_codes(&actual).to_string();
|
||||
|
||||
if self.exit_code != exit_code {
|
||||
println!("OUTPUT\n{}\nOUTPUT", actual);
|
||||
panic!(
|
||||
"bad exit code, expected: {:?}, actual: {:?}",
|
||||
self.exit_code, exit_code
|
||||
);
|
||||
}
|
||||
|
||||
let output_path = tests_dir.join(self.output);
|
||||
println!("output path {}", output_path.display());
|
||||
let expected =
|
||||
std::fs::read_to_string(output_path).expect("cannot read output");
|
||||
|
||||
if !wildcard_match(&expected, &actual) {
|
||||
println!("OUTPUT\n{}\nOUTPUT", actual);
|
||||
println!("EXPECTED\n{}\nEXPECTED", expected);
|
||||
panic!("pattern match failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn wildcard_match(pattern: &str, s: &str) -> bool {
|
||||
pattern_match(pattern, s, "[WILDCARD]")
|
||||
}
|
||||
|
||||
pub fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool {
|
||||
// Normalize line endings
|
||||
let s = s.replace("\r\n", "\n");
|
||||
let pattern = pattern.replace("\r\n", "\n");
|
||||
|
||||
if pattern == wildcard {
|
||||
return true;
|
||||
}
|
||||
|
||||
let parts = pattern.split(wildcard).collect::<Vec<&str>>();
|
||||
if parts.len() == 1 {
|
||||
return pattern == s;
|
||||
}
|
||||
|
||||
if !s.starts_with(parts[0]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut t = s.split_at(parts[0].len());
|
||||
|
||||
for (i, part) in parts.iter().enumerate() {
|
||||
if i == 0 {
|
||||
continue;
|
||||
}
|
||||
dbg!(part, i);
|
||||
if i == parts.len() - 1 && (*part == "" || *part == "\n") {
|
||||
dbg!("exit 1 true", i);
|
||||
return true;
|
||||
}
|
||||
if let Some(found) = t.1.find(*part) {
|
||||
dbg!("found ", found);
|
||||
t = t.1.split_at(found + part.len());
|
||||
} else {
|
||||
dbg!("exit false ", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
dbg!("end ", t.1.len());
|
||||
t.1.is_empty()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wildcard_match() {
|
||||
let fixtures = vec![
|
||||
("foobarbaz", "foobarbaz", true),
|
||||
("[WILDCARD]", "foobarbaz", true),
|
||||
("foobar", "foobarbaz", false),
|
||||
("foo[WILDCARD]baz", "foobarbaz", true),
|
||||
("foo[WILDCARD]baz", "foobazbar", false),
|
||||
("foo[WILDCARD]baz[WILDCARD]qux", "foobarbazqatqux", true),
|
||||
("foo[WILDCARD]", "foobar", true),
|
||||
("foo[WILDCARD]baz[WILDCARD]", "foobarbazqat", true),
|
||||
// check with different line endings
|
||||
("foo[WILDCARD]\nbaz[WILDCARD]\n", "foobar\nbazqat\n", true),
|
||||
(
|
||||
"foo[WILDCARD]\nbaz[WILDCARD]\n",
|
||||
"foobar\r\nbazqat\r\n",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"foo[WILDCARD]\r\nbaz[WILDCARD]\n",
|
||||
"foobar\nbazqat\r\n",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"foo[WILDCARD]\r\nbaz[WILDCARD]\r\n",
|
||||
"foobar\nbazqat\n",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"foo[WILDCARD]\r\nbaz[WILDCARD]\r\n",
|
||||
"foobar\r\nbazqat\r\n",
|
||||
true,
|
||||
),
|
||||
];
|
||||
|
||||
// Iterate through the fixture lists, testing each one
|
||||
for (pattern, string, expected) in fixtures {
|
||||
let actual = wildcard_match(pattern, string);
|
||||
dbg!(pattern, string, expected);
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
console.log(Deno.isTTY().stdin);
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate tempfile;
|
||||
mod util;
|
||||
use util::*;
|
||||
|
||||
// TODO(#2933): Rewrite these tests in rust.
|
||||
// TODO(ry) These tests can't run in parallel.
|
||||
#[test]
|
||||
fn tty_tests() {
|
||||
let g = http_server();
|
||||
// TODO(ry) Re-enable these flaky tests.
|
||||
// run_python_script("tools/complex_permissions_test.py");
|
||||
// run_python_script("tools/permission_prompt_test.py");
|
||||
// TODO(ry) is_tty_test is not passing on travis when run with "cargo test"
|
||||
// run_python_script("tools/is_tty_test.py");
|
||||
drop(g);
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
//! Test utilites shared between integration_tests.rs and tty_tests.rs
|
||||
use deno_cli::colors::strip_ansi_codes;
|
||||
pub use deno_cli::test_util::*;
|
||||
use os_pipe::pipe;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use tempfile::TempDir;
|
||||
|
||||
lazy_static! {
|
||||
static ref DENO_DIR: TempDir = { TempDir::new().expect("tempdir fail") };
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn deno_cmd() -> Command {
|
||||
let mut c = Command::new(deno_exe_path());
|
||||
c.env("DENO_DIR", DENO_DIR.path());
|
||||
c
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // tty_tests use this but are disabled.
|
||||
pub fn run_python_script(script: &str) {
|
||||
let output = Command::new("python")
|
||||
.env("DENO_DIR", DENO_DIR.path())
|
||||
.current_dir(root_path())
|
||||
.arg(script)
|
||||
.arg(format!("--executable={}", deno_exe_path().display()))
|
||||
.env("DENO_BUILD_PATH", target_dir())
|
||||
.output()
|
||||
.expect("failed to spawn script");
|
||||
if !output.status.success() {
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||
panic!(
|
||||
"{} executed with failing error code\n{}{}",
|
||||
script, stdout, stderr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CheckOutputIntegrationTest {
|
||||
pub args: &'static str,
|
||||
pub output: &'static str,
|
||||
pub input: Option<&'static str>,
|
||||
pub exit_code: i32,
|
||||
pub check_stderr: bool,
|
||||
pub http_server: bool,
|
||||
}
|
||||
|
||||
impl CheckOutputIntegrationTest {
|
||||
#[allow(dead_code)]
|
||||
pub fn run(&self) {
|
||||
let args = self.args.split_whitespace();
|
||||
let root = root_path();
|
||||
let deno_exe = deno_exe_path();
|
||||
println!("root path {}", root.display());
|
||||
println!("deno_exe path {}", deno_exe.display());
|
||||
|
||||
let http_server_guard = if self.http_server {
|
||||
Some(http_server())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let (mut reader, writer) = pipe().unwrap();
|
||||
let tests_dir = root.join("cli").join("tests");
|
||||
let mut command = deno_cmd();
|
||||
command.args(args);
|
||||
command.current_dir(&tests_dir);
|
||||
command.stdin(Stdio::piped());
|
||||
command.stderr(Stdio::null());
|
||||
|
||||
if self.check_stderr {
|
||||
let writer_clone = writer.try_clone().unwrap();
|
||||
command.stderr(writer_clone);
|
||||
}
|
||||
|
||||
command.stdout(writer);
|
||||
|
||||
let mut process = command.spawn().expect("failed to execute process");
|
||||
|
||||
if let Some(input) = self.input {
|
||||
let mut p_stdin = process.stdin.take().unwrap();
|
||||
write!(p_stdin, "{}", input).unwrap();
|
||||
}
|
||||
|
||||
// Very important when using pipes: This parent process is still
|
||||
// holding its copies of the write ends, and we have to close them
|
||||
// before we read, otherwise the read end will never report EOF. The
|
||||
// Command object owns the writers now, and dropping it closes them.
|
||||
drop(command);
|
||||
|
||||
let mut actual = String::new();
|
||||
reader.read_to_string(&mut actual).unwrap();
|
||||
|
||||
let status = process.wait().expect("failed to finish process");
|
||||
let exit_code = status.code().unwrap();
|
||||
|
||||
drop(http_server_guard);
|
||||
|
||||
actual = strip_ansi_codes(&actual).to_string();
|
||||
|
||||
if self.exit_code != exit_code {
|
||||
println!("OUTPUT\n{}\nOUTPUT", actual);
|
||||
panic!(
|
||||
"bad exit code, expected: {:?}, actual: {:?}",
|
||||
self.exit_code, exit_code
|
||||
);
|
||||
}
|
||||
|
||||
let output_path = tests_dir.join(self.output);
|
||||
println!("output path {}", output_path.display());
|
||||
let expected =
|
||||
std::fs::read_to_string(output_path).expect("cannot read output");
|
||||
|
||||
if !wildcard_match(&expected, &actual) {
|
||||
println!("OUTPUT\n{}\nOUTPUT", actual);
|
||||
println!("EXPECTED\n{}\nEXPECTED", expected);
|
||||
panic!("pattern match failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn wildcard_match(pattern: &str, s: &str) -> bool {
|
||||
pattern_match(pattern, s, "[WILDCARD]")
|
||||
}
|
||||
|
||||
fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool {
|
||||
// Normalize line endings
|
||||
let s = s.replace("\r\n", "\n");
|
||||
let pattern = pattern.replace("\r\n", "\n");
|
||||
|
||||
if pattern == wildcard {
|
||||
return true;
|
||||
}
|
||||
|
||||
let parts = pattern.split(wildcard).collect::<Vec<&str>>();
|
||||
if parts.len() == 1 {
|
||||
return pattern == s;
|
||||
}
|
||||
|
||||
if !s.starts_with(parts[0]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut t = s.split_at(parts[0].len());
|
||||
|
||||
for (i, part) in parts.iter().enumerate() {
|
||||
if i == 0 {
|
||||
continue;
|
||||
}
|
||||
dbg!(part, i);
|
||||
if i == parts.len() - 1 && (*part == "" || *part == "\n") {
|
||||
dbg!("exit 1 true", i);
|
||||
return true;
|
||||
}
|
||||
if let Some(found) = t.1.find(*part) {
|
||||
dbg!("found ", found);
|
||||
t = t.1.split_at(found + part.len());
|
||||
} else {
|
||||
dbg!("exit false ", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
dbg!("end ", t.1.len());
|
||||
t.1.is_empty()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wildcard_match() {
|
||||
let fixtures = vec![
|
||||
("foobarbaz", "foobarbaz", true),
|
||||
("[WILDCARD]", "foobarbaz", true),
|
||||
("foobar", "foobarbaz", false),
|
||||
("foo[WILDCARD]baz", "foobarbaz", true),
|
||||
("foo[WILDCARD]baz", "foobazbar", false),
|
||||
("foo[WILDCARD]baz[WILDCARD]qux", "foobarbazqatqux", true),
|
||||
("foo[WILDCARD]", "foobar", true),
|
||||
("foo[WILDCARD]baz[WILDCARD]", "foobarbazqat", true),
|
||||
// check with different line endings
|
||||
("foo[WILDCARD]\nbaz[WILDCARD]\n", "foobar\nbazqat\n", true),
|
||||
(
|
||||
"foo[WILDCARD]\nbaz[WILDCARD]\n",
|
||||
"foobar\r\nbazqat\r\n",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"foo[WILDCARD]\r\nbaz[WILDCARD]\n",
|
||||
"foobar\nbazqat\r\n",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"foo[WILDCARD]\r\nbaz[WILDCARD]\r\n",
|
||||
"foobar\nbazqat\n",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"foo[WILDCARD]\r\nbaz[WILDCARD]\r\n",
|
||||
"foobar\r\nbazqat\r\n",
|
||||
true,
|
||||
),
|
||||
];
|
||||
|
||||
// Iterate through the fixture lists, testing each one
|
||||
for (pattern, string, expected) in fixtures {
|
||||
let actual = wildcard_match(pattern, string);
|
||||
dbg!(pattern, string, expected);
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pattern_match() {
|
||||
assert!(pattern_match("foo[BAR]baz", "foobarbaz", "[BAR]"));
|
||||
assert!(!pattern_match("foo[BAR]baz", "foobazbar", "[BAR]"));
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import http_server
|
||||
from test_util import DenoTestCase, run_tests
|
||||
from util import root_path, tty_capture
|
||||
|
||||
PERMISSIONS_PROMPT_TEST_TS = "tools/complex_permissions_test.ts"
|
||||
|
||||
PROMPT_PATTERN = b'⚠️'
|
||||
PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == 'nt', "Unable to test tty on Windows")
|
||||
class BaseComplexPermissionTest(DenoTestCase):
|
||||
def _run_deno(self, flags, args):
|
||||
"Returns (return_code, stdout, stderr)."
|
||||
cmd = ([self.deno_exe, "run", "--no-prompt"] + flags +
|
||||
[PERMISSIONS_PROMPT_TEST_TS] + args)
|
||||
return tty_capture(cmd, b'')
|
||||
|
||||
|
||||
class BaseReadWritePermissionsTest(object):
|
||||
test_type = None
|
||||
|
||||
def test_inside_project_dir(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-" + self.test_type + "=" + root_path],
|
||||
[self.test_type, "package.json", "cli/tests/subdir/config.json"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
def test_outside_test_dir(self):
|
||||
code, _stdout, stderr = self._run_deno([
|
||||
"--allow-" + self.test_type + "=" + os.path.join(
|
||||
root_path, "cli/tests")
|
||||
], [self.test_type, "package.json"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_inside_test_dir(self):
|
||||
code, _stdout, stderr = self._run_deno([
|
||||
"--allow-" + self.test_type + "=" + os.path.join(
|
||||
root_path, "cli/tests")
|
||||
], [self.test_type, "cli/tests/subdir/config.json"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
def test_outside_test_and_js_dir(self):
|
||||
code, _stdout, stderr = self._run_deno([
|
||||
"--allow-" + self.test_type + "=" + os.path.join(
|
||||
root_path, "cli/tests") + "," + os.path.join(
|
||||
root_path, "cli/js")
|
||||
], [self.test_type, "package.json"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_inside_test_and_js_dir(self):
|
||||
code, _stdout, stderr = self._run_deno([
|
||||
"--allow-" + self.test_type + "=" + os.path.join(
|
||||
root_path, "cli/tests") + "," + os.path.join(
|
||||
root_path, "cli/js")
|
||||
], [
|
||||
self.test_type, "cli/js/dir_test.ts",
|
||||
"cli/tests/subdir/config.json"
|
||||
])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
def test_relative(self):
|
||||
# Save and restore curdir
|
||||
saved_curdir = os.getcwd()
|
||||
os.chdir(root_path)
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-" + self.test_type + "=" + "./cli/tests"],
|
||||
[self.test_type, "cli/tests/subdir/config.json"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
os.chdir(saved_curdir)
|
||||
|
||||
def test_no_prefix(self):
|
||||
# Save and restore curdir
|
||||
saved_curdir = os.getcwd()
|
||||
os.chdir(root_path)
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-" + self.test_type + "=" + "cli/tests"],
|
||||
[self.test_type, "cli/tests/subdir/config.json"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
os.chdir(saved_curdir)
|
||||
|
||||
|
||||
class TestReadPermissions(BaseReadWritePermissionsTest,
|
||||
BaseComplexPermissionTest):
|
||||
test_type = "read"
|
||||
|
||||
|
||||
class TestWritePermissions(BaseReadWritePermissionsTest,
|
||||
BaseComplexPermissionTest):
|
||||
test_type = "write"
|
||||
|
||||
|
||||
class TestNetFetchPermissions(BaseComplexPermissionTest):
|
||||
test_type = "netFetch"
|
||||
|
||||
def test_allow_localhost_4545(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=localhost:4545"],
|
||||
[self.test_type, "http://localhost:4545"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
def test_allow_deno_land(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=deno.land"],
|
||||
[self.test_type, "http://localhost:4545"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_allow_localhost_4545_fail(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=localhost:4545"],
|
||||
[self.test_type, "http://localhost:4546"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_allow_localhost(self):
|
||||
code, _stdout, stderr = self._run_deno(["--allow-net=localhost"], [
|
||||
self.test_type, "http://localhost:4545", "http://localhost:4546",
|
||||
"http://localhost:4547"
|
||||
])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
|
||||
class TestNetDialPermissions(BaseComplexPermissionTest):
|
||||
test_type = "netDial"
|
||||
|
||||
def test_allow_localhost_ip_4555(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=127.0.0.1:4545"], [self.test_type, "127.0.0.1:4545"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
def test_allow_deno_land(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=deno.land"], [self.test_type, "127.0.0.1:4545"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_allow_localhost_ip_4545_fail(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=127.0.0.1:4545"], [self.test_type, "127.0.0.1:4546"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_allow_localhost_ip(self):
|
||||
code, _stdout, stderr = self._run_deno(["--allow-net=127.0.0.1"], [
|
||||
self.test_type, "127.0.0.1:4545", "127.0.0.1:4546",
|
||||
"127.0.0.1:4547"
|
||||
])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
|
||||
class TestNetListenPermissions(BaseComplexPermissionTest):
|
||||
test_type = "netListen"
|
||||
|
||||
def test_allow_localhost_4555(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=localhost:4555"], [self.test_type, "localhost:4555"])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
def test_allow_deno_land(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=deno.land"], [self.test_type, "localhost:4545"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_allow_localhost_4555_fail(self):
|
||||
code, _stdout, stderr = self._run_deno(
|
||||
["--allow-net=localhost:4555"], [self.test_type, "localhost:4556"])
|
||||
assert code == 1
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN in stderr
|
||||
|
||||
def test_allow_localhost(self):
|
||||
code, _stdout, stderr = self._run_deno(["--allow-net=localhost"], [
|
||||
self.test_type, "localhost:4555", "localhost:4556",
|
||||
"localhost:4557"
|
||||
])
|
||||
assert code == 0
|
||||
assert PROMPT_PATTERN not in stderr
|
||||
assert PERMISSION_DENIED_PATTERN not in stderr
|
||||
|
||||
|
||||
def complex_permissions_tests():
|
||||
return BaseComplexPermissionTest.__subclasses__()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
const { args, readFileSync, writeFileSync, exit } = Deno;
|
||||
|
||||
const name = args[1];
|
||||
const test: (args: string[]) => void = {
|
||||
read(files: string[]): void {
|
||||
files.forEach(file => readFileSync(file));
|
||||
},
|
||||
write(files: string[]): void {
|
||||
files.forEach(file =>
|
||||
writeFileSync(file, new Uint8Array(0), { append: true })
|
||||
);
|
||||
},
|
||||
netFetch(hosts: string[]): void {
|
||||
hosts.forEach(host => fetch(host));
|
||||
},
|
||||
netListen(hosts: string[]): void {
|
||||
hosts.forEach(host => {
|
||||
const [hostname, port] = host.split(":");
|
||||
const listener = Deno.listen({ hostname, port: Number(port) });
|
||||
listener.close();
|
||||
});
|
||||
},
|
||||
async netDial(hosts: string[]): Promise<void> {
|
||||
for (const host of hosts) {
|
||||
const [hostname, port] = host.split(":");
|
||||
const listener = await Deno.dial({ hostname, port: Number(port) });
|
||||
listener.close();
|
||||
}
|
||||
}
|
||||
}[name];
|
||||
|
||||
if (!test) {
|
||||
console.log("Unknown test:", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
test(args.slice(2));
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import os
|
||||
import unittest
|
||||
from sys import stdin
|
||||
|
||||
from test_util import DenoTestCase, run_tests
|
||||
from util import tty_capture
|
||||
|
||||
IS_TTY_TEST_TS = "tests/is_tty.ts"
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == 'nt', "Unable to test tty on Windows")
|
||||
class TestIsTty(DenoTestCase):
|
||||
def test_is_tty(self):
|
||||
cmd = [self.deno_exe, "run", IS_TTY_TEST_TS]
|
||||
code, stdout, _ = tty_capture(cmd, b'')
|
||||
assert code == 0
|
||||
assert str(stdin.isatty()).lower() in stdout
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
|
@ -1,144 +0,0 @@
|
|||
#!/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 PROMPT_PATTERN not in stderr
|
||||
assert FIRST_CHECK_FAILED_PATTERN not in stdout
|
||||
assert PERMISSION_DENIED_PATTERN not 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 FIRST_CHECK_FAILED_PATTERN not in stdout
|
||||
assert PERMISSION_DENIED_PATTERN not 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 FIRST_CHECK_FAILED_PATTERN not 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 PERMISSION_DENIED_PATTERN not 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 FIRST_CHECK_FAILED_PATTERN not in stdout
|
||||
assert PERMISSION_DENIED_PATTERN not 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 FIRST_CHECK_FAILED_PATTERN not in stdout
|
||||
assert PERMISSION_DENIED_PATTERN not 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 PROMPT_PATTERN not 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 PROMPT_PATTERN not in stderr
|
||||
assert FIRST_CHECK_FAILED_PATTERN not in stdout
|
||||
assert PERMISSION_DENIED_PATTERN not 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()
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
const { args, env, exit, listen, makeTempDirSync, readFileSync, run } = Deno;
|
||||
|
||||
const firstCheckFailedMessage = "First check failed";
|
||||
|
||||
const name = args[1];
|
||||
const test = {
|
||||
async needsRead(): Promise<void> {
|
||||
try {
|
||||
readFileSync("package.json");
|
||||
} catch (e) {
|
||||
console.log(firstCheckFailedMessage);
|
||||
}
|
||||
readFileSync("package.json");
|
||||
},
|
||||
needsWrite(): void {
|
||||
try {
|
||||
makeTempDirSync();
|
||||
} catch (e) {
|
||||
console.log(firstCheckFailedMessage);
|
||||
}
|
||||
makeTempDirSync();
|
||||
},
|
||||
needsEnv(): void {
|
||||
try {
|
||||
env().home;
|
||||
} catch (e) {
|
||||
console.log(firstCheckFailedMessage);
|
||||
}
|
||||
env().home;
|
||||
},
|
||||
needsNet(): void {
|
||||
try {
|
||||
listen({ hostname: "127.0.0.1", port: 4540 });
|
||||
} catch (e) {
|
||||
console.log(firstCheckFailedMessage);
|
||||
}
|
||||
listen({ hostname: "127.0.0.1", port: 4541 });
|
||||
},
|
||||
needsRun(): void {
|
||||
try {
|
||||
run({
|
||||
args: [
|
||||
"python",
|
||||
"-c",
|
||||
"import sys; sys.stdout.write('hello'); sys.stdout.flush()"
|
||||
]
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(firstCheckFailedMessage);
|
||||
}
|
||||
run({
|
||||
args: [
|
||||
"python",
|
||||
"-c",
|
||||
"import sys; sys.stdout.write('hello'); sys.stdout.flush()"
|
||||
]
|
||||
});
|
||||
}
|
||||
}[name];
|
||||
|
||||
if (!test) {
|
||||
console.log("Unknown test:", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
test();
|
Loading…
Add table
Reference in a new issue