72 lines
2.0 KiB
Rust
72 lines
2.0 KiB
Rust
use std::fs;
|
|
use std::path::Path;
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
use super::{crate_name, render_files, scaffold, update_workspace_members};
|
|
|
|
#[test]
|
|
fn accepts_valid_crate_names() {
|
|
assert_eq!(crate_name(Path::new("foo_2")).unwrap(), "foo_2");
|
|
}
|
|
|
|
#[test]
|
|
fn rejects_invalid_crate_names() {
|
|
assert!(crate_name(Path::new("Foo")).is_err());
|
|
assert!(crate_name(Path::new("foo-bar")).is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn renders_crate_name_into_every_file() {
|
|
for file in render_files("example") {
|
|
assert!(!file.contents.contains("{CRATE_NAME}"));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn adds_workspace_member() {
|
|
let manifest = "[workspace]\nmembers = [\n \"src/status\",\n]\n";
|
|
let updated = update_workspace_members(manifest, "src/example").unwrap();
|
|
|
|
assert_eq!(
|
|
updated,
|
|
"[workspace]\nmembers = [\n \"src/status\",\n \"src/example\",\n]\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn creates_a_rust_package() {
|
|
let workspace = std::env::temp_dir().join(format!(
|
|
"scaffolding-test-{}-{}",
|
|
std::process::id(),
|
|
SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_nanos(),
|
|
));
|
|
fs::create_dir_all(workspace.join("src")).unwrap();
|
|
fs::write(
|
|
workspace.join("Cargo.toml"),
|
|
"[workspace]\nmembers = [\n]\n",
|
|
)
|
|
.unwrap();
|
|
|
|
let destination = scaffold(&workspace, &workspace.join("src/example")).unwrap();
|
|
|
|
assert_eq!(
|
|
destination,
|
|
fs::canonicalize(workspace.join("src/example")).unwrap()
|
|
);
|
|
assert!(destination.join("BUILD").exists());
|
|
assert!(destination.join("Cargo.toml").exists());
|
|
assert!(destination.join("example.rs").exists());
|
|
assert!(destination.join("example_main.rs").exists());
|
|
assert!(destination.join("example_test.rs").exists());
|
|
assert!(
|
|
fs::read_to_string(workspace.join("Cargo.toml"))
|
|
.unwrap()
|
|
.contains(" \"src/example\",")
|
|
);
|
|
|
|
fs::remove_dir_all(workspace).unwrap();
|
|
}
|