use assert_cmd::prelude::*; use predicates::prelude::*; use std::fs::{create_dir_all, File}; use std::io::prelude::*; use std::process::Command; use tempfile::tempdir; #[test] fn init() -> Result<(), Box> { // Create a temporary folder let root_dir = tempdir()?; let folder = root_dir.path().join("init-project"); // Run the command let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("init").arg(&folder); cmd.assert().success(); // Check if there is a project file assert!(folder.join("orcs.toml").is_file()); // Check if the project file contains the right project name let mut file = File::open(folder.join("orcs.toml"))?; let mut data = String::new(); file.read_to_string(&mut data)?; assert!(predicate::str::contains("init-project").eval(&data)); Ok(()) } #[test] fn init_load() -> Result<(), Box> { // Create a temporary folder let root_dir = tempdir()?; let folder = root_dir.path().join("init-load-project"); // Run the command let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("init").arg(&folder); cmd.assert().success(); // Check if there is a project file assert!(folder.join("orcs.toml").is_file()); // Load the project let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("load").arg("-p").arg(&folder); cmd.assert() .success() .stdout(predicate::str::contains("init-load-project")); Ok(()) } #[test] fn init_from_template() -> Result<(), Box> { // Create some folders let root_dir = tempdir()?; let template_folder = root_dir.path().join("template"); let project_folder = root_dir.path().join("project-from-template"); // Create a local template create_dir_all(&template_folder.join("test_folder"))?; let mut test_file = File::create(&template_folder.join("test_folder").join("test.txt"))?; let test_data = "Hello, {{{ project_name }}}!"; test_file.write_all(test_data.as_bytes())?; // Run the command let mut cmd = Command::cargo_bin("orcs")?; cmd.arg("init") .arg("-p") .arg(&project_folder) .arg("-t") .arg(&template_folder); cmd.assert().success(); // Check if the test file contains the right project name let mut file = File::open(project_folder.join("test_folder").join("test.txt"))?; let mut data = String::new(); file.read_to_string(&mut data)?; assert!(predicate::str::contains("project-from-template").eval(&data)); Ok(()) }