feat(scaffolding): add Rust package generator
This commit is contained in:
1 parent
d342370b89
commit
a5bc1d5303
12 files changed
+387
No files matched your search
@@ -0,0 +1,71 @@
|
||||
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();
|
||||
}
|
||||
Reference in new issue
Block a user