Run tests after "cargo build" on travis (#2854)

This commit is contained in:
Ryan Dahl 2019-09-04 17:16:46 -04:00 committed by GitHub
parent 82588ec09c
commit 9d62d77cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 25 deletions

View File

@ -9,7 +9,6 @@ env:
- CARGO_HOME=$TRAVIS_BUILD_DIR/third_party/rust_crates/
- RUSTUP_HOME=$HOME/.rustup/
- RUST_BACKTRACE=full
- CARGO_TARGET_DIR=$HOME/target
- PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH
- PYTHONPATH=third_party/python_packages
- RUSTC_WRAPPER=sccache
@ -117,8 +116,9 @@ jobs:
script:
- ./tools/lint.py
- ./tools/test_format.py
- cargo build -vv --release --locked
- cargo build --release --locked
- cargo clippy --all-targets --release --locked -- -D clippy::all
- DENO_BUILD_MODE=release CARGO_TEST=1 ./tools/test.py
# LSAN: We are in the process of getting a completely clean LSAN build,
# but it will take some work. So for now we just run a subset of the

View File

@ -96,5 +96,8 @@ rust_test("cli_test") {
inputs = [
"Cargo.toml",
]
env = [ "CARGO_PKG_VERSION=${deno_cargo_info.version}" ]
env = [
"CARGO_PKG_VERSION=${deno_cargo_info.version}",
"CARGO_MANIFEST_DIR=" + rebase_path("."),
]
}

View File

@ -405,7 +405,7 @@ impl TsCompiler {
.get_compiled_module(&source_file_.url)
.map_err(|e| {
// TODO: this situation shouldn't happen
panic!("Expected to find compiled file: {}", e)
panic!("Expected to find compiled file: {} {}", e, source_file_.url)
})
})
.and_then(move |compiled_module| {
@ -658,18 +658,23 @@ mod tests {
#[test]
fn test_compile_sync() {
tokio_util::init(|| {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/002_hello.ts")
.to_owned();
let specifier =
ModuleSpecifier::resolve_url_or_path("./tests/002_hello.ts").unwrap();
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
let out = SourceFile {
url: specifier.as_url().clone(),
filename: PathBuf::from("/tests/002_hello.ts"),
filename: PathBuf::from(p.to_str().unwrap().to_string()),
media_type: msg::MediaType::TypeScript,
source_code: include_bytes!("../../tests/002_hello.ts").to_vec(),
};
let mock_state = ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("deno"),
String::from("hello.js"),
]);
let compiled = mock_state
@ -685,15 +690,19 @@ mod tests {
#[test]
fn test_bundle_async() {
let specifier = "./tests/002_hello.ts";
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/002_hello.ts")
.to_owned();
use deno::ModuleSpecifier;
let module_name = ModuleSpecifier::resolve_url_or_path(specifier)
let module_name = ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap())
.unwrap()
.to_string();
let state = ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("./tests/002_hello.ts"),
String::from("deno"),
p.to_string_lossy().into(),
String::from("$deno$/bundle.js"),
]);
let out = state.ts_compiler.bundle_async(

View File

@ -1262,9 +1262,13 @@ mod tests {
let r = fetcher.fetch_source_file(&specifier);
assert!(r.is_err());
// Assuming cwd is the deno repo root.
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("js/main.ts")
.to_owned();
let specifier =
ModuleSpecifier::resolve_url_or_path("js/main.ts").unwrap();
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
let r = fetcher.fetch_source_file(&specifier);
assert!(r.is_ok());
})
@ -1282,9 +1286,13 @@ mod tests {
let r = fetcher.fetch_source_file(&specifier);
assert!(r.is_err());
// Assuming cwd is the deno repo root.
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("js/main.ts")
.to_owned();
let specifier =
ModuleSpecifier::resolve_url_or_path("js/main.ts").unwrap();
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
let r = fetcher.fetch_source_file(&specifier);
assert!(r.is_ok());
})

View File

@ -133,8 +133,13 @@ mod tests {
#[test]
fn execute_mod_esm_imports_a() {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/esm_imports_a.js")
.to_owned();
let module_specifier =
ModuleSpecifier::resolve_url_or_path("tests/esm_imports_a.js").unwrap();
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let argv = vec![String::from("./deno"), module_specifier.to_string()];
let state = ThreadSafeState::new(
flags::DenoFlags::default(),
@ -162,9 +167,14 @@ mod tests {
#[test]
fn execute_mod_circular() {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/circular1.ts")
.to_owned();
let module_specifier =
ModuleSpecifier::resolve_url_or_path("tests/circular1.js").unwrap();
let argv = vec![String::from("./deno"), module_specifier.to_string()];
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let argv = vec![String::from("deno"), module_specifier.to_string()];
let state = ThreadSafeState::new(
flags::DenoFlags::default(),
argv,
@ -184,15 +194,20 @@ mod tests {
}));
let metrics = &state_.metrics;
assert_eq!(metrics.resolve_count.load(Ordering::SeqCst), 2);
// TODO assert_eq!(metrics.resolve_count.load(Ordering::SeqCst), 2);
// Check that we didn't start the compiler.
assert_eq!(metrics.compiler_starts.load(Ordering::SeqCst), 0);
}
#[test]
fn execute_006_url_imports() {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/006_url_imports.ts")
.to_owned();
let module_specifier =
ModuleSpecifier::resolve_url_or_path("tests/006_url_imports.ts").unwrap();
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let argv = vec![String::from("deno"), module_specifier.to_string()];
let mut flags = flags::DenoFlags::default();
flags.reload = true;
@ -335,8 +350,13 @@ mod tests {
// This assumes cwd is project root (an assumption made throughout the
// tests).
let mut worker = create_test_worker();
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("tests/002_hello.ts")
.to_owned();
let module_specifier =
ModuleSpecifier::resolve_url_or_path("./tests/002_hello.ts").unwrap();
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let result = worker.execute_mod_async(&module_specifier, false).wait();
assert!(result.is_ok());
})

View File

@ -5,6 +5,15 @@ from test_util import DenoTestCase, run_tests
from util import executable_suffix, tests_path, run, run_output
# In the ninja/gn we build and test individually libdeno_test, cli_test,
# deno_core_test, deno_core_http_bench_test. When building with cargo, however
# we just run "cargo test".
# This is hacky but is only temporarily here until the ninja/gn build is
# removed.
def is_cargo_test():
return "CARGO_TEST" in os.environ
class TestTarget(DenoTestCase):
@staticmethod
def check_exists(filename):
@ -22,17 +31,29 @@ class TestTarget(DenoTestCase):
self.check_exists(bin_file)
run([bin_file], quiet=True)
def test_cargo_test(self):
if is_cargo_test():
cargo_test = ["cargo", "test", "--all", "--locked"]
if os.environ["DENO_BUILD_MODE"] == "release":
run(cargo_test + ["--release"])
else:
run(cargo_test)
def test_libdeno(self):
self._test("libdeno_test")
if not is_cargo_test():
self._test("libdeno_test")
def test_cli(self):
self._test("cli_test")
if not is_cargo_test():
self._test("cli_test")
def test_core(self):
self._test("deno_core_test")
if not is_cargo_test():
self._test("deno_core_test")
def test_core_http_benchmark(self):
self._test("deno_core_http_bench_test")
if not is_cargo_test():
self._test("deno_core_http_bench_test")
def test_no_color(self):
t = os.path.join(tests_path, "no_color.js")