From 9e24dabe9c48f21a5c0c6090d216460b9f0639cd Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 7 Mar 2018 09:49:22 -0800 Subject: [PATCH] test-support: Add ability to add new local dependencies to Cargo.toml --- crates/test-support/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/test-support/src/lib.rs b/crates/test-support/src/lib.rs index aff7398f..04c789bd 100644 --- a/crates/test-support/src/lib.rs +++ b/crates/test-support/src/lib.rs @@ -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));