From e1c7252d37f749e79dfab337c2cacbc120cfb767 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 30 Jan 2026 09:06:59 -0600 Subject: [PATCH 1/2] fix double parens issue --- src/formatting.rs | 10 +- tests/fixtures/expected/issue76.nu | 1 + tests/fixtures/expected/subexpression.nu | 1 + tests/fixtures/input/issue76.nu | 1 + tests/fixtures/input/subexpression.nu | 1 + tests/ground_truth.rs | 332 ++++++++++++++--------- tests/main.rs | 37 +-- 7 files changed, 242 insertions(+), 141 deletions(-) create mode 100644 tests/fixtures/expected/issue76.nu create mode 100644 tests/fixtures/input/issue76.nu diff --git a/src/formatting.rs b/src/formatting.rs index 6450df9..562740a 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -674,8 +674,16 @@ impl<'a> Formatter<'a> { /// Format a subexpression fn format_subexpression(&mut self, block_id: nu_protocol::BlockId) { - self.write("("); let block = self.working_set.get_block(block_id); + // Special case: subexpressions containing only a string interpolation don't need parentheses + if block.pipelines.len() == 1 && block.pipelines[0].elements.len() == 1 { + if let Expr::StringInterpolation(_) = &block.pipelines[0].elements[0].expr.expr { + self.format_block(block); + return; + } + } + + self.write("("); let is_simple = block.pipelines.len() == 1 && block.pipelines[0].elements.len() <= 3; if is_simple { diff --git a/tests/fixtures/expected/issue76.nu b/tests/fixtures/expected/issue76.nu new file mode 100644 index 0000000..89ca911 --- /dev/null +++ b/tests/fixtures/expected/issue76.nu @@ -0,0 +1 @@ +def pretty-print-command [] { ($"`(ansi default_dimmed)(ansi default_italic)($in)(ansi reset)`") } \ No newline at end of file diff --git a/tests/fixtures/expected/subexpression.nu b/tests/fixtures/expected/subexpression.nu index 3e1cd40..ece5e8c 100644 --- a/tests/fixtures/expected/subexpression.nu +++ b/tests/fixtures/expected/subexpression.nu @@ -8,4 +8,5 @@ let result = (1 + 2) * 3 let value = ($x + (($y * 2))) print (echo "hello") +let msg = $"Hello ($name)" if (true) { print "yes" } diff --git a/tests/fixtures/input/issue76.nu b/tests/fixtures/input/issue76.nu new file mode 100644 index 0000000..89ca911 --- /dev/null +++ b/tests/fixtures/input/issue76.nu @@ -0,0 +1 @@ +def pretty-print-command [] { ($"`(ansi default_dimmed)(ansi default_italic)($in)(ansi reset)`") } \ No newline at end of file diff --git a/tests/fixtures/input/subexpression.nu b/tests/fixtures/input/subexpression.nu index 27a6625..8cf5470 100644 --- a/tests/fixtures/input/subexpression.nu +++ b/tests/fixtures/input/subexpression.nu @@ -8,4 +8,5 @@ let result = (1 + 2) * 3 let value = ($x + (($y * 2))) print (echo "hello") +let msg = ($"Hello ($name)") if (true) { print "yes" } diff --git a/tests/ground_truth.rs b/tests/ground_truth.rs index 813be50..0446f3d 100644 --- a/tests/ground_truth.rs +++ b/tests/ground_truth.rs @@ -7,10 +7,32 @@ use std::fs; use std::path::PathBuf; use std::process::Command; -const TEST_BINARY: &str = "target/debug/nufmt"; +/// Get the path to the test binary +pub fn get_test_binary() -> PathBuf { + let exe_name = if cfg!(windows) { "nufmt.exe" } else { "nufmt" }; + + // Try CARGO_TARGET_DIR first + if let Ok(target_dir) = std::env::var("CARGO_TARGET_DIR") { + let path = PathBuf::from(target_dir).join("debug").join(&exe_name); + if path.exists() { + return path.canonicalize().unwrap_or(path); + } + } + + // Try default target directory + let default_path = PathBuf::from("target").join("debug").join(&exe_name); + if default_path.exists() { + return default_path.canonicalize().unwrap_or(default_path); + } else { + panic!( + "Test binary not found. Please build the project first to create {:?}", + default_path + ); + } +} /// Helper to run the formatter on input and compare with expected output -fn run_ground_truth_test(name: &str) { +fn run_ground_truth_test(test_binary: &PathBuf, name: &str) { let input_path = PathBuf::from(format!("tests/fixtures/input/{}.nu", name)); let expected_path = PathBuf::from(format!("tests/fixtures/expected/{}.nu", name)); @@ -30,37 +52,10 @@ fn run_ground_truth_test(name: &str) { let input = fs::read_to_string(&input_path).expect("Failed to read input file"); // Run formatter via stdin - let output = Command::new(TEST_BINARY) - .arg("--stdin") - .stdin(std::process::Stdio::piped()) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()) - .spawn() - .expect("Failed to spawn nufmt"); - - use std::io::Write; - output - .stdin - .as_ref() - .unwrap() - .write_all(input.as_bytes()) - .expect("Failed to write to stdin"); - - let output = output.wait_with_output().expect("Failed to wait for nufmt"); - - // Check for errors - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr); - panic!( - "Formatter failed for {}: exit code {:?}\nstderr: {}", - name, - output.status.code(), - stderr - ); - } - - // Get formatted output - let formatted = String::from_utf8(output.stdout).expect("Invalid UTF-8 in output"); + let formatted = match format_via_stdin(&test_binary, &input) { + Ok(output) => output, + Err(err) => panic!("Formatter failed for {}: {}", name, err), + }; // Read expected output let expected = fs::read_to_string(&expected_path).expect("Failed to read expected file"); @@ -98,7 +93,7 @@ fn run_ground_truth_test(name: &str) { } /// Test that formatting is idempotent (formatting twice gives same result) -fn run_idempotency_test(name: &str) { +fn run_idempotency_test(test_binary: &PathBuf, name: &str) { let input_path = PathBuf::from(format!("tests/fixtures/input/{}.nu", name)); if !input_path.exists() { @@ -108,14 +103,14 @@ fn run_idempotency_test(name: &str) { let input = fs::read_to_string(&input_path).expect("Failed to read input file"); // First format - let first_output = format_via_stdin(&input); + let first_output = format_via_stdin(test_binary, &input); if first_output.is_err() { return; // Skip if formatting fails } let first = first_output.unwrap(); // Second format - let second_output = format_via_stdin(&first); + let second_output = format_via_stdin(test_binary, &first); if second_output.is_err() { panic!("Second format failed for {}, but first succeeded", name); } @@ -131,8 +126,8 @@ fn run_idempotency_test(name: &str) { } } -fn format_via_stdin(input: &str) -> Result { - let output = Command::new(TEST_BINARY) +fn format_via_stdin(test_binary: &PathBuf, input: &str) -> Result { + let output = Command::new(test_binary) .arg("--stdin") .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) @@ -163,22 +158,26 @@ fn format_via_stdin(input: &str) -> Result { #[test] fn ground_truth_let_statement() { - run_ground_truth_test("let_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "let_statement"); } #[test] fn ground_truth_mut_statement() { - run_ground_truth_test("mut_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "mut_statement"); } #[test] fn ground_truth_const_statement() { - run_ground_truth_test("const_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "const_statement"); } #[test] fn ground_truth_def_statement() { - run_ground_truth_test("def_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "def_statement"); } // ============================================================================ @@ -187,42 +186,50 @@ fn ground_truth_def_statement() { #[test] fn ground_truth_if_else() { - run_ground_truth_test("if_else"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "if_else"); } #[test] fn ground_truth_for_loop() { - run_ground_truth_test("for_loop"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "for_loop"); } #[test] fn ground_truth_while_loop() { - run_ground_truth_test("while_loop"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "while_loop"); } #[test] fn ground_truth_loop_statement() { - run_ground_truth_test("loop_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "loop_statement"); } #[test] fn ground_truth_match_expr() { - run_ground_truth_test("match_expr"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "match_expr"); } #[test] fn ground_truth_try_catch() { - run_ground_truth_test("try_catch"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "try_catch"); } #[test] fn ground_truth_break_continue() { - run_ground_truth_test("break_continue"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "break_continue"); } #[test] fn ground_truth_return_statement() { - run_ground_truth_test("return_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "return_statement"); } // ============================================================================ @@ -231,22 +238,26 @@ fn ground_truth_return_statement() { #[test] fn ground_truth_list() { - run_ground_truth_test("list"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "list"); } #[test] fn ground_truth_record() { - run_ground_truth_test("record"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "record"); } #[test] fn ground_truth_table() { - run_ground_truth_test("table"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "table"); } #[test] fn ground_truth_nested_structures() { - run_ground_truth_test("nested_structures"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "nested_structures"); } // ============================================================================ @@ -255,42 +266,50 @@ fn ground_truth_nested_structures() { #[test] fn ground_truth_pipeline() { - run_ground_truth_test("pipeline"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "pipeline"); } #[test] fn ground_truth_multiline_pipeline() { - run_ground_truth_test("multiline_pipeline"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "multiline_pipeline"); } #[test] fn ground_truth_closure() { - run_ground_truth_test("closure"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "closure"); } #[test] fn ground_truth_subexpression() { - run_ground_truth_test("subexpression"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "subexpression"); } #[test] fn ground_truth_binary_ops() { - run_ground_truth_test("binary_ops"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "binary_ops"); } #[test] fn ground_truth_range() { - run_ground_truth_test("range"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "range"); } #[test] fn ground_truth_cell_path() { - run_ground_truth_test("cell_path"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "cell_path"); } #[test] fn ground_truth_spread() { - run_ground_truth_test("spread"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "spread"); } // ============================================================================ @@ -299,12 +318,14 @@ fn ground_truth_spread() { #[test] fn ground_truth_string_interpolation() { - run_ground_truth_test("string_interpolation"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "string_interpolation"); } #[test] fn ground_truth_comment() { - run_ground_truth_test("comment"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "comment"); } // ============================================================================ @@ -313,22 +334,26 @@ fn ground_truth_comment() { #[test] fn ground_truth_value_with_unit() { - run_ground_truth_test("value_with_unit"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "value_with_unit"); } #[test] fn ground_truth_datetime() { - run_ground_truth_test("datetime"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "datetime"); } #[test] fn ground_truth_nothing() { - run_ground_truth_test("nothing"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "nothing"); } #[test] fn ground_truth_glob_pattern() { - run_ground_truth_test("glob_pattern"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "glob_pattern"); } // ============================================================================ @@ -337,32 +362,38 @@ fn ground_truth_glob_pattern() { #[test] fn ground_truth_module() { - run_ground_truth_test("module"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "module"); } #[test] fn ground_truth_use_statement() { - run_ground_truth_test("use_statement"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "use_statement"); } #[test] fn ground_truth_export() { - run_ground_truth_test("export"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "export"); } #[test] fn ground_truth_source() { - run_ground_truth_test("source"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "source"); } #[test] fn ground_truth_hide() { - run_ground_truth_test("hide"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "hide"); } #[test] fn ground_truth_overlay() { - run_ground_truth_test("overlay"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "overlay"); } // ============================================================================ @@ -371,17 +402,20 @@ fn ground_truth_overlay() { #[test] fn ground_truth_alias() { - run_ground_truth_test("alias"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "alias"); } #[test] fn ground_truth_extern() { - run_ground_truth_test("extern"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "extern"); } #[test] fn ground_truth_external_call() { - run_ground_truth_test("external_call"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "external_call"); } // ============================================================================ @@ -390,17 +424,20 @@ fn ground_truth_external_call() { #[test] fn ground_truth_do_block() { - run_ground_truth_test("do_block"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "do_block"); } #[test] fn ground_truth_where_clause() { - run_ground_truth_test("where_clause"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "where_clause"); } #[test] fn ground_truth_error_make() { - run_ground_truth_test("error_make"); + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "error_make"); } // ============================================================================ @@ -409,22 +446,26 @@ fn ground_truth_error_make() { #[test] fn idempotency_let_statement() { - run_idempotency_test("let_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "let_statement"); } #[test] fn idempotency_mut_statement() { - run_idempotency_test("mut_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "mut_statement"); } #[test] fn idempotency_const_statement() { - run_idempotency_test("const_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "const_statement"); } #[test] fn idempotency_def_statement() { - run_idempotency_test("def_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "def_statement"); } // ============================================================================ @@ -433,42 +474,50 @@ fn idempotency_def_statement() { #[test] fn idempotency_if_else() { - run_idempotency_test("if_else"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "if_else"); } #[test] fn idempotency_for_loop() { - run_idempotency_test("for_loop"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "for_loop"); } #[test] fn idempotency_while_loop() { - run_idempotency_test("while_loop"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "while_loop"); } #[test] fn idempotency_loop_statement() { - run_idempotency_test("loop_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "loop_statement"); } #[test] fn idempotency_match_expr() { - run_idempotency_test("match_expr"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "match_expr"); } #[test] fn idempotency_try_catch() { - run_idempotency_test("try_catch"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "try_catch"); } #[test] fn idempotency_break_continue() { - run_idempotency_test("break_continue"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "break_continue"); } #[test] fn idempotency_return_statement() { - run_idempotency_test("return_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "return_statement"); } // ============================================================================ @@ -477,22 +526,26 @@ fn idempotency_return_statement() { #[test] fn idempotency_list() { - run_idempotency_test("list"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "list"); } #[test] fn idempotency_record() { - run_idempotency_test("record"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "record"); } #[test] fn idempotency_table() { - run_idempotency_test("table"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "table"); } #[test] fn idempotency_nested_structures() { - run_idempotency_test("nested_structures"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "nested_structures"); } // ============================================================================ @@ -501,42 +554,50 @@ fn idempotency_nested_structures() { #[test] fn idempotency_pipeline() { - run_idempotency_test("pipeline"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "pipeline"); } #[test] fn idempotency_multiline_pipeline() { - run_idempotency_test("multiline_pipeline"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "multiline_pipeline"); } #[test] fn idempotency_closure() { - run_idempotency_test("closure"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "closure"); } #[test] fn idempotency_subexpression() { - run_idempotency_test("subexpression"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "subexpression"); } #[test] fn idempotency_binary_ops() { - run_idempotency_test("binary_ops"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "binary_ops"); } #[test] fn idempotency_range() { - run_idempotency_test("range"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "range"); } #[test] fn idempotency_cell_path() { - run_idempotency_test("cell_path"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "cell_path"); } #[test] fn idempotency_spread() { - run_idempotency_test("spread"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "spread"); } // ============================================================================ @@ -545,12 +606,14 @@ fn idempotency_spread() { #[test] fn idempotency_string_interpolation() { - run_idempotency_test("string_interpolation"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "string_interpolation"); } #[test] fn idempotency_comment() { - run_idempotency_test("comment"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "comment"); } // ============================================================================ @@ -559,22 +622,26 @@ fn idempotency_comment() { #[test] fn idempotency_value_with_unit() { - run_idempotency_test("value_with_unit"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "value_with_unit"); } #[test] fn idempotency_datetime() { - run_idempotency_test("datetime"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "datetime"); } #[test] fn idempotency_nothing() { - run_idempotency_test("nothing"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "nothing"); } #[test] fn idempotency_glob_pattern() { - run_idempotency_test("glob_pattern"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "glob_pattern"); } // ============================================================================ @@ -583,32 +650,38 @@ fn idempotency_glob_pattern() { #[test] fn idempotency_module() { - run_idempotency_test("module"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "module"); } #[test] fn idempotency_use_statement() { - run_idempotency_test("use_statement"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "use_statement"); } #[test] fn idempotency_export() { - run_idempotency_test("export"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "export"); } #[test] fn idempotency_source() { - run_idempotency_test("source"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "source"); } #[test] fn idempotency_hide() { - run_idempotency_test("hide"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "hide"); } #[test] fn idempotency_overlay() { - run_idempotency_test("overlay"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "overlay"); } // ============================================================================ @@ -617,17 +690,20 @@ fn idempotency_overlay() { #[test] fn idempotency_alias() { - run_idempotency_test("alias"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "alias"); } #[test] fn idempotency_extern() { - run_idempotency_test("extern"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "extern"); } #[test] fn idempotency_external_call() { - run_idempotency_test("external_call"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "external_call"); } // ============================================================================ @@ -636,15 +712,27 @@ fn idempotency_external_call() { #[test] fn idempotency_do_block() { - run_idempotency_test("do_block"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "do_block"); } #[test] fn idempotency_where_clause() { - run_idempotency_test("where_clause"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "where_clause"); } #[test] fn idempotency_error_make() { - run_idempotency_test("error_make"); + let test_binary = get_test_binary(); + run_idempotency_test(&test_binary, "error_make"); +} + +// ============================================================================ +// Issue Tests - +// ============================================================================ +#[test] +fn issue76_test() { + let test_binary = get_test_binary(); + run_ground_truth_test(&test_binary, "issue76"); } diff --git a/tests/main.rs b/tests/main.rs index 347530d..f493bdf 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -1,3 +1,5 @@ +mod ground_truth; +use ground_truth::get_test_binary; use std::{fs, path::PathBuf, process::Command}; use tempfile::tempdir; @@ -8,7 +10,6 @@ let one = 1 const VALID: &str = "# beginning of script comment let one = 1 "; -const TEST_BINARY: &str = "target/debug/nufmt"; #[test] fn failure_with_invalid_config() { @@ -16,7 +17,7 @@ fn failure_with_invalid_config() { let config_file = dir.path().join("nufmt.nuon"); fs::write(&config_file, r#"{unknown: 1}"#).unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--config") .arg(config_file.to_str().unwrap()) .arg(dir.path().to_str().unwrap()) @@ -30,7 +31,7 @@ fn failure_with_invalid_config() { #[test] fn failure_with_invalid_config_file() { - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--config") .arg("path/that/does/not/exist/nufmt.nuon") .output() @@ -43,7 +44,7 @@ fn failure_with_invalid_config_file() { #[test] fn failure_with_invalid_file_to_format() { - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("path/that/does/not/exist/a.nu") .output() .unwrap(); @@ -57,7 +58,7 @@ fn failure_with_invalid_file_to_format() { fn warning_when_no_files_are_detected() { let dir = tempdir().unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--dry-run") .arg(dir.path().to_str().unwrap()) .output() @@ -76,7 +77,7 @@ fn warning_is_displayed_when_no_files_are_detected_with_excluded_files() { fs::write(&config_file, r#"{exclude: ["a*"]}"#).unwrap(); fs::write(&file_a, INVALID).unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--config") .arg(config_file.to_str().unwrap()) .arg("--dry-run") @@ -99,7 +100,7 @@ fn files_are_reformatted() { fs::write(&file_a, INVALID).unwrap(); fs::write(&file_b, INVALID).unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--config") .arg(config_file.to_str().unwrap()) .arg(dir.path().to_str().unwrap()) @@ -123,7 +124,7 @@ fn files_are_checked() { fs::write(&file_a, INVALID).unwrap(); fs::write(&file_b, INVALID).unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--config") .arg(config_file.to_str().unwrap()) .arg("--dry-run") @@ -144,7 +145,7 @@ fn format_let_statement() { let file = dir.path().join("test.nu"); fs::write(&file, "let x = 1").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -160,7 +161,7 @@ fn format_def_statement() { let file = dir.path().join("test.nu"); fs::write(&file, "def foo [x: int] { $x + 1 }").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -177,7 +178,7 @@ fn format_if_else() { let file = dir.path().join("test.nu"); fs::write(&file, "if true { echo yes } else { echo no }").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -194,7 +195,7 @@ fn format_pipeline() { let file = dir.path().join("test.nu"); fs::write(&file, "ls|get name").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -210,7 +211,7 @@ fn format_preserves_comments() { let file = dir.path().join("test.nu"); fs::write(&file, "# comment\nlet x = 1").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -228,14 +229,14 @@ fn format_is_idempotent() { fs::write(&file, "let x = 1\nlet y = 2").unwrap(); // First format - Command::new(TEST_BINARY) + Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); let first = fs::read_to_string(&file).unwrap(); // Second format - Command::new(TEST_BINARY) + Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -250,7 +251,7 @@ fn format_for_loop() { let file = dir.path().join("test.nu"); fs::write(&file, "for x in [1, 2, 3] { print $x }").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -267,7 +268,7 @@ fn format_closure() { let file = dir.path().join("test.nu"); fs::write(&file, "{|x| $x * 2 }").unwrap(); - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg(file.to_str().unwrap()) .output() .unwrap(); @@ -282,7 +283,7 @@ fn format_fixtures_basic() { // Test that the basic fixture can be formatted without errors let fixture_path = PathBuf::from("tests/fixtures/basic.nu"); if fixture_path.exists() { - let output = Command::new(TEST_BINARY) + let output = Command::new(get_test_binary()) .arg("--dry-run") .arg(fixture_path.to_str().unwrap()) .output() From d470a6d720846df93691f4151115792e72553ded Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 30 Jan 2026 09:13:47 -0600 Subject: [PATCH 2/2] clippy --- tests/ground_truth.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ground_truth.rs b/tests/ground_truth.rs index 0446f3d..df45cce 100644 --- a/tests/ground_truth.rs +++ b/tests/ground_truth.rs @@ -13,16 +13,16 @@ pub fn get_test_binary() -> PathBuf { // Try CARGO_TARGET_DIR first if let Ok(target_dir) = std::env::var("CARGO_TARGET_DIR") { - let path = PathBuf::from(target_dir).join("debug").join(&exe_name); + let path = PathBuf::from(target_dir).join("debug").join(exe_name); if path.exists() { return path.canonicalize().unwrap_or(path); } } // Try default target directory - let default_path = PathBuf::from("target").join("debug").join(&exe_name); + let default_path = PathBuf::from("target").join("debug").join(exe_name); if default_path.exists() { - return default_path.canonicalize().unwrap_or(default_path); + default_path.canonicalize().unwrap_or(default_path) } else { panic!( "Test binary not found. Please build the project first to create {:?}", @@ -52,7 +52,7 @@ fn run_ground_truth_test(test_binary: &PathBuf, name: &str) { let input = fs::read_to_string(&input_path).expect("Failed to read input file"); // Run formatter via stdin - let formatted = match format_via_stdin(&test_binary, &input) { + let formatted = match format_via_stdin(test_binary, &input) { Ok(output) => output, Err(err) => panic!("Formatter failed for {}: {}", name, err), };