Skip to content

Commit

Permalink
Merge pull request #68 from oli-obk/single_test_command
Browse files Browse the repository at this point in the history
Provide a command for running a single test instead of running it directly
  • Loading branch information
oli-obk authored May 12, 2023
2 parents 4df025f + c255115 commit e5bc735
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ui_test"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A test framework for testing rustc diagnostics output"
Expand Down
19 changes: 6 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use bstr::ByteSlice;
pub use color_eyre;
use color_eyre::eyre::{eyre, Context, Result};
use color_eyre::eyre::{eyre, Result};
use crossbeam_channel::unbounded;
use parser::{ErrorMatch, Pattern, Revisioned};
use regex::bytes::Regex;
Expand Down Expand Up @@ -355,9 +355,9 @@ pub fn run_tests(config: Config) -> Result<()> {
)
}

/// Run a single file, with the settings from the `config` argument. Ignores various
/// settings from `Config` that relate to finding test files.
pub fn run_file(mut config: Config, path: &Path) -> Result<std::process::Output> {
/// Create a command for running a single file, with the settings from the `config` argument.
/// Ignores various settings from `Config` that relate to finding test files.
pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
config.build_dependencies_and_link_them()?;

let comments =
Expand All @@ -370,16 +370,9 @@ pub fn run_file(mut config: Config, path: &Path) -> Result<std::process::Output>
&comments,
config.out_dir.as_deref(),
&mut errors,
)
.output()
.wrap_err_with(|| {
format!(
"path `{}` is not an executable",
config.program.program.display()
)
});
);
assert!(errors.is_empty(), "{errors:#?}");
result
Ok(result)
}

#[allow(clippy::large_enum_variant)]
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic-bin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail-mode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions tests/integrations/basic-fail-mode/tests/run_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ fn run_file() -> Result<()> {
let tmp_dir = tempfile::tempdir()?;
config.out_dir = Some(tmp_dir.path().into());

let result = ui_test::run_file(
let mut result = ui_test::test_command(
config,
&Path::new(file!())
.parent()
.unwrap()
.join("run_file/run_file.rs"),
)?;
ensure!(result.status.success(), "");
ensure!(result.output()?.status.success(), "");
Ok(())
}

Expand All @@ -25,13 +25,15 @@ fn fail_run_file() {
let mut config = Config::default();
config.program = CommandBuilder::cmd("invalid_alsdkfjalsdfjalskdfj");

let _ = ui_test::run_file(
let _ = ui_test::test_command(
config,
&Path::new(file!())
.parent()
.unwrap()
.join("run_file/run_file.rs"),
)
.unwrap()
.output()
.unwrap_err();
}

Expand All @@ -52,13 +54,13 @@ fn run_file_no_deps() -> Result<()> {
.envs
.push(("CARGO_TARGET_DIR".into(), Some(path.into())));

let result = ui_test::run_file(
let mut result = ui_test::test_command(
config,
&Path::new(file!())
.parent()
.unwrap()
.join("run_file/run_file_with_deps.rs"),
)?;
ensure!(result.status.success(), "");
ensure!(result.output()?.status.success(), "");
Ok(())
}
2 changes: 1 addition & 1 deletion tests/integrations/basic-fail/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/integrations/basic-fail/Cargo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ test result: FAIL. 6 tests failed, 0 tests passed, 0 ignored, 0 filtered out
Error: tests failed

Location:
$DIR/src/lib.rs:549:13
$DIR/src/lib.rs:542:13
error: test failed, to rerun pass `--test ui_tests`

Caused by:
Expand Down Expand Up @@ -434,7 +434,7 @@ test result: FAIL. 1 tests failed, 2 tests passed, 0 ignored, 0 filtered out
thread 'main' panicked at 'invalid mode/result combo: yolo: Err(tests failed

Location:
$DIR/src/lib.rs:549:13)', tests/ui_tests_bless.rs:56:18
$DIR/src/lib.rs:542:13)', tests/ui_tests_bless.rs:56:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: test failed, to rerun pass `--test ui_tests_bless`
Error: failed to parse rustc version info: invalid_foobarlaksdfalsdfj
Expand Down Expand Up @@ -528,7 +528,7 @@ test result: FAIL. 6 tests failed, 0 tests passed, 0 ignored, 0 filtered out
Error: tests failed

Location:
$DIR/src/lib.rs:549:13
$DIR/src/lib.rs:542:13
error: test failed, to rerun pass `--test ui_tests_invalid_program2`

Caused by:
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/integrations/basic/tests/run_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ fn run_file() -> Result<()> {
let tmp_dir = tempfile::tempdir()?;
config.out_dir = Some(tmp_dir.path().into());

let result = ui_test::run_file(
let mut result = ui_test::test_command(
config,
&Path::new(file!())
.parent()
.unwrap()
.join("run_file/run_file.rs"),
)?;
ensure!(result.status.success(), "");
ensure!(result.output()?.status.success(), "");
Ok(())
}

Expand All @@ -37,14 +37,14 @@ fn run_file_with_deps() -> Result<()> {
.envs
.push(("CARGO_TARGET_DIR".into(), Some(path.into())));

let result = ui_test::run_file(
let mut result = ui_test::test_command(
config,
&Path::new(file!())
.parent()
.unwrap()
.join("run_file/run_file_with_deps.rs"),
)?;
ensure!(result.status.success(), "");
ensure!(result.output()?.status.success(), "");
Ok(())
}

Expand All @@ -61,7 +61,7 @@ fn non_utf8() -> Result<()> {
config.program = CommandBuilder::cmd("cat");
config.edition = None;

let result = ui_test::run_file(config, &path)?;
ensure!(result.status.success(), "");
let mut result = ui_test::test_command(config, &path)?;
ensure!(result.output()?.status.success(), "");
Ok(())
}

0 comments on commit e5bc735

Please sign in to comment.