test-support: Add ability to add new local dependencies to Cargo.toml

This commit is contained in:
Nick Fitzgerald 2018-03-07 09:49:22 -08:00
parent 1a9e031ed0
commit 9e24dabe9c

View File

@ -42,6 +42,8 @@ pub fn project() -> Project {
[lib]
crate-type = ["cdylib"]
# XXX: It is important that `[dependencies]` is the last section
# here, so that `add_local_dependency` functions correctly!
[dependencies]
wasm-bindgen = {{ path = '{}' }}
"#, IDX.with(|x| *x), dir.display())),
@ -142,6 +144,20 @@ impl Project {
self
}
pub fn add_local_dependency(&mut self, name: &str, path: &str) -> &mut Project {
{
let cargo_toml = self.files
.iter_mut()
.find(|f| f.0 == "Cargo.toml")
.expect("should have Cargo.toml file!");
cargo_toml.1.push_str(name);
cargo_toml.1.push_str(" = { path = \"");
cargo_toml.1.push_str(path);
cargo_toml.1.push_str("\" }");
}
self
}
pub fn test(&mut self) {
let root = root();
drop(fs::remove_dir_all(&root));