-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove test.py, use cargo test as test frontend (#2967)
Fixes #2933
- Loading branch information
Showing
24 changed files
with
545 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
56ac638
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks to @kt3k - he's responsible for a large amount of this patch (see #2955)
(I'm sorry for not attributing correctly in the author or co-authored-by lines - I always forget when I squash into master on the Github interface...)