Skip to content

Commit 81ad840

Browse files
committed
feat: pass runner commands as strings
use shlex to parse a user defined string into shell args that can be passed to duct. Main driver is a better ux
1 parent 39db1f4 commit 81ad840

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ regex = "1.11.1"
3737

3838
# Used to easily deserialize the TOML configuration file
3939
serde = { version = "1.0.216", features = ["derive"] }
40+
shlex = "1.3.0"
4041

4142
# Used to parse the TOML configuration file
4243
toml = "0.8.19"

docs/configuration.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ See [templates documentation](./templates.md) for more information on the expect
154154

155155
#### command
156156

157-
The `command` field is used to define the command to run the test. This should just be the name of the executable.
158-
159-
#### args
160-
161-
The `args` field is used to define the arguments to pass to the test command.
157+
The `command` field is used to define the command to run the test.
162158

163159
#### fail_regex_template
164160

examples/shapes/polytest.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ template_dir = "./templates/minitest_unit"
8484
fail_regex_template = "Test{{ suite_name | convert_case('Pascal') }}#test_{{ test_name }} = \\d+\\.\\d+ s = (F|E)"
8585
pass_regex_template = "Test{{ suite_name | convert_case('Pascal') }}#test_{{ test_name }} = \\d+\\.\\d+ s = \\."
8686

87-
command = "bundle"
88-
args = ["exec", "rake", "test", "A='--verbose'"]
87+
command = "bundle exec rake test A='--verbose'"
8988

9089
# Custom Document
9190

src/main.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ impl ConfigMeta {
8787
#[derive(Deserialize, Debug, Clone)]
8888
struct RunnerConfig {
8989
command: String,
90-
args: Vec<String>,
9190
fail_regex_template: String,
9291
pass_regex_template: String,
9392
env: Option<HashMap<String, String>>,
@@ -96,7 +95,6 @@ struct RunnerConfig {
9695
#[derive(Deserialize, Debug, Clone)]
9796
struct Runner {
9897
command: String,
99-
args: Vec<String>,
10098
fail_regex_template: String,
10199
pass_regex_template: String,
102100
env: Option<HashMap<String, String>>,
@@ -106,7 +104,6 @@ impl Runner {
106104
fn from_config(config: &RunnerConfig) -> Self {
107105
Self {
108106
command: config.command.clone(),
109-
args: config.args.clone(),
110107
fail_regex_template: "(?m)".to_owned() + config.fail_regex_template.as_str(),
111108
pass_regex_template: "(?m)".to_owned() + config.pass_regex_template.as_str(),
112109
env: config.env.clone(),
@@ -200,8 +197,7 @@ impl Target {
200197
.to_string(),
201198
runner: Runner {
202199
env: None,
203-
command: "pytest".to_string(),
204-
args: vec!["-v".to_string()],
200+
command: "pytest -v".to_string(),
205201
fail_regex_template:
206202
r"(?m){{ file_name }}::test_{{ test_name }} FAILED".to_string(),
207203
pass_regex_template:
@@ -223,8 +219,7 @@ impl Target {
223219
test_template: include_str!("../templates/bun/test.ts.jinja").to_string(),
224220
runner: Runner {
225221
env: None,
226-
command: "bun".to_string(),
227-
args: vec!["test".to_string()],
222+
command: "bun test".to_string(),
228223
fail_regex_template: r"(?m)\(fail\) {{ suite_name }} > {{ group_name }} > {{ test_name }}( \[\d+\.\d+ms])*$".to_string(),
229224
pass_regex_template: r"(?m)\(pass\) {{ suite_name }} > {{ group_name }} > {{ test_name }}( \[\d+\.\d+ms])*$".to_string(),
230225
},
@@ -548,12 +543,10 @@ fn main() -> Result<()> {
548543
for target in &targets {
549544
let runner = target.runner.clone();
550545

551-
println!(
552-
"Running {}: {} {:?}",
553-
target.id, runner.command, runner.args
554-
);
546+
println!("Running {}: {}", target.id, runner.command);
555547

556-
let mut runner_cmd = cmd(runner.command, &runner.args[..]).dir(&target.out_dir);
548+
let parsed_cmd: Vec<String> = shlex::Shlex::new(runner.command.as_str()).collect();
549+
let mut runner_cmd = cmd(&parsed_cmd[0], &parsed_cmd[1..]).dir(&target.out_dir);
557550
if let Some(env) = runner.env {
558551
for (key, value) in env {
559552
runner_cmd = runner_cmd.env(key, value);

0 commit comments

Comments
 (0)