Skip to content

Commit

Permalink
test(apply): add apply_to_path_with_invalid_lang()
Browse files Browse the repository at this point in the history
see #485
  • Loading branch information
Alex-ley-scrub committed Oct 24, 2024
1 parent 8763951 commit 7b567e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/cli_bin/tests/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,34 @@ fn apply_to_path_with_invalid_javascript_extension() -> Result<()> {
Ok(())
}

/// test that we show an 'Error parsing source code' when we try to apply
/// to a path which contains the wrong language as specified in the lang flag
/// see https://github.com/getgrit/gritql/issues/485
#[test]
fn apply_to_path_with_invalid_lang() -> Result<()> {
let (_temp_dir, fixture_dir) = get_fixture("invalid_extensions", false)?;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg("`object` => ``")
.arg("file4.js.py")
.arg("--lang=py")
.arg("--force")
.current_dir(&fixture_dir);

let result = cmd.output()?;

let stderr = String::from_utf8(result.stderr)?;
println!("stderr: {:?}", stderr);
let stdout = String::from_utf8(result.stdout)?;
println!("stdout: {:?}", stdout);

assert!(result.status.success(), "Command failed");
assert_snapshot!(stdout);

Ok(())
}

/// Ban multiple stdin paths
#[test]
fn apply_stdin_two_paths() -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/cli_bin/tests/apply.rs
expression: stdout
---
file4.js.py: ERROR (code: 300) - Error parsing source code at 1:7 in file4.js.py. This may cause otherwise applicable queries to not match.
file4.js.py
-const mine = (object) => {
- return String(object) + 'is mine';
+const mine = () => {
+ return String() + 'is mine';
};


Processed 1 files and found 2 matches

0 comments on commit 7b567e0

Please sign in to comment.