Skip to content

Commit

Permalink
test: Enhance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Dec 5, 2023
1 parent ef59a91 commit 7fa02bd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 103 deletions.
7 changes: 7 additions & 0 deletions bin/src/cli_exit_codes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub const SUCCESS_WITHOUT_CONFLICTS: i32 = 0;
pub const SUCCESS_WITH_CONFLICTS: i32 = 1;

pub const READING_FILE_ERROR: i32 = 129;
pub const GUESS_LANGUAGE_ERROR: i32 = 130;
pub const WRITING_FILE_ERROR: i32 = 131;
pub const INTERNAL_EXECUTION_ERROR: i32 = 132;
2 changes: 1 addition & 1 deletion bin/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ mod tests {
#[test]
fn if_the_file_extension_has_a_parser_available_it_returns_a_parser_configuration() {
let file_path = std::path::PathBuf::from("/path/for/java/file/Example.java");
assert!(get_language_by_file_path(&file_path).is_ok())
assert_eq!(get_language_by_file_path(&file_path).unwrap(), model::Language::Java)
}
}
2 changes: 2 additions & 0 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod cli_exit_codes;
mod control;

pub use cli_exit_codes::*;
pub use control::run_tool_on_merge_scenario;
11 changes: 1 addition & 10 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
mod cli_args;
mod cli_exit_codes;
mod control;
mod language;

use clap::Parser;

mod cli_exit_codes {
pub const SUCCESS_WITHOUT_CONFLICTS: i32 = 0;
pub const SUCCESS_WITH_CONFLICTS: i32 = 1;

pub const READING_FILE_ERROR: i32 = 129;
pub const GUESS_LANGUAGE_ERROR: i32 = 130;
pub const WRITING_FILE_ERROR: i32 = 131;
pub const INTERNAL_EXECUTION_ERROR: i32 = 132;
}

fn main() {
let args = cli_args::CliArgs::parse();

Expand Down
116 changes: 25 additions & 91 deletions bin/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,25 @@
// use std::process::Command;

// use assert_cmd::prelude::*;

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

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

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

// assert_eq!(
// std::fs::read_to_string("tests/samples/one_parent_equals_base/changed_parent.java")
// .unwrap(),
// std::fs::read_to_string("tests/samples/one_parent_equals_base/merge.output.right.java")
// .unwrap()
// )
// }

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

// assert_eq!(
// std::fs::read_to_string("tests/samples/one_parent_equals_base/changed_parent.java")
// .unwrap(),
// std::fs::read_to_string("tests/samples/one_parent_equals_base/merge.output.left.java")
// .unwrap()
// )
// }

// #[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(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(expected_result_path).unwrap(),
// std::fs::read_to_string(actual_result_path).unwrap()
// )
// }
use std::process::Command;

use assert_cmd::prelude::*;

#[test]
fn if_there_is_a_conflict_it_returns_valid_exit_code() {
let mut cmd = Command::cargo_bin("generic-merge").unwrap();
cmd.arg("--base-path=tests/samples/smoke_java/base.java")
.arg("--left-path=tests/samples/smoke_java/left.java")
.arg("--right-path=tests/samples/smoke_java/right.java")
.arg("--merge-path=tests/samples/smoke_java/merge.java")
.assert()
.code(bin::SUCCESS_WITH_CONFLICTS);
}

#[test]
fn if_there_is_no_conflict_it_returns_valid_exit_code() {
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.java")
.assert()
.code(bin::SUCCESS_WITHOUT_CONFLICTS);
}
2 changes: 1 addition & 1 deletion model/src/language.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum Language {
Java,
}

0 comments on commit 7fa02bd

Please sign in to comment.