add unit tests for ftw tag

This commit is contained in:
Michael Angelo Calimlim 2023-10-21 12:23:03 +08:00
parent 098a00523e
commit 06a3a4640a
3 changed files with 133 additions and 3 deletions

View file

@ -496,6 +496,70 @@ mod ftw_command_tests {
.contains(&project.get_name()));
}
#[test]
fn test_process_ftw_command_new_with_latest_tag() {
let project = Project::new();
let cmd = FtwCommand::New {
project_name: project.get_name(),
template: FtwTemplate::default(),
tag: FtwTag::Latest,
};
let _ = cmd.process();
assert!(project.exists(".gitignore"));
assert!(project.exists("Cargo.toml"));
assert!(project.exists("Makefile"));
assert!(project.exists("godot/default_env.tres"));
assert!(project.exists("godot/export_presets.cfg"));
assert!(project.exists("godot/native/game.gdnlib"));
assert!(project.exists("godot/project.godot"));
assert!(project.exists("rust/Cargo.toml"));
assert!(project.exists("rust/src/lib.rs"));
assert!(!project.exists("LICENSE"));
assert!(!project.exists(".travis.yml"));
assert!(!project.exists("sh"));
assert!(project.read(".gitignore").contains(".ftw"));
assert!(project.read(".gitignore").contains("bin/*"));
assert!(project.read(".gitignore").contains("export_presets.cfg"));
assert!(project.read(".gitignore").contains("lib/*"));
assert!(project.read(".tag").contains("v1.3.0"));
assert!(project
.read("rust/Cargo.toml")
.contains(&project.get_name()));
}
#[test]
fn test_process_ftw_command_new_with_v120_tag() {
let project = Project::new();
let cmd = FtwCommand::New {
project_name: project.get_name(),
template: FtwTemplate::default(),
tag: FtwTag::Tagged {
git_tag: String::from("v1.2.0"),
},
};
let _ = cmd.process();
assert!(project.exists(".gitignore"));
assert!(project.exists("Cargo.toml"));
assert!(project.exists("Makefile"));
assert!(project.exists("godot/default_env.tres"));
assert!(project.exists("godot/export_presets.cfg"));
assert!(project.exists("godot/native/game.gdnlib"));
assert!(project.exists("godot/project.godot"));
assert!(project.exists("rust/Cargo.toml"));
assert!(project.exists("rust/src/lib.rs"));
assert!(!project.exists("LICENSE"));
assert!(!project.exists(".travis.yml"));
assert!(!project.exists("sh"));
assert!(!project.exists(".tag"));
assert!(project.read(".gitignore").contains(".ftw"));
assert!(project.read(".gitignore").contains("bin/*"));
assert!(project.read(".gitignore").contains("export_presets.cfg"));
assert!(project.read(".gitignore").contains("lib/*"));
assert!(project
.read("rust/Cargo.toml")
.contains(&project.get_name()));
}
#[test]
fn test_process_ftw_command_class() {
let project = Project::new();

View file

@ -11,7 +11,7 @@ pub enum FtwTag {
Tagged { git_tag: GitTag },
}
const DEFAULT_TEMPLATE_TAG: &str = "v1.2.0";
const DEFAULT_TEMPLATE_TAG: &str = "v1.3.0";
impl FromStr for FtwTag {
type Err = ();
@ -69,7 +69,7 @@ mod ftw_tag_tests {
#[test]
fn test_to_git_tag() {
assert_eq!(FtwTag::Latest.to_git_tag(), "v1.2.0");
assert_eq!(FtwTag::Latest.to_git_tag(), "v1.3.0");
assert_eq!(
FtwTag::Tagged {
git_tag: String::from("v1.1.0")
@ -84,7 +84,7 @@ mod ftw_tag_tests {
let latest = FtwTag::Latest;
let git_tag = String::from("v1.1.0");
let tagged = FtwTag::Tagged { git_tag };
assert_eq!(format!("{latest}"), "v1.2.0");
assert_eq!(format!("{latest}"), "v1.3.0");
assert_eq!(format!("{tagged}"), "v1.1.0");
}

View file

@ -37,6 +37,72 @@ fn test_ftw_new() {
.contains(&project.get_name()));
}
#[test]
fn test_ftw_new_with_latest_tag() {
let project = Project::new();
ftw()
.arg("new")
.arg(&project.get_name())
.arg("default")
.arg("latest")
.assert()
.success()
.stdout(predicates::str::contains("SUCCESS").from_utf8());
assert!(project.exists(".gitignore"));
assert!(project.exists("Cargo.toml"));
assert!(project.exists("Makefile"));
assert!(project.exists("godot/default_env.tres"));
assert!(project.exists("godot/export_presets.cfg"));
assert!(project.exists("godot/native/game.gdnlib"));
assert!(project.exists("godot/project.godot"));
assert!(project.exists("rust/Cargo.toml"));
assert!(project.exists("rust/src/lib.rs"));
assert!(!project.exists("LICENSE"));
assert!(!project.exists(".travis.yml"));
assert!(!project.exists("sh"));
assert!(project.read(".gitignore").contains(".ftw"));
assert!(project.read(".gitignore").contains("bin/*"));
assert!(project.read(".gitignore").contains("export_presets.cfg"));
assert!(project.read(".gitignore").contains("lib/*"));
assert!(project.read(".tag").contains("v1.3.0"));
assert!(project
.read("rust/Cargo.toml")
.contains(&project.get_name()));
}
#[test]
fn test_ftw_new_with_v120_tag() {
let project = Project::new();
ftw()
.arg("new")
.arg(&project.get_name())
.arg("default")
.arg("v1.2.0")
.assert()
.success()
.stdout(predicates::str::contains("SUCCESS").from_utf8());
assert!(project.exists(".gitignore"));
assert!(project.exists("Cargo.toml"));
assert!(project.exists("Makefile"));
assert!(project.exists("godot/default_env.tres"));
assert!(project.exists("godot/export_presets.cfg"));
assert!(project.exists("godot/native/game.gdnlib"));
assert!(project.exists("godot/project.godot"));
assert!(project.exists("rust/Cargo.toml"));
assert!(project.exists("rust/src/lib.rs"));
assert!(!project.exists("LICENSE"));
assert!(!project.exists(".travis.yml"));
assert!(!project.exists("sh"));
assert!(!project.exists(".tag"));
assert!(project.read(".gitignore").contains(".ftw"));
assert!(project.read(".gitignore").contains("bin/*"));
assert!(project.read(".gitignore").contains("export_presets.cfg"));
assert!(project.read(".gitignore").contains("lib/*"));
assert!(project
.read("rust/Cargo.toml")
.contains(&project.get_name()));
}
#[test]
fn test_ftw_new_no_template() {
let project = Project::new();