Skip to content

Commit c54a2ad

Browse files
committed
Auto merge of #3799 - integer32llc:restore-generated-tests-module, r=alexcrichton
Restore the generated tests module created by `cargo new` Appears to have been removed unintentionally in #3004. Was just working on the book, ran `cargo new adder` with cargo-0.18.0-nightly (6f1b860 2017-02-11), and got this in `src/lib.rs`: ```rust #[test] fn it_works() { } ``` when I expected to get this: ```rust #[cfg(test)] mod tests { #[test] fn it_works() { } } ``` It looks like this was changed as part of #3004 ([removed](875a8ab#diff-149dd4362a3b0dc13b113762713119dfL477), [added](875a8ab#diff-149dd4362a3b0dc13b113762713119dfR678)), I'm assuming unintentionally? The regression has not yet hit the beta channel; `cargo-0.17.0-nightly (0bb8047 2017-02-06)` generates the src/lib.rs I expect.
2 parents 5db6d64 + de06b75 commit c54a2ad

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ fn collect_template_dir(template_path: &PathBuf, _: &Path) -> CargoResult<Vec<Bo
582582
human(format!("entry is somehow not a subpath \
583583
of the directory being walked."))
584584
})));
585-
templates.push(Box::new(InputFileTemplateFile::new(entry_path,
585+
templates.push(Box::new(InputFileTemplateFile::new(entry_path,
586586
dest_file_name.to_path_buf())));
587587
Ok(())
588588
}));
@@ -707,8 +707,11 @@ authors = [{{toml-escape author}}]
707707
/// Create a new "lib" project
708708
fn create_lib_template() -> Vec<Box<TemplateFile>> {
709709
let lib_file = Box::new(InMemoryTemplateFile::new(PathBuf::from("src/lib.rs"),
710-
String::from(r#"#[test]
711-
fn it_works() {
710+
String::from(r#"#[cfg(test)]
711+
mod tests {
712+
#[test]
713+
fn it_works() {
714+
}
712715
}
713716
"#)));
714717
vec![lib_file]

tests/new.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ fn simple_lib() {
3232
assert_that(&paths::root().join("foo/src/lib.rs"), existing_file());
3333
assert_that(&paths::root().join("foo/.gitignore"), is_not(existing_file()));
3434

35+
let lib = paths::root().join("foo/src/lib.rs");
36+
let mut contents = String::new();
37+
File::open(&lib).unwrap().read_to_string(&mut contents).unwrap();
38+
assert_eq!(contents, r#"#[cfg(test)]
39+
mod tests {
40+
#[test]
41+
fn it_works() {
42+
}
43+
}
44+
"#);
45+
3546
assert_that(cargo_process("build").cwd(&paths::root().join("foo")),
3647
execs().with_status(0));
3748
}

0 commit comments

Comments
 (0)