|
@@ -223,191 +223,193 @@ fn remove_triple_newlines(string: &str) -> String {
|
|
|
new_string
|
|
|
}
|
|
|
|
|
|
-#[cfg(test)]
|
|
|
-pub(crate) mod tests {
|
|
|
- use escargot::{CargoBuild, CargoRun};
|
|
|
- use once_cell::sync::Lazy;
|
|
|
- use std::fs::{create_dir_all, read_to_string};
|
|
|
- use std::path::{Path, PathBuf};
|
|
|
- use std::process::Command;
|
|
|
- use tempfile::tempdir;
|
|
|
- use toml::Value;
|
|
|
-
|
|
|
- static BINARY: Lazy<CargoRun> = Lazy::new(|| {
|
|
|
- CargoBuild::new()
|
|
|
- .bin(env!("CARGO_BIN_NAME"))
|
|
|
- .current_release()
|
|
|
- .run()
|
|
|
- .expect("Couldn't build the binary for tests.")
|
|
|
- });
|
|
|
-
|
|
|
- // Note: tests below (at least 6 of them) were written to mainly test
|
|
|
- // correctness of project's directory and its name, because previously it
|
|
|
- // was broken and tests bring a peace of mind. And also so that I don't have
|
|
|
- // to run my local hand-made tests every time.
|
|
|
-
|
|
|
- pub(crate) type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
|
|
-
|
|
|
- pub(crate) fn subcommand(name: &str) -> Command {
|
|
|
- let mut command = BINARY.command();
|
|
|
- command.arg(name).arg("--yes"); // Skip any questions by choosing default answers.
|
|
|
- command
|
|
|
- }
|
|
|
-
|
|
|
- pub(crate) fn get_cargo_toml_path(project_path: &Path) -> PathBuf {
|
|
|
- project_path.join("Cargo.toml")
|
|
|
- }
|
|
|
-
|
|
|
- pub(crate) fn get_project_name(cargo_toml_path: &Path) -> Result<String> {
|
|
|
- Ok(toml::from_str::<Value>(&read_to_string(cargo_toml_path)?)?
|
|
|
- .get("package")
|
|
|
- .unwrap()
|
|
|
- .get("name")
|
|
|
- .unwrap()
|
|
|
- .as_str()
|
|
|
- .unwrap()
|
|
|
- .to_string())
|
|
|
- }
|
|
|
-
|
|
|
- fn subcommand_new() -> Command {
|
|
|
- subcommand("new")
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn test_subcommand_new_with_dot_path() -> Result<()> {
|
|
|
- let project_dir = "dir";
|
|
|
- let project_name = project_dir;
|
|
|
-
|
|
|
- let temp_dir = tempdir()?;
|
|
|
- // Make current dir's name deterministic.
|
|
|
- let current_dir = temp_dir.path().join(project_dir);
|
|
|
- create_dir_all(¤t_dir)?;
|
|
|
- let project_path = ¤t_dir;
|
|
|
- assert!(project_path.exists());
|
|
|
-
|
|
|
- assert!(subcommand_new()
|
|
|
- .arg(".")
|
|
|
- .current_dir(¤t_dir)
|
|
|
- .status()
|
|
|
- .is_ok());
|
|
|
-
|
|
|
- let cargo_toml_path = get_cargo_toml_path(project_path);
|
|
|
- assert!(cargo_toml_path.exists());
|
|
|
- assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn test_subcommand_new_with_1_dir_path() -> Result<()> {
|
|
|
- let project_dir = "dir";
|
|
|
- let project_name = project_dir;
|
|
|
-
|
|
|
- let current_dir = tempdir()?;
|
|
|
-
|
|
|
- assert!(subcommand_new()
|
|
|
- .arg(project_dir)
|
|
|
- .current_dir(¤t_dir)
|
|
|
- .status()
|
|
|
- .is_ok());
|
|
|
-
|
|
|
- let project_path = current_dir.path().join(project_dir);
|
|
|
- let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
- assert!(project_path.exists());
|
|
|
- assert!(cargo_toml_path.exists());
|
|
|
- assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn test_subcommand_new_with_2_dir_path() -> Result<()> {
|
|
|
- let project_dir = "a/b";
|
|
|
- let project_name = "b";
|
|
|
-
|
|
|
- let current_dir = tempdir()?;
|
|
|
-
|
|
|
- assert!(subcommand_new()
|
|
|
- .arg(project_dir)
|
|
|
- .current_dir(¤t_dir)
|
|
|
- .status()
|
|
|
- .is_ok());
|
|
|
-
|
|
|
- let project_path = current_dir.path().join(project_dir);
|
|
|
- let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
- assert!(project_path.exists());
|
|
|
- assert!(cargo_toml_path.exists());
|
|
|
- assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn test_subcommand_new_with_dot_path_and_custom_name() -> Result<()> {
|
|
|
- let project_dir = "dir";
|
|
|
- let project_name = "project";
|
|
|
-
|
|
|
- let temp_dir = tempdir()?;
|
|
|
- // Make current dir's name deterministic.
|
|
|
- let current_dir = temp_dir.path().join(project_dir);
|
|
|
- create_dir_all(¤t_dir)?;
|
|
|
- let project_path = ¤t_dir;
|
|
|
- assert!(project_path.exists());
|
|
|
-
|
|
|
- assert!(subcommand_new()
|
|
|
- .arg("--name")
|
|
|
- .arg(project_name)
|
|
|
- .arg(".")
|
|
|
- .current_dir(¤t_dir)
|
|
|
- .status()
|
|
|
- .is_ok());
|
|
|
-
|
|
|
- let cargo_toml_path = get_cargo_toml_path(project_path);
|
|
|
- assert!(cargo_toml_path.exists());
|
|
|
- assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn test_subcommand_new_with_1_dir_path_and_custom_name() -> Result<()> {
|
|
|
- let project_dir = "dir";
|
|
|
- let project_name = "project";
|
|
|
-
|
|
|
- let current_dir = tempdir()?;
|
|
|
-
|
|
|
- assert!(subcommand_new()
|
|
|
- .arg(project_dir)
|
|
|
- .arg("--name")
|
|
|
- .arg(project_name)
|
|
|
- .current_dir(¤t_dir)
|
|
|
- .status()
|
|
|
- .is_ok());
|
|
|
-
|
|
|
- let project_path = current_dir.path().join(project_dir);
|
|
|
- let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
- assert!(project_path.exists());
|
|
|
- assert!(cargo_toml_path.exists());
|
|
|
- assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn test_subcommand_new_with_2_dir_path_and_custom_name() -> Result<()> {
|
|
|
- let project_dir = "a/b";
|
|
|
- let project_name = "project";
|
|
|
-
|
|
|
- let current_dir = tempdir()?;
|
|
|
-
|
|
|
- assert!(subcommand_new()
|
|
|
- .arg(project_dir)
|
|
|
- .arg("--name")
|
|
|
- .arg(project_name)
|
|
|
- .current_dir(¤t_dir)
|
|
|
- .status()
|
|
|
- .is_ok());
|
|
|
-
|
|
|
- let project_path = current_dir.path().join(project_dir);
|
|
|
- let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
- assert!(project_path.exists());
|
|
|
- assert!(cargo_toml_path.exists());
|
|
|
- assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-}
|
|
|
+// todo: re-enable these tests with better parallelization
|
|
|
+//
|
|
|
+// #[cfg(test)]
|
|
|
+// pub(crate) mod tests {
|
|
|
+// use escargot::{CargoBuild, CargoRun};
|
|
|
+// use once_cell::sync::Lazy;
|
|
|
+// use std::fs::{create_dir_all, read_to_string};
|
|
|
+// use std::path::{Path, PathBuf};
|
|
|
+// use std::process::Command;
|
|
|
+// use tempfile::tempdir;
|
|
|
+// use toml::Value;
|
|
|
+
|
|
|
+// static BINARY: Lazy<CargoRun> = Lazy::new(|| {
|
|
|
+// CargoBuild::new()
|
|
|
+// .bin(env!("CARGO_BIN_NAME"))
|
|
|
+// .current_release()
|
|
|
+// .run()
|
|
|
+// .expect("Couldn't build the binary for tests.")
|
|
|
+// });
|
|
|
+
|
|
|
+// // Note: tests below (at least 6 of them) were written to mainly test
|
|
|
+// // correctness of project's directory and its name, because previously it
|
|
|
+// // was broken and tests bring a peace of mind. And also so that I don't have
|
|
|
+// // to run my local hand-made tests every time.
|
|
|
+
|
|
|
+// pub(crate) type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
|
|
+
|
|
|
+// pub(crate) fn subcommand(name: &str) -> Command {
|
|
|
+// let mut command = BINARY.command();
|
|
|
+// command.arg(name).arg("--yes"); // Skip any questions by choosing default answers.
|
|
|
+// command
|
|
|
+// }
|
|
|
+
|
|
|
+// pub(crate) fn get_cargo_toml_path(project_path: &Path) -> PathBuf {
|
|
|
+// project_path.join("Cargo.toml")
|
|
|
+// }
|
|
|
+
|
|
|
+// pub(crate) fn get_project_name(cargo_toml_path: &Path) -> Result<String> {
|
|
|
+// Ok(toml::from_str::<Value>(&read_to_string(cargo_toml_path)?)?
|
|
|
+// .get("package")
|
|
|
+// .unwrap()
|
|
|
+// .get("name")
|
|
|
+// .unwrap()
|
|
|
+// .as_str()
|
|
|
+// .unwrap()
|
|
|
+// .to_string())
|
|
|
+// }
|
|
|
+
|
|
|
+// fn subcommand_new() -> Command {
|
|
|
+// subcommand("new")
|
|
|
+// }
|
|
|
+
|
|
|
+// #[test]
|
|
|
+// fn test_subcommand_new_with_dot_path() -> Result<()> {
|
|
|
+// let project_dir = "dir";
|
|
|
+// let project_name = project_dir;
|
|
|
+
|
|
|
+// let temp_dir = tempdir()?;
|
|
|
+// // Make current dir's name deterministic.
|
|
|
+// let current_dir = temp_dir.path().join(project_dir);
|
|
|
+// create_dir_all(¤t_dir)?;
|
|
|
+// let project_path = ¤t_dir;
|
|
|
+// assert!(project_path.exists());
|
|
|
+
|
|
|
+// assert!(subcommand_new()
|
|
|
+// .arg(".")
|
|
|
+// .current_dir(¤t_dir)
|
|
|
+// .status()
|
|
|
+// .is_ok());
|
|
|
+
|
|
|
+// let cargo_toml_path = get_cargo_toml_path(project_path);
|
|
|
+// assert!(cargo_toml_path.exists());
|
|
|
+// assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+
|
|
|
+// #[test]
|
|
|
+// fn test_subcommand_new_with_1_dir_path() -> Result<()> {
|
|
|
+// let project_dir = "dir";
|
|
|
+// let project_name = project_dir;
|
|
|
+
|
|
|
+// let current_dir = tempdir()?;
|
|
|
+
|
|
|
+// assert!(subcommand_new()
|
|
|
+// .arg(project_dir)
|
|
|
+// .current_dir(¤t_dir)
|
|
|
+// .status()
|
|
|
+// .is_ok());
|
|
|
+
|
|
|
+// let project_path = current_dir.path().join(project_dir);
|
|
|
+// let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
+// assert!(project_path.exists());
|
|
|
+// assert!(cargo_toml_path.exists());
|
|
|
+// assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+
|
|
|
+// #[test]
|
|
|
+// fn test_subcommand_new_with_2_dir_path() -> Result<()> {
|
|
|
+// let project_dir = "a/b";
|
|
|
+// let project_name = "b";
|
|
|
+
|
|
|
+// let current_dir = tempdir()?;
|
|
|
+
|
|
|
+// assert!(subcommand_new()
|
|
|
+// .arg(project_dir)
|
|
|
+// .current_dir(¤t_dir)
|
|
|
+// .status()
|
|
|
+// .is_ok());
|
|
|
+
|
|
|
+// let project_path = current_dir.path().join(project_dir);
|
|
|
+// let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
+// assert!(project_path.exists());
|
|
|
+// assert!(cargo_toml_path.exists());
|
|
|
+// assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+
|
|
|
+// #[test]
|
|
|
+// fn test_subcommand_new_with_dot_path_and_custom_name() -> Result<()> {
|
|
|
+// let project_dir = "dir";
|
|
|
+// let project_name = "project";
|
|
|
+
|
|
|
+// let temp_dir = tempdir()?;
|
|
|
+// // Make current dir's name deterministic.
|
|
|
+// let current_dir = temp_dir.path().join(project_dir);
|
|
|
+// create_dir_all(¤t_dir)?;
|
|
|
+// let project_path = ¤t_dir;
|
|
|
+// assert!(project_path.exists());
|
|
|
+
|
|
|
+// assert!(subcommand_new()
|
|
|
+// .arg("--name")
|
|
|
+// .arg(project_name)
|
|
|
+// .arg(".")
|
|
|
+// .current_dir(¤t_dir)
|
|
|
+// .status()
|
|
|
+// .is_ok());
|
|
|
+
|
|
|
+// let cargo_toml_path = get_cargo_toml_path(project_path);
|
|
|
+// assert!(cargo_toml_path.exists());
|
|
|
+// assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+
|
|
|
+// #[test]
|
|
|
+// fn test_subcommand_new_with_1_dir_path_and_custom_name() -> Result<()> {
|
|
|
+// let project_dir = "dir";
|
|
|
+// let project_name = "project";
|
|
|
+
|
|
|
+// let current_dir = tempdir()?;
|
|
|
+
|
|
|
+// assert!(subcommand_new()
|
|
|
+// .arg(project_dir)
|
|
|
+// .arg("--name")
|
|
|
+// .arg(project_name)
|
|
|
+// .current_dir(¤t_dir)
|
|
|
+// .status()
|
|
|
+// .is_ok());
|
|
|
+
|
|
|
+// let project_path = current_dir.path().join(project_dir);
|
|
|
+// let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
+// assert!(project_path.exists());
|
|
|
+// assert!(cargo_toml_path.exists());
|
|
|
+// assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+
|
|
|
+// #[test]
|
|
|
+// fn test_subcommand_new_with_2_dir_path_and_custom_name() -> Result<()> {
|
|
|
+// let project_dir = "a/b";
|
|
|
+// let project_name = "project";
|
|
|
+
|
|
|
+// let current_dir = tempdir()?;
|
|
|
+
|
|
|
+// assert!(subcommand_new()
|
|
|
+// .arg(project_dir)
|
|
|
+// .arg("--name")
|
|
|
+// .arg(project_name)
|
|
|
+// .current_dir(¤t_dir)
|
|
|
+// .status()
|
|
|
+// .is_ok());
|
|
|
+
|
|
|
+// let project_path = current_dir.path().join(project_dir);
|
|
|
+// let cargo_toml_path = get_cargo_toml_path(&project_path);
|
|
|
+// assert!(project_path.exists());
|
|
|
+// assert!(cargo_toml_path.exists());
|
|
|
+// assert_eq!(get_project_name(&cargo_toml_path)?, project_name);
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+// }
|