add test for condition_script_runner_args expansion and script_runner_args expansion

This commit is contained in:
Melvin Wang
2024-08-01 11:14:51 -07:00
parent 53e7f319b5
commit d5541e9f34
4 changed files with 86 additions and 2 deletions
Generated
+1
View File
@@ -178,6 +178,7 @@ dependencies = [
"shell2batch",
"strip-ansi-escapes",
"strum_macros",
"tempfile",
"toml",
]
+2 -1
View File
@@ -80,8 +80,9 @@ strum_macros = "0.26.4"
toml = "^0.8"
[dev-dependencies]
expect-test = "^1"
cfg-if = "^1.0.0"
expect-test = "^1"
tempfile = "^3.10.1"
[target.'cfg(windows)'.dependencies]
nu-ansi-term = "^0.50"
+82
View File
@@ -1,3 +1,5 @@
use std::fs;
use super::*;
use crate::test;
use crate::types::{
@@ -7,6 +9,7 @@ use crate::types::{
use cfg_if::cfg_if;
use git_info::types::GitInfo;
use rust_info::types::RustInfo;
use tempfile::tempdir;
#[cfg(target_os = "linux")]
use crate::types::WatchOptions;
@@ -895,6 +898,85 @@ fn run_task_deprecated_flag() {
run_task(&flow_info, Rc::new(RefCell::new(FlowState::new())), &step).unwrap();
}
#[test]
#[ignore]
fn run_task_rust_script_with_args_and_rust_condition_script_with_args() {
// TODO: this relies on https://github.com/fornwall/rust-script/pull/136 merging, and a new version being released
// TODO: enforce min rust-script version here
let dummy_path = "dummy/path";
// Create temporary directory to store outputs of condition script and script
let output_dir = tempdir().unwrap();
let condition_script_output_file = output_dir.path().join("condition-script-output.txt");
let script_output_file = output_dir.path().join("script-output.txt");
let flow_info = FlowInfo {
config: Config::default(),
task: "test".to_string(),
env_info: EnvInfo {
rust_info: RustInfo::new(),
crate_info: CrateInfo::new(),
git_info: GitInfo::new(),
ci_info: ci_info::get(),
},
disable_workspace: false,
disable_on_error: false,
allow_private: false,
skip_init_end_tasks: false,
skip_tasks_pattern: None,
cli_arguments: None,
};
let step = Step {
name: "test".to_string(),
config: Task {
condition_script_runner_args: Some(
["--base-path", &dummy_path]
.iter()
.map(ToString::to_string)
.collect(),
),
condition_script: Some(ConditionScriptValue::SingleLine(format!(
r##"#!@rust
#![allow(unused_doc_comments)]
let base_path = std::env::var("RUST_SCRIPT_BASE_PATH").expect("RUST_SCRIPT_BASE_PATH should always be set by rust-script");
std::fs::write(r#"{}"#, base_path)?
"##,
condition_script_output_file.to_str().unwrap()
))),
script_runner_args: Some(
["--base-path", &dummy_path]
.iter()
.map(ToString::to_string)
.collect(),
),
script: Some(ScriptValue::SingleLine(format!(
r##"#!@rust
#![allow(unused_doc_comments)]
let base_path = std::env::var("RUST_SCRIPT_BASE_PATH").expect("RUST_SCRIPT_BASE_PATH should always be set by rust-script");
std::fs::write(r#"{}"#, base_path)?
"##,
script_output_file.to_str().unwrap()
))),
..Default::default()
},
};
run_task(&flow_info, Rc::new(RefCell::new(FlowState::new())), &step).unwrap();
// Check that condition_script_args are expanded
let condition_script_output = fs::read_to_string(&condition_script_output_file)
.expect("condition_script should have created this file");
assert_eq!(condition_script_output, dummy_path);
// Check that script_args are expanded
let script_output =
fs::read_to_string(&script_output_file).expect("script should have created this file");
assert_eq!(script_output, dummy_path);
}
#[test]
#[ignore]
fn should_watch_none_and_env_not_set() {
+1 -1
View File
@@ -2359,7 +2359,7 @@ impl ConfigSection {
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
/// Holds the entire configuration such as task definitions and env vars
pub struct Config {
/// Runtime config