-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use test launcher when not needed (#960)
This backwards compatible change does 2 things: it uses testing.TestEnvironment to populate the environment for the rust_test execution. This is a new discovery that we were not aware of, and it mostly removes most common duties from our test launcher. stops using test launcher for situations when it is not needed (when there is no {pwd} placeholder expansion needed in environment variable values). What will likely follow is an incompatible change that removes {pwd} expansion altogether (after I do the reserach to see if it is used :)
- Loading branch information
Showing
8 changed files
with
93 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
load( | ||
"//rust:rust.bzl", | ||
"rust_binary", | ||
"rust_test", | ||
) | ||
|
||
rust_binary( | ||
name = "hello-world", | ||
srcs = ["src/main.rs"], | ||
edition = "2018", | ||
) | ||
|
||
filegroup( | ||
name = "hello_world_main", | ||
srcs = ["src/main.rs"], | ||
) | ||
|
||
rust_test( | ||
name = "test", | ||
srcs = ["tests/run.rs"], | ||
data = [ | ||
":hello-world", | ||
":hello_world_main", | ||
], | ||
edition = "2018", | ||
env = { | ||
"FERRIS_SAYS": "Hello fellow Rustaceans!", | ||
"HELLO_WORLD_BIN_ROOTPATH": "$(rootpath :hello-world)", | ||
"HELLO_WORLD_SRC_EXECPATH": "$(execpath :hello_world_main)", | ||
}, | ||
) |
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,3 @@ | ||
fn main() { | ||
println!("Hello world"); | ||
} |
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,35 @@ | ||
#[test] | ||
fn run() { | ||
let path = env!("CARGO_BIN_EXE_hello-world"); | ||
let output = std::process::Command::new(path) | ||
.output() | ||
.expect("Failed to run process"); | ||
assert_eq!(&b"Hello world\n"[..], output.stdout.as_slice()); | ||
|
||
// Test the `env` attribute of `rust_test` at run time | ||
assert_eq!( | ||
std::env::var("FERRIS_SAYS").unwrap(), | ||
"Hello fellow Rustaceans!" | ||
); | ||
|
||
// Test the behavior of `rootpath` and that a binary can be found relative to current_dir | ||
let hello_world_bin = | ||
std::path::PathBuf::from(std::env::var_os("HELLO_WORLD_BIN_ROOTPATH").unwrap()); | ||
|
||
assert_eq!( | ||
hello_world_bin.as_path(), | ||
std::path::Path::new(if std::env::consts::OS == "windows" { | ||
"test/test_env_launcher/hello-world.exe" | ||
} else { | ||
"test/test_env_launcher/hello-world" | ||
}) | ||
); | ||
assert!(!hello_world_bin.is_absolute()); | ||
assert!(hello_world_bin.exists()); | ||
|
||
// Ensure `execpath` expanded variables map to real files and have absolute paths | ||
let hello_world_src = | ||
std::path::PathBuf::from(std::env::var("HELLO_WORLD_SRC_EXECPATH").unwrap()); | ||
assert!(hello_world_src.is_absolute()); | ||
assert!(hello_world_src.exists()); | ||
} |