2024-03-13 12:21:13 -04:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2024-03-13 22:15:39 -04:00
|
|
|
use std::cell::RefCell;
|
2024-05-03 00:49:42 -04:00
|
|
|
use std::collections::BTreeMap;
|
2024-03-15 15:46:51 -04:00
|
|
|
use std::collections::HashMap;
|
2024-03-13 12:21:13 -04:00
|
|
|
use std::collections::HashSet;
|
2024-03-13 22:15:39 -04:00
|
|
|
use std::panic::AssertUnwindSafe;
|
|
|
|
use std::rc::Rc;
|
2024-03-13 12:21:13 -04:00
|
|
|
|
|
|
|
use deno_core::anyhow::Context;
|
|
|
|
use deno_core::serde_json;
|
2024-04-15 17:50:52 -04:00
|
|
|
use file_test_runner::collection::collect_tests_or_exit;
|
2024-05-03 00:49:42 -04:00
|
|
|
use file_test_runner::collection::strategies::FileTestMapperStrategy;
|
2024-04-15 17:50:52 -04:00
|
|
|
use file_test_runner::collection::strategies::TestPerDirectoryCollectionStrategy;
|
|
|
|
use file_test_runner::collection::CollectOptions;
|
2024-05-03 00:49:42 -04:00
|
|
|
use file_test_runner::collection::CollectTestsError;
|
|
|
|
use file_test_runner::collection::CollectedCategoryOrTest;
|
2024-04-15 17:50:52 -04:00
|
|
|
use file_test_runner::collection::CollectedTest;
|
2024-05-03 00:49:42 -04:00
|
|
|
use file_test_runner::collection::CollectedTestCategory;
|
|
|
|
use file_test_runner::TestResult;
|
2024-06-06 08:37:13 -04:00
|
|
|
use once_cell::sync::Lazy;
|
2024-03-13 12:21:13 -04:00
|
|
|
use serde::Deserialize;
|
|
|
|
use test_util::tests_path;
|
|
|
|
use test_util::PathRef;
|
|
|
|
use test_util::TestContextBuilder;
|
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
const MANIFEST_FILE_NAME: &str = "__test__.jsonc";
|
2024-03-13 12:21:13 -04:00
|
|
|
|
2024-06-06 08:37:13 -04:00
|
|
|
static NO_CAPTURE: Lazy<bool> =
|
|
|
|
Lazy::new(|| std::env::args().any(|arg| arg == "--nocapture"));
|
|
|
|
|
2024-03-13 12:21:13 -04:00
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
enum VecOrString {
|
|
|
|
Vec(Vec<String>),
|
|
|
|
String(String),
|
|
|
|
}
|
|
|
|
|
2024-05-03 00:49:42 -04:00
|
|
|
type JsonMap = serde_json::Map<String, serde_json::Value>;
|
|
|
|
|
2024-03-13 12:21:13 -04:00
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
|
|
|
struct MultiTestMetaData {
|
|
|
|
/// Whether to copy all the non-assertion files in the current
|
|
|
|
/// test directory to a temporary directory before running the
|
|
|
|
/// steps.
|
|
|
|
#[serde(default)]
|
|
|
|
pub temp_dir: bool,
|
|
|
|
/// The base environment to use for the test.
|
|
|
|
#[serde(default)]
|
|
|
|
pub base: Option<String>,
|
2024-04-01 18:58:52 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub envs: HashMap<String, String>,
|
2024-05-03 00:49:42 -04:00
|
|
|
#[serde(default)]
|
2024-08-20 10:11:43 -04:00
|
|
|
pub cwd: Option<String>,
|
|
|
|
#[serde(default)]
|
2024-05-03 00:49:42 -04:00
|
|
|
pub tests: BTreeMap<String, JsonMap>,
|
2024-08-27 20:19:29 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub ignore: bool,
|
2024-05-03 00:49:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MultiTestMetaData {
|
|
|
|
pub fn into_collected_tests(
|
|
|
|
mut self,
|
|
|
|
parent_test: &CollectedTest,
|
|
|
|
) -> Vec<CollectedTest<serde_json::Value>> {
|
|
|
|
fn merge_json_value(
|
|
|
|
multi_test_meta_data: &MultiTestMetaData,
|
|
|
|
value: &mut JsonMap,
|
|
|
|
) {
|
|
|
|
if let Some(base) = &multi_test_meta_data.base {
|
|
|
|
if !value.contains_key("base") {
|
|
|
|
value.insert("base".to_string(), base.clone().into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if multi_test_meta_data.temp_dir && !value.contains_key("tempDir") {
|
|
|
|
value.insert("tempDir".to_string(), true.into());
|
|
|
|
}
|
2024-08-20 10:11:43 -04:00
|
|
|
if multi_test_meta_data.cwd.is_some() && !value.contains_key("cwd") {
|
|
|
|
value
|
|
|
|
.insert("cwd".to_string(), multi_test_meta_data.cwd.clone().into());
|
|
|
|
}
|
2024-05-03 00:49:42 -04:00
|
|
|
if !multi_test_meta_data.envs.is_empty() {
|
|
|
|
if !value.contains_key("envs") {
|
|
|
|
value.insert("envs".to_string(), JsonMap::default().into());
|
|
|
|
}
|
|
|
|
let envs_obj = value.get_mut("envs").unwrap().as_object_mut().unwrap();
|
|
|
|
for (key, value) in &multi_test_meta_data.envs {
|
|
|
|
if !envs_obj.contains_key(key) {
|
|
|
|
envs_obj.insert(key.into(), value.clone().into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-27 20:19:29 -04:00
|
|
|
if multi_test_meta_data.ignore && !value.contains_key("ignore") {
|
|
|
|
value.insert("ignore".to_string(), true.into());
|
|
|
|
}
|
2024-05-03 00:49:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut collected_tests = Vec::with_capacity(self.tests.len());
|
|
|
|
for (name, mut json_data) in std::mem::take(&mut self.tests) {
|
|
|
|
merge_json_value(&self, &mut json_data);
|
|
|
|
collected_tests.push(CollectedTest {
|
|
|
|
name: format!("{}::{}", parent_test.name, name),
|
|
|
|
path: parent_test.path.clone(),
|
|
|
|
data: serde_json::Value::Object(json_data),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
collected_tests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
|
|
|
struct MultiStepMetaData {
|
|
|
|
/// Whether to copy all the non-assertion files in the current
|
|
|
|
/// test directory to a temporary directory before running the
|
|
|
|
/// steps.
|
|
|
|
#[serde(default)]
|
|
|
|
pub temp_dir: bool,
|
2024-11-13 10:10:09 -05:00
|
|
|
/// Whether the temporary directory should be symlinked to another path.
|
|
|
|
#[serde(default)]
|
|
|
|
pub symlinked_temp_dir: bool,
|
2024-05-03 00:49:42 -04:00
|
|
|
/// The base environment to use for the test.
|
|
|
|
#[serde(default)]
|
|
|
|
pub base: Option<String>,
|
|
|
|
#[serde(default)]
|
2024-08-20 10:11:43 -04:00
|
|
|
pub cwd: Option<String>,
|
|
|
|
#[serde(default)]
|
2024-05-03 00:49:42 -04:00
|
|
|
pub envs: HashMap<String, String>,
|
|
|
|
#[serde(default)]
|
2024-06-05 11:04:16 -04:00
|
|
|
pub repeat: Option<usize>,
|
|
|
|
#[serde(default)]
|
2024-03-13 12:21:13 -04:00
|
|
|
pub steps: Vec<StepMetaData>,
|
2024-08-27 20:19:29 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub ignore: bool,
|
2024-03-13 12:21:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
|
|
|
struct SingleTestMetaData {
|
|
|
|
#[serde(default)]
|
|
|
|
pub base: Option<String>,
|
|
|
|
#[serde(default)]
|
|
|
|
pub temp_dir: bool,
|
2024-06-05 11:04:16 -04:00
|
|
|
#[serde(default)]
|
2024-11-13 10:10:09 -05:00
|
|
|
pub symlinked_temp_dir: bool,
|
|
|
|
#[serde(default)]
|
2024-06-05 11:04:16 -04:00
|
|
|
pub repeat: Option<usize>,
|
2024-03-13 12:21:13 -04:00
|
|
|
#[serde(flatten)]
|
|
|
|
pub step: StepMetaData,
|
2024-08-27 20:19:29 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub ignore: bool,
|
2024-03-13 12:21:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SingleTestMetaData {
|
2024-05-03 00:49:42 -04:00
|
|
|
pub fn into_multi(self) -> MultiStepMetaData {
|
|
|
|
MultiStepMetaData {
|
2024-03-13 12:21:13 -04:00
|
|
|
base: self.base,
|
2024-08-20 10:11:43 -04:00
|
|
|
cwd: None,
|
2024-03-13 12:21:13 -04:00
|
|
|
temp_dir: self.temp_dir,
|
2024-11-13 10:10:09 -05:00
|
|
|
symlinked_temp_dir: self.symlinked_temp_dir,
|
2024-06-05 11:04:16 -04:00
|
|
|
repeat: self.repeat,
|
2024-04-01 18:58:52 -04:00
|
|
|
envs: Default::default(),
|
2024-03-13 12:21:13 -04:00
|
|
|
steps: vec![self.step],
|
2024-08-27 20:19:29 -04:00
|
|
|
ignore: self.ignore,
|
2024-03-13 12:21:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
|
|
|
struct StepMetaData {
|
2024-04-29 10:08:27 -04:00
|
|
|
/// If the test should be retried multiple times on failure.
|
|
|
|
#[serde(default)]
|
|
|
|
pub flaky: bool,
|
2024-03-13 12:21:13 -04:00
|
|
|
pub args: VecOrString,
|
2024-03-25 18:20:15 -04:00
|
|
|
pub cwd: Option<String>,
|
2024-04-27 17:11:57 -04:00
|
|
|
#[serde(rename = "if")]
|
|
|
|
pub if_cond: Option<String>,
|
2024-04-15 17:50:52 -04:00
|
|
|
pub command_name: Option<String>,
|
2024-03-15 15:46:51 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub envs: HashMap<String, String>,
|
2024-09-18 15:15:13 -04:00
|
|
|
pub input: Option<String>,
|
2024-03-13 12:21:13 -04:00
|
|
|
pub output: String,
|
|
|
|
#[serde(default)]
|
|
|
|
pub exit_code: i32,
|
|
|
|
}
|
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
pub fn main() {
|
2024-05-03 00:49:42 -04:00
|
|
|
let root_category =
|
|
|
|
collect_tests_or_exit::<serde_json::Value>(CollectOptions {
|
|
|
|
base: tests_path().join("specs").to_path_buf(),
|
|
|
|
strategy: Box::new(FileTestMapperStrategy {
|
|
|
|
base_strategy: TestPerDirectoryCollectionStrategy {
|
|
|
|
file_name: MANIFEST_FILE_NAME.to_string(),
|
|
|
|
},
|
|
|
|
map: map_test_within_file,
|
|
|
|
}),
|
|
|
|
filter_override: None,
|
|
|
|
});
|
2024-04-12 17:58:40 -04:00
|
|
|
|
|
|
|
if root_category.is_empty() {
|
|
|
|
return; // all tests filtered out
|
2024-03-13 22:15:39 -04:00
|
|
|
}
|
2024-04-12 17:58:40 -04:00
|
|
|
|
|
|
|
let _http_guard = test_util::http_server();
|
|
|
|
file_test_runner::run_tests(
|
|
|
|
&root_category,
|
2024-06-06 08:37:13 -04:00
|
|
|
file_test_runner::RunOptions {
|
|
|
|
parallel: !*NO_CAPTURE,
|
|
|
|
},
|
2024-05-13 18:55:14 -04:00
|
|
|
run_test,
|
2024-04-12 17:58:40 -04:00
|
|
|
);
|
2024-03-13 22:15:39 -04:00
|
|
|
}
|
|
|
|
|
2024-05-03 00:49:42 -04:00
|
|
|
/// Maps a __test__.jsonc file to a category of tests if it contains a "test" object.
|
|
|
|
fn map_test_within_file(
|
|
|
|
test: CollectedTest,
|
|
|
|
) -> Result<CollectedCategoryOrTest<serde_json::Value>, CollectTestsError> {
|
|
|
|
let test_path = PathRef::new(&test.path);
|
|
|
|
let metadata_value = test_path.read_jsonc_value();
|
|
|
|
if metadata_value
|
|
|
|
.as_object()
|
|
|
|
.map(|o| o.contains_key("tests"))
|
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
|
|
|
let data: MultiTestMetaData = serde_json::from_value(metadata_value)
|
|
|
|
.with_context(|| format!("Failed deserializing {}", test_path))
|
|
|
|
.map_err(CollectTestsError::Other)?;
|
|
|
|
Ok(CollectedCategoryOrTest::Category(CollectedTestCategory {
|
|
|
|
children: data
|
|
|
|
.into_collected_tests(&test)
|
|
|
|
.into_iter()
|
|
|
|
.map(CollectedCategoryOrTest::Test)
|
|
|
|
.collect(),
|
|
|
|
name: test.name,
|
|
|
|
path: test.path,
|
|
|
|
}))
|
|
|
|
} else {
|
|
|
|
Ok(CollectedCategoryOrTest::Test(CollectedTest {
|
|
|
|
name: test.name,
|
|
|
|
path: test.path,
|
|
|
|
data: metadata_value,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_test(test: &CollectedTest<serde_json::Value>) -> TestResult {
|
|
|
|
let cwd = PathRef::new(&test.path).parent();
|
|
|
|
let metadata_value = test.data.clone();
|
|
|
|
let diagnostic_logger = Rc::new(RefCell::new(Vec::<u8>::new()));
|
2024-06-05 11:04:16 -04:00
|
|
|
let result = TestResult::from_maybe_panic_or_result(AssertUnwindSafe(|| {
|
|
|
|
let metadata = deserialize_value(metadata_value);
|
2024-08-27 20:19:29 -04:00
|
|
|
if metadata.ignore {
|
|
|
|
TestResult::Ignored
|
|
|
|
} else if let Some(repeat) = metadata.repeat {
|
2024-11-26 19:32:30 -05:00
|
|
|
for _ in 0..repeat {
|
|
|
|
run_test_inner(&metadata, &cwd, diagnostic_logger.clone());
|
|
|
|
}
|
|
|
|
TestResult::Passed
|
2024-06-05 11:04:16 -04:00
|
|
|
} else {
|
|
|
|
run_test_inner(&metadata, &cwd, diagnostic_logger.clone());
|
|
|
|
TestResult::Passed
|
|
|
|
}
|
2024-05-03 00:49:42 -04:00
|
|
|
}));
|
|
|
|
match result {
|
|
|
|
TestResult::Failed {
|
|
|
|
output: panic_output,
|
|
|
|
} => {
|
|
|
|
let mut output = diagnostic_logger.borrow().clone();
|
|
|
|
output.push(b'\n');
|
|
|
|
output.extend(panic_output);
|
|
|
|
TestResult::Failed { output }
|
|
|
|
}
|
|
|
|
TestResult::Passed | TestResult::Ignored | TestResult::SubTests(_) => {
|
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_test_inner(
|
2024-06-05 11:04:16 -04:00
|
|
|
metadata: &MultiStepMetaData,
|
2024-05-03 00:49:42 -04:00
|
|
|
cwd: &PathRef,
|
|
|
|
diagnostic_logger: Rc<RefCell<Vec<u8>>>,
|
|
|
|
) {
|
2024-06-05 11:04:16 -04:00
|
|
|
let context = test_context_from_metadata(metadata, cwd, diagnostic_logger);
|
2024-05-03 00:49:42 -04:00
|
|
|
for step in metadata.steps.iter().filter(|s| should_run_step(s)) {
|
2024-06-05 11:04:16 -04:00
|
|
|
let run_func = || run_step(step, metadata, cwd, &context);
|
2024-05-03 00:49:42 -04:00
|
|
|
if step.flaky {
|
|
|
|
run_flaky(run_func);
|
|
|
|
} else {
|
|
|
|
run_func();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deserialize_value(metadata_value: serde_json::Value) -> MultiStepMetaData {
|
2024-04-12 17:58:40 -04:00
|
|
|
// checking for "steps" leads to a more targeted error message
|
|
|
|
// instead of when deserializing an untagged enum
|
2024-05-03 00:49:42 -04:00
|
|
|
if metadata_value
|
2024-04-12 17:58:40 -04:00
|
|
|
.as_object()
|
2024-05-03 00:49:42 -04:00
|
|
|
.map(|o| o.contains_key("steps"))
|
|
|
|
.unwrap_or(false)
|
2024-04-12 17:58:40 -04:00
|
|
|
{
|
2024-05-03 00:49:42 -04:00
|
|
|
serde_json::from_value::<MultiStepMetaData>(metadata_value)
|
2024-04-12 17:58:40 -04:00
|
|
|
} else {
|
|
|
|
serde_json::from_value::<SingleTestMetaData>(metadata_value)
|
|
|
|
.map(|s| s.into_multi())
|
2024-03-13 12:21:13 -04:00
|
|
|
}
|
2024-05-03 00:49:42 -04:00
|
|
|
.context("Failed to parse test spec")
|
|
|
|
.unwrap()
|
|
|
|
}
|
2024-03-13 12:21:13 -04:00
|
|
|
|
2024-05-03 00:49:42 -04:00
|
|
|
fn test_context_from_metadata(
|
|
|
|
metadata: &MultiStepMetaData,
|
|
|
|
cwd: &PathRef,
|
|
|
|
diagnostic_logger: Rc<RefCell<Vec<u8>>>,
|
|
|
|
) -> test_util::TestContext {
|
2024-04-12 17:58:40 -04:00
|
|
|
let mut builder = TestContextBuilder::new();
|
|
|
|
builder = builder.logging_capture(diagnostic_logger);
|
2024-03-13 12:21:13 -04:00
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
if metadata.temp_dir {
|
|
|
|
builder = builder.use_temp_cwd();
|
|
|
|
} else {
|
|
|
|
builder = builder.cwd(cwd.to_string_lossy());
|
2024-03-13 12:21:13 -04:00
|
|
|
}
|
|
|
|
|
2024-11-13 10:10:09 -05:00
|
|
|
if metadata.symlinked_temp_dir {
|
|
|
|
// not actually deprecated, we just want to discourage its use
|
|
|
|
// because it's mostly used for testing purposes locally
|
|
|
|
#[allow(deprecated)]
|
|
|
|
{
|
|
|
|
builder = builder.use_symlinked_temp_dir();
|
|
|
|
}
|
|
|
|
if cfg!(not(debug_assertions)) {
|
|
|
|
// panic to prevent using this on the CI as CI already uses
|
|
|
|
// a symlinked temp directory for every test
|
|
|
|
panic!("Cannot use symlinkedTempDir in release mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
match &metadata.base {
|
|
|
|
// todo(dsherret): add bases in the future as needed
|
|
|
|
Some(base) => panic!("Unknown test base: {}", base),
|
|
|
|
None => {
|
2024-04-27 17:11:57 -04:00
|
|
|
// by default add all these
|
|
|
|
builder = builder
|
|
|
|
.add_jsr_env_vars()
|
|
|
|
.add_npm_env_vars()
|
|
|
|
.add_compile_env_vars();
|
2024-03-13 12:21:13 -04:00
|
|
|
}
|
2024-04-12 17:58:40 -04:00
|
|
|
}
|
2024-03-13 12:21:13 -04:00
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
let context = builder.build();
|
2024-03-25 18:20:15 -04:00
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
if metadata.temp_dir {
|
|
|
|
// copy all the files in the cwd to a temp directory
|
|
|
|
// excluding the metadata and assertion files
|
|
|
|
let temp_dir = context.temp_dir().path();
|
2024-05-03 00:49:42 -04:00
|
|
|
let assertion_paths = resolve_test_and_assertion_files(cwd, metadata);
|
2024-04-12 17:58:40 -04:00
|
|
|
cwd.copy_to_recursive_with_exclusions(temp_dir, &assertion_paths);
|
|
|
|
}
|
2024-05-03 00:49:42 -04:00
|
|
|
context
|
2024-04-12 17:58:40 -04:00
|
|
|
}
|
|
|
|
|
2024-04-27 17:11:57 -04:00
|
|
|
fn should_run_step(step: &StepMetaData) -> bool {
|
|
|
|
if let Some(cond) = &step.if_cond {
|
|
|
|
match cond.as_str() {
|
|
|
|
"windows" => cfg!(windows),
|
|
|
|
"unix" => cfg!(unix),
|
|
|
|
"mac" => cfg!(target_os = "macos"),
|
|
|
|
"linux" => cfg!(target_os = "linux"),
|
|
|
|
value => panic!("Unknown if condition: {}", value),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-29 10:08:27 -04:00
|
|
|
fn run_flaky(action: impl Fn()) {
|
|
|
|
for _ in 0..2 {
|
|
|
|
let result = std::panic::catch_unwind(AssertUnwindSafe(&action));
|
|
|
|
if result.is_ok() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// surface error on third try
|
|
|
|
action();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_step(
|
|
|
|
step: &StepMetaData,
|
2024-05-03 00:49:42 -04:00
|
|
|
metadata: &MultiStepMetaData,
|
2024-04-29 10:08:27 -04:00
|
|
|
cwd: &PathRef,
|
|
|
|
context: &test_util::TestContext,
|
|
|
|
) {
|
|
|
|
let command = context
|
|
|
|
.new_command()
|
|
|
|
.envs(metadata.envs.iter().chain(step.envs.iter()));
|
|
|
|
let command = match &step.args {
|
|
|
|
VecOrString::Vec(args) => command.args_vec(args),
|
|
|
|
VecOrString::String(text) => command.args(text),
|
|
|
|
};
|
2024-08-20 10:11:43 -04:00
|
|
|
let command = match step.cwd.as_ref().or(metadata.cwd.as_ref()) {
|
2024-04-29 10:08:27 -04:00
|
|
|
Some(cwd) => command.current_dir(cwd),
|
|
|
|
None => command,
|
|
|
|
};
|
|
|
|
let command = match &step.command_name {
|
|
|
|
Some(command_name) => command.name(command_name),
|
|
|
|
None => command,
|
|
|
|
};
|
2024-06-06 08:37:13 -04:00
|
|
|
let command = match *NO_CAPTURE {
|
|
|
|
// deprecated is only to prevent use, so this is fine here
|
|
|
|
#[allow(deprecated)]
|
|
|
|
true => command.show_output(),
|
|
|
|
false => command,
|
|
|
|
};
|
2024-09-18 15:15:13 -04:00
|
|
|
let command = match &step.input {
|
|
|
|
Some(input) => command.stdin_text(input),
|
|
|
|
None => command,
|
|
|
|
};
|
2024-04-29 10:08:27 -04:00
|
|
|
let output = command.run();
|
|
|
|
if step.output.ends_with(".out") {
|
|
|
|
let test_output_path = cwd.join(&step.output);
|
|
|
|
output.assert_matches_file(test_output_path);
|
|
|
|
} else {
|
|
|
|
output.assert_matches_text(&step.output);
|
|
|
|
}
|
|
|
|
output.assert_exit_code(step.exit_code);
|
|
|
|
}
|
|
|
|
|
2024-04-12 17:58:40 -04:00
|
|
|
fn resolve_test_and_assertion_files(
|
|
|
|
dir: &PathRef,
|
2024-05-03 00:49:42 -04:00
|
|
|
metadata: &MultiStepMetaData,
|
2024-04-12 17:58:40 -04:00
|
|
|
) -> HashSet<PathRef> {
|
|
|
|
let mut result = HashSet::with_capacity(metadata.steps.len() + 1);
|
|
|
|
result.insert(dir.join(MANIFEST_FILE_NAME));
|
|
|
|
result.extend(metadata.steps.iter().map(|step| dir.join(&step.output)));
|
2024-03-13 12:21:13 -04:00
|
|
|
result
|
|
|
|
}
|