Skip to content

Commit

Permalink
refactor: DRY code
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Dec 5, 2023
1 parent e29e542 commit 2324848
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,36 @@ fn if_right_equals_base_then_output_left_as_result() {

#[test]
fn it_works_on_semi_structured_merge() {
let mut cmd = Command::cargo_bin("generic-merge").unwrap();
cmd.arg("--base-path=tests/samples/semi_structured/base.java")
.arg("--left-path=tests/samples/semi_structured/left.java")
.arg("--right-path=tests/samples/semi_structured/right.java")
.arg("--merge-path=tests/samples/semi_structured/merge.output.java")
.assert()
.code(0);

assert_eq!(
std::fs::read_to_string("tests/samples/semi_structured/merge.expected.java").unwrap(),
std::fs::read_to_string("tests/samples/semi_structured/merge.output.java").unwrap()
)
run_tool_on_scenario("semi_structured")
}

#[test]
fn it_works_on_node_reordering() {
let mut cmd = Command::cargo_bin("generic-merge").unwrap();
cmd.arg("--base-path=tests/samples/node_reordering/base.java")
.arg("--left-path=tests/samples/node_reordering/left.java")
.arg("--right-path=tests/samples/node_reordering/right.java")
.arg("--merge-path=tests/samples/node_reordering/merge.output.java")
.assert()
.code(0);

assert_eq!(
std::fs::read_to_string("tests/samples/node_reordering/merge.expected.java").unwrap(),
std::fs::read_to_string("tests/samples/node_reordering/merge.output.java").unwrap()
)
run_tool_on_scenario("node_reordering")
}

#[test]
fn it_works_on_no_conflicts() {
run_tool_on_scenario("no_conflicts")
}

fn run_tool_on_scenario(scenario_name: &str) {
let mut cmd = Command::cargo_bin("generic-merge").unwrap();
cmd.arg("--base-path=tests/samples/no_conflicts/base.java")
.arg("--left-path=tests/samples/no_conflicts/left.java")
.arg("--right-path=tests/samples/no_conflicts/right.java")
.arg("--merge-path=tests/samples/no_conflicts/merge.output.java")
cmd.arg(format!("-b=tests/samples/{}/base.java", scenario_name))
.arg(format!("-l=tests/samples/{}/left.java", scenario_name))
.arg(format!("-r=tests/samples/{}/right.java", scenario_name))
.arg(format!(
"-m=tests/samples/{}/merge.output.java",
scenario_name
))
.assert()
.code(0);

let expected_result_path = format!("tests/samples/{}/merge.expected.java", scenario_name);
let actual_result_path = format!("tests/samples/{}/merge.output.java", scenario_name);

assert_eq!(
std::fs::read_to_string("tests/samples/no_conflicts/merge.expected.java").unwrap(),
std::fs::read_to_string("tests/samples/no_conflicts/merge.output.java").unwrap()
std::fs::read_to_string(expected_result_path).unwrap(),
std::fs::read_to_string(actual_result_path).unwrap()
)
}

0 comments on commit 2324848

Please sign in to comment.