Add an opt-out to the auto-generated Cargo.toml

This commit is contained in:
Dale Wijnand 2018-07-24 13:19:47 +01:00
parent 2e6e5f880b
commit d2c815be22
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
2 changed files with 9 additions and 2 deletions

View File

@ -535,7 +535,7 @@ Caused by:
#[test]
fn cargo_compile_without_manifest() {
let tmpdir = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
let p = ProjectBuilder::new(tmpdir.path().to_path_buf()).build();
let p = ProjectBuilder::new(tmpdir.path().to_path_buf()).no_manifest().build();
assert_that(
p.cargo("build"),

View File

@ -197,6 +197,7 @@ pub struct ProjectBuilder {
root: Project,
files: Vec<FileBuilder>,
symlinks: Vec<SymlinkBuilder>,
no_manifest: bool,
}
impl ProjectBuilder {
@ -215,6 +216,7 @@ impl ProjectBuilder {
root: Project::Rooted(root),
files: vec![],
symlinks: vec![],
no_manifest: false,
}
}
@ -248,6 +250,11 @@ impl ProjectBuilder {
self
}
pub fn no_manifest(mut self) -> Self {
self.no_manifest = true;
self
}
/// Create the project.
pub fn build(mut self) -> Project {
// First, clean the directory if it already exists
@ -257,7 +264,7 @@ impl ProjectBuilder {
self.root.root().mkdir_p();
let manifest_path = self.root.root().join("Cargo.toml");
if self.files.iter().all(|fb| fb.path != manifest_path) {
if !self.no_manifest && self.files.iter().all(|fb| fb.path != manifest_path) {
self._file(Path::new("Cargo.toml"), BASIC_MANIFEST)
}