From 56ac638d93c96712d6c624e60dcfa4540d334b18 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 19 Sep 2019 14:48:05 -0400 Subject: [PATCH] Remove test.py, use cargo test as test frontend (#2967) Fixes #2933 --- .appveyor.yml | 2 +- .github/workflows/build.yml | 4 +- .travis.yml | 2 +- cli/file_fetcher.rs | 25 +- cli/http_util.rs | 4 + cli/lib.rs | 1 + cli/test_util.rs | 77 ++++++ cli/tests/006_url_imports.ts | 2 +- cli/tests/019_media_types.ts | 16 +- cli/tests/022_info_flag_script.out | 18 +- cli/tests/035_no_fetch_flag.out | 2 +- cli/tests/README.md | 4 +- cli/tests/integration_tests.rs | 426 +++++++++++------------------ cli/tests/tty_tests.rs | 18 ++ cli/tests/util/mod.rs | 218 +++++++++++++++ cli/worker.rs | 4 +- tools/cargo_package.py | 3 +- tools/complex_permissions_test.py | 25 +- tools/fetch_test.py | 3 +- tools/setup.py | 4 +- tools/target_test.py | 7 - tools/test.py | 62 ----- tools/unit_tests.py | 28 -- website/manual.md | 4 +- 24 files changed, 545 insertions(+), 414 deletions(-) create mode 100644 cli/test_util.rs create mode 100644 cli/tests/tty_tests.rs create mode 100644 cli/tests/util/mod.rs delete mode 100755 tools/test.py delete mode 100755 tools/unit_tests.py diff --git a/.appveyor.yml b/.appveyor.yml index 8b10be68de..dc657b6d63 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -166,7 +166,7 @@ build_script: test_script: - python tools\lint.py - python tools\test_format.py - - python tools\test.py + - cargo test -vv --release --all-targets --locked after_test: # Stop sccache and show stats. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00e3b3e803..22886e48e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,10 +70,10 @@ jobs: run: sccache --start-server - name: Build - run: cargo build -vv --release --locked --all-targets + run: cargo build --release --locked --all-targets - name: Test - run: python ./tools/test.py + run: cargo test --release --locked --all-targets - name: Stop sccache run: sccache --stop-server diff --git a/.travis.yml b/.travis.yml index ea2bcc321a..e1ad2a1530 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ before_script: # Default script for release builds. script: - cargo build -vv --release --locked --all-targets -- DENO_BUILD_MODE=release ./tools/test.py +- cargo test -vv --release --all-targets --locked # For some reason it's faster to run clippy after build. - rustup component add clippy - cargo clippy --all-targets --release --locked -- -D clippy::all diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index c062009a41..9c0ef920c5 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -724,6 +724,7 @@ mod tests { #[test] fn test_get_source_code_1() { + let http_server_guard = crate::test_util::http_server(); let (temp_dir, fetcher) = test_setup(); // http_util::fetch_sync_string requires tokio tokio_util::init(|| { @@ -800,10 +801,12 @@ mod tests { assert_eq!(&(r4.media_type), &msg::MediaType::TypeScript); assert!(fs::read_to_string(&headers_file_name).is_err()); }); + drop(http_server_guard); } #[test] fn test_get_source_code_2() { + let http_server_guard = crate::test_util::http_server(); let (temp_dir, fetcher) = test_setup(); // http_util::fetch_sync_string requires tokio tokio_util::init(|| { @@ -866,10 +869,12 @@ mod tests { "text/javascript" ); }); + drop(http_server_guard); } #[test] fn test_get_source_code_multiple_downloads_of_same_file() { + let http_server_guard = crate::test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); // http_util::fetch_sync_string requires tokio tokio_util::init(|| { @@ -910,10 +915,12 @@ mod tests { assert_eq!(headers_file_modified, headers_file_modified_2); }); + drop(http_server_guard); } #[test] fn test_get_source_code_3() { + let http_server_guard = crate::test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); // Test basic follow and headers recording tokio_util::init(|| { @@ -960,10 +967,12 @@ mod tests { // Examine the meta result. assert_eq!(mod_meta.url.clone(), target_module_url); }); + drop(http_server_guard); } #[test] fn test_get_source_code_4() { + let http_server_guard = crate::test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); // Test double redirects and headers recording tokio_util::init(|| { @@ -1022,10 +1031,12 @@ mod tests { // Examine the meta result. assert_eq!(mod_meta.url.clone(), target_url); }); + drop(http_server_guard); } #[test] fn test_get_source_code_5() { + let http_server_guard = crate::test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); // Test that redirect target is not downloaded twice for different redirect source. tokio_util::init(|| { @@ -1067,10 +1078,12 @@ mod tests { assert_eq!(file_modified, file_modified_2); }); + drop(http_server_guard); } #[test] fn test_get_source_code_6() { + let http_server_guard = crate::test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); // Test that redirections can be limited tokio_util::init(|| { @@ -1087,10 +1100,12 @@ mod tests { let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::TooManyRedirects); }); + drop(http_server_guard); } #[test] fn test_get_source_code_no_fetch() { + let http_server_guard = crate::test_util::http_server(); let (_temp_dir, fetcher) = test_setup(); tokio_util::init(|| { let module_url = @@ -1110,11 +1125,12 @@ mod tests { let result = fetcher.get_source_file(&module_url, true, true); assert!(result.is_ok()); }); + drop(http_server_guard); } #[test] fn test_fetch_source_async_1() { - // http_util::fetch_sync_string requires tokio + let http_server_guard = crate::test_util::http_server(); tokio_util::init(|| { let (_temp_dir, fetcher) = test_setup(); let module_url = @@ -1152,11 +1168,12 @@ mod tests { // Not MediaType::TypeScript due to .headers.json modification assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript); }); + drop(http_server_guard); } #[test] fn test_fetch_source_1() { - // http_util::fetch_sync_string requires tokio + let http_server_guard = crate::test_util::http_server(); tokio_util::init(|| { let (_temp_dir, fetcher) = test_setup(); let module_url = @@ -1189,11 +1206,12 @@ mod tests { // Not MediaType::TypeScript due to .headers.json modification assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript); }); + drop(http_server_guard); } #[test] fn test_fetch_source_2() { - // http_util::fetch_sync_string requires tokio + let http_server_guard = crate::test_util::http_server(); tokio_util::init(|| { let (_temp_dir, fetcher) = test_setup(); let module_url = @@ -1249,6 +1267,7 @@ mod tests { "text/typescript" ); }); + drop(http_server_guard); } #[test] diff --git a/cli/http_util.rs b/cli/http_util.rs index 6411a9ad63..abeeffb7a3 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -145,6 +145,7 @@ mod tests { #[test] fn test_fetch_sync_string() { + let http_server_guard = crate::test_util::http_server(); // Relies on external http server. See tools/http_server.py let url = Url::parse("http://127.0.0.1:4545/package.json").unwrap(); tokio_util::init(|| match fetch_string_once_sync(&url).unwrap() { @@ -154,10 +155,12 @@ mod tests { } _ => unreachable!(), }); + drop(http_server_guard); } #[test] fn test_fetch_string_once_with_redirect() { + let http_server_guard = crate::test_util::http_server(); // Relies on external http server. See tools/http_server.py let url = Url::parse("http://127.0.0.1:4546/package.json").unwrap(); // Dns resolver substitutes `127.0.0.1` with `localhost` @@ -166,6 +169,7 @@ mod tests { let result = fetch_string_once_sync(&url).unwrap(); assert_eq!(result, FetchOnceResult::Redirect(target_url)); }); + drop(http_server_guard); } #[test] diff --git a/cli/lib.rs b/cli/lib.rs index ff8f022393..3f101b7756 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -44,6 +44,7 @@ mod signal; pub mod source_maps; mod startup_data; pub mod state; +pub mod test_util; mod tokio_read; mod tokio_util; mod tokio_write; diff --git a/cli/test_util.rs b/cli/test_util.rs new file mode 100644 index 0000000000..e10c0af7cb --- /dev/null +++ b/cli/test_util.rs @@ -0,0 +1,77 @@ +// 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... +// #![cfg(test)] + +use std::path::PathBuf; +use std::process::Child; +use std::process::Command; +use std::sync::Mutex; +use std::sync::MutexGuard; + +lazy_static! { + static ref GUARD: Mutex<()> = Mutex::new(()); +} + +pub fn root_path() -> PathBuf { + PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/..")) +} + +pub fn target_dir() -> PathBuf { + let current_exe = std::env::current_exe().unwrap(); + let target_dir = current_exe.parent().unwrap().parent().unwrap(); + println!("target_dir {}", target_dir.display()); + target_dir.into() +} + +pub fn deno_exe_path() -> PathBuf { + // Something like /Users/rld/src/deno/target/debug/deps/deno + let mut p = target_dir().join("deno"); + if cfg!(windows) { + p.set_extension("exe"); + } + p +} + +pub struct HttpServerGuard<'a> { + #[allow(dead_code)] + g: MutexGuard<'a, ()>, + child: Child, +} + +impl<'a> Drop for HttpServerGuard<'a> { + fn drop(&mut self) { + match self.child.try_wait() { + Ok(None) => { + self.child.kill().expect("failed to kill http_server.py"); + } + Ok(Some(status)) => { + panic!("http_server.py exited unexpectedly {}", status) + } + Err(e) => panic!("http_server.py err {}", e), + } + } +} + +/// Starts tools/http_server.py when the returned guard is dropped, the server +/// will be killed. +pub fn http_server<'a>() -> HttpServerGuard<'a> { + // TODO(ry) Allow tests to use the http server in parallel. + let g = GUARD.lock().unwrap(); + + println!("tools/http_server.py starting..."); + let child = Command::new("python") + .current_dir(root_path()) + .arg("tools/http_server.py") + .spawn() + .expect("failed to execute child"); + + // Wait 1 second for the server to come up. TODO(ry) this is Racy. + std::thread::sleep(std::time::Duration::from_secs(2)); + + println!("tools/http_server.py ready"); + + HttpServerGuard { child, g } +} diff --git a/cli/tests/006_url_imports.ts b/cli/tests/006_url_imports.ts index b2c7db2704..109cb603e3 100644 --- a/cli/tests/006_url_imports.ts +++ b/cli/tests/006_url_imports.ts @@ -1,3 +1,3 @@ -import { printHello } from "http://localhost:4545/tests/subdir/mod2.ts"; +import { printHello } from "http://localhost:4545/cli/tests/subdir/mod2.ts"; printHello(); console.log("success"); diff --git a/cli/tests/019_media_types.ts b/cli/tests/019_media_types.ts index 5f1f862a09..cc99be83bd 100644 --- a/cli/tests/019_media_types.ts +++ b/cli/tests/019_media_types.ts @@ -2,14 +2,14 @@ // based on the URL containing `.t#.` strings, which exercises the different // mapping of media types end to end. -import { loaded as loadedTs1 } from "http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts"; -import { loaded as loadedTs2 } from "http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts"; -import { loaded as loadedTs3 } from "http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts"; -import { loaded as loadedTs4 } from "http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts"; -import { loaded as loadedJs1 } from "http://localhost:4545/tests/subdir/mt_text_javascript.j1.js"; -import { loaded as loadedJs2 } from "http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js"; -import { loaded as loadedJs3 } from "http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js"; -import { loaded as loadedJs4 } from "http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js"; +import { loaded as loadedTs1 } from "http://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts"; +import { loaded as loadedTs2 } from "http://localhost:4545/cli/tests/subdir/mt_video_vdn.t2.ts"; +import { loaded as loadedTs3 } from "http://localhost:4545/cli/tests/subdir/mt_video_mp2t.t3.ts"; +import { loaded as loadedTs4 } from "http://localhost:4545/cli/tests/subdir/mt_application_x_typescript.t4.ts"; +import { loaded as loadedJs1 } from "http://localhost:4545/cli/tests/subdir/mt_text_javascript.j1.js"; +import { loaded as loadedJs2 } from "http://localhost:4545/cli/tests/subdir/mt_application_ecmascript.j2.js"; +import { loaded as loadedJs3 } from "http://localhost:4545/cli/tests/subdir/mt_text_ecmascript.j3.js"; +import { loaded as loadedJs4 } from "http://localhost:4545/cli/tests/subdir/mt_application_x_javascript.j4.js"; console.log( "success", diff --git a/cli/tests/022_info_flag_script.out b/cli/tests/022_info_flag_script.out index 519e7cf6b0..48eef73656 100644 --- a/cli/tests/022_info_flag_script.out +++ b/cli/tests/022_info_flag_script.out @@ -3,12 +3,12 @@ type: TypeScript compiled: [WILDCARD].js map: [WILDCARD].js.map deps: -http://127.0.0.1:4545/tests/019_media_types.ts - ├── http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts - ├── http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts - ├── http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts - ├── http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts - ├── http://localhost:4545/tests/subdir/mt_text_javascript.j1.js - ├── http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js - ├── http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js - └── http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js +http://127.0.0.1:4545/cli/tests/019_media_types.ts + ├── http://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts + ├── http://localhost:4545/cli/tests/subdir/mt_video_vdn.t2.ts + ├── http://localhost:4545/cli/tests/subdir/mt_video_mp2t.t3.ts + ├── http://localhost:4545/cli/tests/subdir/mt_application_x_typescript.t4.ts + ├── http://localhost:4545/cli/tests/subdir/mt_text_javascript.j1.js + ├── http://localhost:4545/cli/tests/subdir/mt_application_ecmascript.j2.js + ├── http://localhost:4545/cli/tests/subdir/mt_text_ecmascript.j3.js + └── http://localhost:4545/cli/tests/subdir/mt_application_x_javascript.j4.js diff --git a/cli/tests/035_no_fetch_flag.out b/cli/tests/035_no_fetch_flag.out index 0c835830ca..26f020aa5b 100644 --- a/cli/tests/035_no_fetch_flag.out +++ b/cli/tests/035_no_fetch_flag.out @@ -1 +1 @@ -Cannot resolve module "http://127.0.0.1:4545/tests/019_media_types.ts" +Cannot resolve module "http://127.0.0.1:4545/cli/tests/019_media_types.ts" diff --git a/cli/tests/README.md b/cli/tests/README.md index dc199196d2..fe90719269 100644 --- a/cli/tests/README.md +++ b/cli/tests/README.md @@ -3,5 +3,5 @@ This path contains integration tests. See integration_tests.rs for the index. TODO(ry) Currently //tests is a symlink to //cli/tests, to simplify transition. -In the future //tests should be removed when all references to //tests are -updated. +In the future the symlink should be removed when all the many references have +been updated to the new path. diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 86de4fa6a6..b9946e1f9a 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1,21 +1,82 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. #[macro_use] -extern crate log; +extern crate lazy_static; +extern crate tempfile; +mod util; +use util::*; -use deno_cli::colors::strip_ansi_codes; -use os_pipe::pipe; -use std::env; -use std::io::Read; -use std::io::Write; -use std::path::PathBuf; -use std::process::Command; -use std::process::Stdio; +#[test] +fn benchmark_test() { + run_python_script("tools/benchmark_test.py") +} + +#[test] +fn deno_dir_test() { + let g = http_server(); + 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"); + drop(g); +} + +// TODO(#2933): Rewrite this test in rust. +#[test] +fn fmt_test() { + let g = http_server(); + 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()) + .arg("run") + .arg("--reload") + .arg("--allow-run") + .arg("--allow-env") + .arg("js/unit_test_runner.ts") + .spawn() + .expect("failed to spawn script"); + let status = deno.wait().expect("failed to wait for the child process"); + assert_eq!(Some(0), status.code()); + assert!(status.success()); + drop(g); +} + +// TODO(#2933): Rewrite this test in rust. +#[test] +fn repl_test() { + run_python_script("tools/repl_test.py") +} + +#[test] +fn setup_test() { + run_python_script("tools/setup_test.py") +} + +#[test] +fn target_test() { + run_python_script("tools/target_test.py") +} + +#[test] +fn util_test() { + run_python_script("tools/util_test.py") +} macro_rules! itest( ($name:ident {$( $key:ident: $value:expr,)*}) => { #[test] fn $name() { - (IntegrationTest { + (CheckOutputIntegrationTest { $( $key: $value, )* @@ -27,180 +88,187 @@ macro_rules! itest( itest!(_001_hello { args: "run --reload 001_hello.js", - output: "tests/001_hello.js.out", + output: "001_hello.js.out", }); itest!(_002_hello { args: "run --reload 002_hello.ts", - output: "tests/002_hello.ts.out", + output: "002_hello.ts.out", }); itest!(_003_relative_import { args: "run --reload 003_relative_import.ts", - output: "tests/003_relative_import.ts.out", + output: "003_relative_import.ts.out", }); itest!(_004_set_timeout { args: "run --reload 004_set_timeout.ts", - output: "tests/004_set_timeout.ts.out", + output: "004_set_timeout.ts.out", }); itest!(_005_more_imports { args: "run --reload 005_more_imports.ts", - output: "tests/005_more_imports.ts.out", + output: "005_more_imports.ts.out", }); itest!(_006_url_imports { args: "run --reload 006_url_imports.ts", - output: "tests/006_url_imports.ts.out", + output: "006_url_imports.ts.out", + http_server: true, }); itest!(_012_async { args: "run --reload 012_async.ts", - output: "tests/012_async.ts.out", + output: "012_async.ts.out", }); itest!(_013_dynamic_import { args: "013_dynamic_import.ts --reload --allow-read", - output: "tests/013_dynamic_import.ts.out", + output: "013_dynamic_import.ts.out", }); itest!(_014_duplicate_import { args: "014_duplicate_import.ts --reload --allow-read", - output: "tests/014_duplicate_import.ts.out", + output: "014_duplicate_import.ts.out", }); itest!(_015_duplicate_parallel_import { args: "015_duplicate_parallel_import.js --reload --allow-read", - output: "tests/015_duplicate_parallel_import.js.out", + output: "015_duplicate_parallel_import.js.out", }); itest!(_016_double_await { args: "run --allow-read --reload 016_double_await.ts", - output: "tests/016_double_await.ts.out", + output: "016_double_await.ts.out", }); itest!(_017_import_redirect { args: "run --reload 017_import_redirect.ts", - output: "tests/017_import_redirect.ts.out", + output: "017_import_redirect.ts.out", }); itest!(_018_async_catch { args: "run --reload 018_async_catch.ts", - output: "tests/018_async_catch.ts.out", + output: "018_async_catch.ts.out", }); itest!(_019_media_types { args: "run --reload 019_media_types.ts", - output: "tests/019_media_types.ts.out", + output: "019_media_types.ts.out", + http_server: true, }); itest!(_020_json_modules { args: "run --reload 020_json_modules.ts", - output: "tests/020_json_modules.ts.out", + output: "020_json_modules.ts.out", }); itest!(_021_mjs_modules { args: "run --reload 021_mjs_modules.ts", - output: "tests/021_mjs_modules.ts.out", + output: "021_mjs_modules.ts.out", }); itest!(_022_info_flag_script { - args: "info http://127.0.0.1:4545/tests/019_media_types.ts", - output: "tests/022_info_flag_script.out", + args: "info http://127.0.0.1:4545/cli/tests/019_media_types.ts", + output: "022_info_flag_script.out", + http_server: true, }); itest!(_023_no_ext_with_headers { args: "run --reload 023_no_ext_with_headers", - output: "tests/023_no_ext_with_headers.out", + output: "023_no_ext_with_headers.out", }); // FIXME(bartlomieju): this test should use remote file // itest!(_024_import_no_ext_with_headers { // args: "run --reload 024_import_no_ext_with_headers.ts", -// output: "tests/024_import_no_ext_with_headers.ts.out", +// output: "024_import_no_ext_with_headers.ts.out", // }); itest!(_025_hrtime { args: "run --allow-hrtime --reload 025_hrtime.ts", - output: "tests/025_hrtime.ts.out", + output: "025_hrtime.ts.out", }); itest!(_025_reload_js_type_error { args: "run --reload 025_reload_js_type_error.js", - output: "tests/025_reload_js_type_error.js.out", + output: "025_reload_js_type_error.js.out", }); itest!(_026_redirect_javascript { args: "run --reload 026_redirect_javascript.js", - output: "tests/026_redirect_javascript.js.out", + output: "026_redirect_javascript.js.out", + http_server: true, }); itest!(_026_workers { args: "run --reload 026_workers.ts", - output: "tests/026_workers.ts.out", + output: "026_workers.ts.out", }); itest!(_027_redirect_typescript { args: "run --reload 027_redirect_typescript.ts", - output: "tests/027_redirect_typescript.ts.out", + output: "027_redirect_typescript.ts.out", + http_server: true, }); itest!(_028_args { args: "run --reload 028_args.ts --arg1 val1 --arg2=val2 -- arg3 arg4", - output: "tests/028_args.ts.out", + output: "028_args.ts.out", }); itest!(_029_eval { args: "eval console.log(\"hello\")", - output: "tests/029_eval.out", + output: "029_eval.out", }); itest!(_030_xeval { args: "xeval console.log($.toUpperCase())", input: Some("a\nb\n\nc"), - output: "tests/030_xeval.out", + output: "030_xeval.out", }); itest!(_031_xeval_replvar { args: "xeval -I val console.log(val.toUpperCase());", input: Some("a\nb\n\nc"), - output: "tests/031_xeval_replvar.out", + output: "031_xeval_replvar.out", }); itest!(_032_xeval_delim { args: "xeval -d DELIM console.log($.toUpperCase());", input: Some("aDELIMbDELIMDELIMc"), - output: "tests/032_xeval_delim.out", + output: "032_xeval_delim.out", }); itest!(_033_import_map { args: "run --reload --importmap=importmaps/import_map.json importmaps/test.ts", - output: "tests/033_import_map.out", + output: "033_import_map.out", }); itest!(_034_onload { args: "run --reload 034_onload/main.ts", - output: "tests/034_onload.out", + output: "034_onload.out", }); itest!(_035_no_fetch_flag { - args: "--reload --no-fetch http://127.0.0.1:4545/tests/019_media_types.ts", - output: "tests/035_no_fetch_flag.out", + args: + "--reload --no-fetch http://127.0.0.1:4545/cli/tests/019_media_types.ts", + output: "035_no_fetch_flag.out", exit_code: 1, check_stderr: true, + http_server: true, }); itest!(_036_import_map_fetch { args: "fetch --reload --importmap=importmaps/import_map.json importmaps/test.ts", - output: "tests/036_import_map_fetch.out", + output: "036_import_map_fetch.out", }); itest!(_037_current_thread { args: "run --current-thread --reload 034_onload/main.ts", - output: "tests/034_onload.out", + output: "034_onload.out", }); itest!(_038_checkjs { @@ -208,72 +276,72 @@ itest!(_038_checkjs { args: "run --reload --config 038_checkjs.tsconfig.json 038_checkjs.js", check_stderr: true, exit_code: 1, - output: "tests/038_checkjs.js.out", + output: "038_checkjs.js.out", }); itest!(_039_worker_deno_ns { args: "run --reload 039_worker_deno_ns.ts", - output: "tests/039_worker_deno_ns.ts.out", + output: "039_worker_deno_ns.ts.out", }); itest!(_040_worker_blob { args: "run --reload 040_worker_blob.ts", - output: "tests/040_worker_blob.ts.out", + output: "040_worker_blob.ts.out", }); itest!(_041_dyn_import_eval { args: "eval import('./subdir/mod4.js').then(console.log)", - output: "tests/041_dyn_import_eval.out", + output: "041_dyn_import_eval.out", }); itest!(_041_info_flag { args: "info", - output: "tests/041_info_flag.out", + output: "041_info_flag.out", }); itest!(_042_dyn_import_evalcontext { args: "run --allow-read --reload 042_dyn_import_evalcontext.ts", - output: "tests/042_dyn_import_evalcontext.ts.out", + output: "042_dyn_import_evalcontext.ts.out", }); itest!(async_error { exit_code: 1, args: "run --reload async_error.ts", check_stderr: true, - output: "tests/async_error.ts.out", + output: "async_error.ts.out", }); itest!(circular1 { args: "run --reload circular1.js", - output: "tests/circular1.js.out", + output: "circular1.js.out", }); itest!(config { args: "run --reload --config config.tsconfig.json config.ts", check_stderr: true, exit_code: 1, - output: "tests/config.ts.out", + output: "config.ts.out", }); itest!(error_001 { args: "run --reload error_001.ts", check_stderr: true, exit_code: 1, - output: "tests/error_001.ts.out", + output: "error_001.ts.out", }); itest!(error_002 { args: "run --reload error_002.ts", check_stderr: true, exit_code: 1, - output: "tests/error_002.ts.out", + output: "error_002.ts.out", }); itest!(error_003_typescript { args: "run --reload error_003_typescript.ts", check_stderr: true, exit_code: 1, - output: "tests/error_003_typescript.ts.out", + output: "error_003_typescript.ts.out", }); // Supposing that we've already attempted to run error_003_typescript.ts @@ -284,363 +352,187 @@ itest!(error_003_typescript2 { args: "run error_003_typescript.ts", check_stderr: true, exit_code: 1, - output: "tests/error_003_typescript.ts.out", + output: "error_003_typescript.ts.out", }); itest!(error_004_missing_module { args: "run --reload error_004_missing_module.ts", check_stderr: true, exit_code: 1, - output: "tests/error_004_missing_module.ts.out", + output: "error_004_missing_module.ts.out", }); itest!(error_005_missing_dynamic_import { args: "run --reload error_005_missing_dynamic_import.ts", check_stderr: true, exit_code: 1, - output: "tests/error_005_missing_dynamic_import.ts.out", + output: "error_005_missing_dynamic_import.ts.out", }); itest!(error_006_import_ext_failure { args: "run --reload error_006_import_ext_failure.ts", check_stderr: true, exit_code: 1, - output: "tests/error_006_import_ext_failure.ts.out", + output: "error_006_import_ext_failure.ts.out", }); itest!(error_007_any { args: "run --reload error_007_any.ts", check_stderr: true, exit_code: 1, - output: "tests/error_007_any.ts.out", + output: "error_007_any.ts.out", }); itest!(error_008_checkjs { args: "run --reload error_008_checkjs.js", check_stderr: true, exit_code: 1, - output: "tests/error_008_checkjs.js.out", + output: "error_008_checkjs.js.out", }); itest!(error_011_bad_module_specifier { args: "run --reload error_011_bad_module_specifier.ts", check_stderr: true, exit_code: 1, - output: "tests/error_011_bad_module_specifier.ts.out", + output: "error_011_bad_module_specifier.ts.out", }); itest!(error_012_bad_dynamic_import_specifier { args: "run --reload error_012_bad_dynamic_import_specifier.ts", check_stderr: true, exit_code: 1, - output: "tests/error_012_bad_dynamic_import_specifier.ts.out", + output: "error_012_bad_dynamic_import_specifier.ts.out", }); itest!(error_013_missing_script { args: "run --reload missing_file_name", check_stderr: true, exit_code: 1, - output: "tests/error_013_missing_script.out", + output: "error_013_missing_script.out", }); itest!(error_014_catch_dynamic_import_error { args: "error_014_catch_dynamic_import_error.js --reload --allow-read", - output: "tests/error_014_catch_dynamic_import_error.js.out", + output: "error_014_catch_dynamic_import_error.js.out", }); itest!(error_015_dynamic_import_permissions { args: "--reload --no-prompt error_015_dynamic_import_permissions.js", - output: "tests/error_015_dynamic_import_permissions.out", + output: "error_015_dynamic_import_permissions.out", check_stderr: true, exit_code: 1, + http_server: true, }); // We have an allow-net flag but not allow-read, it should still result in error. itest!(error_016_dynamic_import_permissions2 { args: "--no-prompt --reload --allow-net error_016_dynamic_import_permissions2.js", - output: "tests/error_016_dynamic_import_permissions2.out", + output: "error_016_dynamic_import_permissions2.out", check_stderr: true, exit_code: 1, + http_server: true, }); itest!(error_stack { args: "run --reload error_stack.ts", check_stderr: true, exit_code: 1, - output: "tests/error_stack.ts.out", + output: "error_stack.ts.out", }); itest!(error_syntax { args: "run --reload error_syntax.js", check_stderr: true, exit_code: 1, - output: "tests/error_syntax.js.out", + output: "error_syntax.js.out", }); itest!(error_type_definitions { args: "run --reload error_type_definitions.ts", check_stderr: true, exit_code: 1, - output: "tests/error_type_definitions.ts.out", + output: "error_type_definitions.ts.out", }); itest!(exit_error42 { exit_code: 42, args: "run --reload exit_error42.ts", - output: "tests/exit_error42.ts.out", + output: "exit_error42.ts.out", }); itest!(https_import { args: "run --reload https_import.ts", - output: "tests/https_import.ts.out", + output: "https_import.ts.out", }); itest!(if_main { args: "run --reload if_main.ts", - output: "tests/if_main.ts.out", + output: "if_main.ts.out", }); itest!(import_meta { args: "run --reload import_meta.ts", - output: "tests/import_meta.ts.out", + output: "import_meta.ts.out", }); itest!(seed_random { args: "run --seed=100 seed_random.js", - output: "tests/seed_random.js.out", + output: "seed_random.js.out", }); itest!(type_definitions { args: "run --reload type_definitions.ts", - output: "tests/type_definitions.ts.out", + output: "type_definitions.ts.out", }); itest!(types { args: "types", - output: "tests/types.out", + output: "types.out", }); itest!(unbuffered_stderr { args: "run --reload unbuffered_stderr.ts", check_stderr: true, - output: "tests/unbuffered_stderr.ts.out", + output: "unbuffered_stderr.ts.out", }); itest!(unbuffered_stdout { args: "run --reload unbuffered_stdout.ts", - output: "tests/unbuffered_stdout.ts.out", + output: "unbuffered_stdout.ts.out", }); itest!(v8_flags { args: "run --v8-flags=--expose-gc v8_flags.js", - output: "tests/v8_flags.js.out", + output: "v8_flags.js.out", }); itest!(v8_help { args: "--v8-options", - output: "tests/v8_help.out", + output: "v8_help.out", }); itest!(version { args: "version", - output: "tests/version.out", + output: "version.out", }); itest!(version_long_flag { args: "--version", - output: "tests/version.out", + output: "version.out", }); itest!(version_short_flag { args: "-v", - output: "tests/version.out", + output: "version.out", }); itest!(wasm { args: "run wasm.ts", - output: "tests/wasm.ts.out", + output: "wasm.ts.out", }); itest!(wasm_async { args: "wasm_async.js", - output: "tests/wasm_async.out", + output: "wasm_async.out", }); - -/////////////////////////// - -#[derive(Debug, Default)] -struct IntegrationTest { - args: &'static str, - output: &'static str, - input: Option<&'static str>, - exit_code: i32, - check_stderr: bool, -} - -impl IntegrationTest { - pub fn run(&self) { - let args = self.args.split_whitespace(); - let root = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/..")); - let mut target = "debug"; - - if let Ok(build_mode) = env::var("DENO_BUILD_MODE") { - if build_mode == "release" { - target = "release"; - } - } - - let bin = root.join(format!("target/{}/deno", target)); - debug!("root path {}", root.display()); - debug!("bin path {}", bin.display()); - - let (mut reader, writer) = pipe().unwrap(); - let mut command = Command::new(bin); - command.args(args); - command.current_dir(root.join("tests")); - 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(); - - 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 = root.join(self.output); - debug!("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::>(); - 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]")); -} diff --git a/cli/tests/tty_tests.rs b/cli/tests/tty_tests.rs new file mode 100644 index 0000000000..413d39caf0 --- /dev/null +++ b/cli/tests/tty_tests.rs @@ -0,0 +1,18 @@ +// 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(); + 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); +} diff --git a/cli/tests/util/mod.rs b/cli/tests/util/mod.rs new file mode 100644 index 0000000000..a91e5367b6 --- /dev/null +++ b/cli/tests/util/mod.rs @@ -0,0 +1,218 @@ +//! 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 +} + +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::>(); + 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]")); +} diff --git a/cli/worker.rs b/cli/worker.rs index a14a226104..b92cef58e7 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -201,10 +201,11 @@ mod tests { #[test] fn execute_006_url_imports() { + let http_server_guard = crate::test_util::http_server(); let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) .parent() .unwrap() - .join("tests/006_url_imports.ts") + .join("cli/tests/006_url_imports.ts") .to_owned(); let module_specifier = ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); @@ -232,6 +233,7 @@ mod tests { assert_eq!(metrics.resolve_count.load(Ordering::SeqCst), 3); // Check that we've only invoked the compiler once. assert_eq!(metrics.compiler_starts.load(Ordering::SeqCst), 1); + drop(http_server_guard); } fn create_test_worker() -> Worker { diff --git a/tools/cargo_package.py b/tools/cargo_package.py index 7696681e79..29f5e7fb50 100755 --- a/tools/cargo_package.py +++ b/tools/cargo_package.py @@ -15,8 +15,7 @@ import errno from shutil import copytree, ignore_patterns, copyfile from tempfile import mkdtemp from string import Template -from util import root_path -from util import run +from util import root_path, run if sys.platform == "linux2": llvm_target = "x86_64-unknown-linux-gnu" diff --git a/tools/complex_permissions_test.py b/tools/complex_permissions_test.py index cc35577ded..985f9a9721 100755 --- a/tools/complex_permissions_test.py +++ b/tools/complex_permissions_test.py @@ -29,7 +29,7 @@ class BaseReadWritePermissionsTest(object): def test_inside_project_dir(self): code, _stdout, stderr = self._run_deno( ["--allow-" + self.test_type + "=" + root_path], - [self.test_type, "package.json", "tests/subdir/config.json"]) + [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 @@ -37,7 +37,7 @@ class BaseReadWritePermissionsTest(object): def test_outside_test_dir(self): code, _stdout, stderr = self._run_deno([ "--allow-" + self.test_type + "=" + os.path.join( - root_path, "tests") + root_path, "cli/tests") ], [self.test_type, "package.json"]) assert code == 1 assert PROMPT_PATTERN not in stderr @@ -46,8 +46,8 @@ class BaseReadWritePermissionsTest(object): def test_inside_test_dir(self): code, _stdout, stderr = self._run_deno([ "--allow-" + self.test_type + "=" + os.path.join( - root_path, "tests") - ], [self.test_type, "tests/subdir/config.json"]) + 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 @@ -55,7 +55,7 @@ class BaseReadWritePermissionsTest(object): def test_outside_test_and_js_dir(self): code, _stdout, stderr = self._run_deno([ "--allow-" + self.test_type + "=" + os.path.join( - root_path, "tests") + "," + os.path.join(root_path, "js") + root_path, "cli/tests") + "," + os.path.join(root_path, "js") ], [self.test_type, "package.json"]) assert code == 1 assert PROMPT_PATTERN not in stderr @@ -64,8 +64,8 @@ class BaseReadWritePermissionsTest(object): def test_inside_test_and_js_dir(self): code, _stdout, stderr = self._run_deno([ "--allow-" + self.test_type + "=" + os.path.join( - root_path, "tests") + "," + os.path.join(root_path, "js") - ], [self.test_type, "js/dir_test.ts", "tests/subdir/config.json"]) + root_path, "cli/tests") + "," + os.path.join(root_path, "js") + ], [self.test_type, "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 @@ -75,8 +75,8 @@ class BaseReadWritePermissionsTest(object): saved_curdir = os.getcwd() os.chdir(root_path) code, _stdout, stderr = self._run_deno( - ["--allow-" + self.test_type + "=" + "./tests"], - [self.test_type, "tests/subdir/config.json"]) + ["--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 @@ -87,8 +87,8 @@ class BaseReadWritePermissionsTest(object): saved_curdir = os.getcwd() os.chdir(root_path) code, _stdout, stderr = self._run_deno( - ["--allow-" + self.test_type + "=" + "tests"], - [self.test_type, "tests/subdir/config.json"]) + ["--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 @@ -215,5 +215,4 @@ def complex_permissions_tests(): if __name__ == "__main__": - with http_server.spawn(): - run_tests() + run_tests() diff --git a/tools/fetch_test.py b/tools/fetch_test.py index b4bf1836c9..e6e5cb6a0f 100755 --- a/tools/fetch_test.py +++ b/tools/fetch_test.py @@ -29,5 +29,4 @@ class TestFetch(DenoTestCase): if __name__ == "__main__": - with http_server.spawn(): - run_tests() + run_tests() diff --git a/tools/setup.py b/tools/setup.py index aef65924de..b6c8cac924 100755 --- a/tools/setup.py +++ b/tools/setup.py @@ -127,9 +127,9 @@ def generate_gn_args(mode): if "DENO_BUILD_ARGS" in os.environ: out += os.environ["DENO_BUILD_ARGS"].split() - cacher = third_party.get_prebuilt_tool_path("sccache") + cacher = find_executable("sccache") if not os.path.exists(cacher): - cacher = find_executable("sccache") or find_executable("ccache") + cacher = third_party.get_prebuilt_tool_path("sccache") # Check if ccache or sccache are in the path, and if so we set cc_wrapper. cc_wrapper = cacher diff --git a/tools/target_test.py b/tools/target_test.py index b4cb6996c2..724dacdecf 100644 --- a/tools/target_test.py +++ b/tools/target_test.py @@ -21,13 +21,6 @@ class TestTarget(DenoTestCase): self.check_exists(bin_file) run([bin_file], quiet=True) - def test_cargo_test(self): - cargo_test = ["cargo", "test", "--all", "--locked"] - if build_mode() == "release": - run(cargo_test + ["--release"]) - else: - run(cargo_test) - def test_libdeno(self): self._test("libdeno_test") diff --git a/tools/test.py b/tools/test.py deleted file mode 100755 index c3110c655d..0000000000 --- a/tools/test.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python -# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -# Runs the full test suite. -# Usage: ./tools/test.py out/Debug -import os - -from benchmark_test import TestBenchmark -from deno_dir_test import TestDenoDir -from fetch_test import TestFetch -from fmt_test import TestFmt -from repl_test import TestRepl -from setup_test import TestSetup -from target_test import TestTarget -from unit_tests import JsUnitTests -from util_test import TestUtil -# NOTE: These tests are skipped on Windows -from is_tty_test import TestIsTty -from permission_prompt_test import permission_prompt_tests -from complex_permissions_test import complex_permissions_tests - -import http_server -from util import (enable_ansi_colors, build_path, RESET, FG_RED, FG_GREEN, - executable_suffix, rmtree, tests_path) -from test_util import parse_test_args, run_tests - - -def main(): - args = parse_test_args() - - deno_dir = os.path.join(args.build_dir, ".deno_test") - if os.path.isdir(deno_dir): - rmtree(deno_dir) - os.environ["DENO_DIR"] = deno_dir - - enable_ansi_colors() - - test_cases = [ - TestSetup, - TestUtil, - TestTarget, - JsUnitTests, - TestFetch, - TestRepl, - TestDenoDir, - TestBenchmark, - ] - - # TODO(ry) This test isn't working yet on github actions. - if "GH_ACTIONS" not in os.environ: - test_cases += [TestIsTty] - - test_cases += permission_prompt_tests() - test_cases += complex_permissions_tests() - # It is very slow, so do TestFmt at the end. - test_cases += [TestFmt] - - with http_server.spawn(): - run_tests(test_cases) - - -if __name__ == '__main__': - main() diff --git a/tools/unit_tests.py b/tools/unit_tests.py deleted file mode 100755 index 859afcea33..0000000000 --- a/tools/unit_tests.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import sys -import subprocess - -import http_server -from test_util import DenoTestCase, run_tests - - -class JsUnitTests(DenoTestCase): - def test_unit_test_runner(self): - cmd = [ - self.deno_exe, "run", "--reload", "--allow-run", "--allow-env", - "js/unit_test_runner.ts" - ] - process = subprocess.Popen( - cmd, bufsize=1, universal_newlines=True, stderr=subprocess.STDOUT) - - process.wait() - errcode = process.returncode - if errcode != 0: - raise AssertionError( - "js/unit_test_runner.ts exited with exit code %s" % errcode) - - -if __name__ == '__main__': - with http_server.spawn(): - run_tests() diff --git a/website/manual.md b/website/manual.md index ae3f18d41b..ead3dddac6 100644 --- a/website/manual.md +++ b/website/manual.md @@ -167,7 +167,7 @@ cargo build -vv ./target/debug/deno tests/002_hello.ts # Test. -./tools/test.py +cargo test # Format code. ./tools/format.py @@ -1148,7 +1148,7 @@ Before submitting, please make sure the following is done: 1. That there is a related issue and it is referenced in the PR text. 2. There are tests that cover the changes. -3. Ensure `./tools/test.py` passes. +3. Ensure `cargo test` passes. 4. Format your code with `tools/format.py` 5. Make sure `./tools/lint.py` passes.