Skip to content

Commit

Permalink
test: Add syntethic scenarios to check correctness. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh authored Dec 5, 2023
1 parent 8345e9f commit 493f85d
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 6 deletions.
32 changes: 26 additions & 6 deletions bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,36 @@ fn if_right_equals_base_then_output_left_as_result() {

#[test]
fn it_works_on_semi_structured_merge() {
run_tool_on_scenario("semi_structured")
}

#[test]
fn it_works_on_node_reordering() {
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/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")
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/semi_structured/merge.expected.java").unwrap(),
std::fs::read_to_string("tests/samples/semi_structured/merge.output.java").unwrap()
std::fs::read_to_string(expected_result_path).unwrap(),
std::fs::read_to_string(actual_result_path).unwrap()
)
}
11 changes: 11 additions & 0 deletions bin/tests/samples/no_conflicts/base.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Test {

long fibo(int n) {
if (n < 2) {
return n;
} else {
return fibo(n - 1) + fibo(n - 2);
}
}

}
10 changes: 10 additions & 0 deletions bin/tests/samples/no_conflicts/left.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Test {
public int idade = 10;
long fibo(int n) {
if (n < 2) {
return n;
} else {
return fibo(n - 1) + fibo(n - 2);
}
}
}
1 change: 1 addition & 0 deletions bin/tests/samples/no_conflicts/merge.expected.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class Test { public int idade = 10 ; long fibo ( int n ) { if ( n < 2 ) { return n ; } else { return fibo ( n - 1 ) + fibo ( n - 2 ) ; } } public String nome = "Joao" ; }
11 changes: 11 additions & 0 deletions bin/tests/samples/no_conflicts/right.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Test {
public String nome = "Joao";
long fibo(int n) {
if (n < 2) {
return n;
} else {
return fibo(n - 1) + fibo(n - 2);
}
}

}
10 changes: 10 additions & 0 deletions bin/tests/samples/node_reordering/base.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Test {

class A {

}

interface I {

}
}
14 changes: 14 additions & 0 deletions bin/tests/samples/node_reordering/left.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Test {

class A {

}

class B {

}

interface I {

}
}
1 change: 1 addition & 0 deletions bin/tests/samples/node_reordering/merge.expected.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class Test { class A { } class B { } interface I { } class C { } }
14 changes: 14 additions & 0 deletions bin/tests/samples/node_reordering/right.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Test {

class A {

}

class C {

}

interface I {

}
}

0 comments on commit 493f85d

Please sign in to comment.