Skip to content

Commit

Permalink
Added test case for invalid path to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ketkarameya committed Aug 22, 2023
1 parent b2afb57 commit c7b3346
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repos:
files: demo/
exclude: only_lists.py
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2" # Use the sha or tag you want to point at
rev: "v3.0.2"
hooks:
- id: prettier
files: ^experimental/piranha_playground/
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl Piranha {

let temp_dir = if !self.piranha_arguments.code_snippet().is_empty() {
let td = self.write_code_snippet_to_temp();
// let td_path = td.path().to_str().unwrap().to_string();
paths_to_codebase = vec![td.path().to_str().unwrap_or_default().to_string()];
Some(td)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/models/piranha_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct PiranhaArguments {
/// Path to source code folder or file
#[get = "pub"]
#[builder(default = "default_paths_to_codebase()")]
#[clap(short = 'c', long, num_args = 0.., required = true)]
#[clap(short = 'c', long, num_args = 1.., required = true)]
paths_to_codebase: Vec<String>,

/// Paths to include (as glob patterns)
Expand Down
26 changes: 25 additions & 1 deletion src/tests/test_piranha_java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ fn test_dyn_rule() {
}

#[test]

fn test_multiple_code_bases() {
initialize();
let _path = PathBuf::from("test-resources")
Expand All @@ -457,6 +456,31 @@ fn test_multiple_code_bases() {
.rule_graph(RuleGraphBuilder::default().rules(vec![rule]).build())
.build();
let output_summaries = execute_piranha(&piranha_arguments);
// Note that we expect 2 matches because we have 2 code bases, and each code base has 1 match.
// We also have another codebase `folder_3` but the `paths_to_codebase` does not include it.
assert_eq!(output_summaries.len(), 2);
assert_frequency_for_matches(&output_summaries, &HashMap::from([("match_import", 2)]));
}

#[test]
#[should_panic(
expected = "Path to codebase does not exist: test-resources/java/structural_find_replace_multiple_code_bases/folder_0"
)]
fn test_incorrect_codebase_path() {
initialize();
let _path = PathBuf::from("test-resources")
.join(JAVA)
.join("structural_find_replace_multiple_code_bases");
// Note that structural_find_replace_multiple_code_bases/folder_0 does not exist
let path_to_codebase1 = _path.join("folder_0").to_str().unwrap().to_string();
let rule = piranha_rule! {
name = "match_import",
query = "cs import java.util.List;"
};
let piranha_arguments = PiranhaArgumentsBuilder::default()
.language(PiranhaLanguage::from(JAVA))
.paths_to_codebase(vec![path_to_codebase1])
.rule_graph(RuleGraphBuilder::default().rules(vec![rule]).build())
.build();
_ = execute_piranha(&piranha_arguments);
}

0 comments on commit c7b3346

Please sign in to comment.