diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index b9447e9f968..40296b4181e 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1,6 +1,6 @@ use support::ChannelChanger; use support::registry::{self, alt_api_path, Package}; -use support::{execs, paths, project}; +use support::{basic_manifest, execs, paths, project}; use support::hamcrest::assert_that; use std::fs::File; use std::io::Write; @@ -249,15 +249,7 @@ fn registry_and_path_dep_works() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index fc4edaba6d3..9b8ab632051 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -1,4 +1,4 @@ -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::registry::Package; use support::hamcrest::assert_that; @@ -598,36 +598,10 @@ Caused by: #[test] fn duplicate_deps() { let p = project() - .file( - "shim-bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "shim-bar/src/lib.rs", - r#" - pub fn a() {} - "#, - ) - .file( - "linux-bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "linux-bar/src/lib.rs", - r#" - pub fn a() {} - "#, - ) + .file("shim-bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("shim-bar/src/lib.rs", "pub fn a() {}") + .file("linux-bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("linux-bar/src/lib.rs", "pub fn a() {}") .file( "Cargo.toml", r#" @@ -663,36 +637,10 @@ have a single canonical source path irrespective of build target. #[test] fn duplicate_deps_diff_sources() { let p = project() - .file( - "shim-bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "shim-bar/src/lib.rs", - r#" - pub fn a() {} - "#, - ) - .file( - "linux-bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "linux-bar/src/lib.rs", - r#" - pub fn a() {} - "#, - ) + .file("shim-bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("shim-bar/src/lib.rs", "pub fn a() {}") + .file("linux-bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("linux-bar/src/lib.rs", "pub fn a() {}") .file( "Cargo.toml", r#" @@ -766,12 +714,7 @@ warning: unused manifest key: target.foo.bar bulid = "foo" "#, ) - .file( - "src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); assert_that( p.cargo("build"), @@ -798,12 +741,7 @@ warning: unused manifest key: project.bulid build = "foo" "#, ) - .file( - "src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); assert_that( p.cargo("build"), @@ -828,14 +766,7 @@ fn unused_keys_in_virtual_manifest() { bulid = "foo" "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - version = "0.0.1" - name = "bar" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", r"") .build(); assert_that( @@ -884,12 +815,7 @@ to use. This will be considered an error in future versions #[test] fn invalid_toml_historically_allowed_is_warned() { let p = project() - .file( - ".cargo/config", - r#" - [bar] baz = 2 - "#, - ) + .file(".cargo/config", "[bar] baz = 2") .file("src/main.rs", "fn main() {}") .build(); @@ -947,12 +873,7 @@ This will be considered an error in future versions fn bad_source_config1() { let p = project() .file("src/lib.rs", "") - .file( - ".cargo/config", - r#" - [source.foo] - "#, - ) + .file(".cargo/config", "[source.foo]") .build(); assert_that( diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index b40e5045f8f..61f4c18eac3 100644 --- a/tests/testsuite/bench.rs +++ b/tests/testsuite/bench.rs @@ -3,7 +3,7 @@ use std::str; use cargo::util::process; use support::{is_nightly, ChannelChanger}; use support::paths::CargoPathExt; -use support::{basic_bin_manifest, basic_lib_manifest, execs, project}; +use support::{basic_manifest, basic_bin_manifest, basic_lib_manifest, execs, project}; use support::hamcrest::{assert_that, existing_file}; #[test] @@ -724,9 +724,7 @@ fn dont_run_examples() { .file("src/lib.rs", r"") .file( "examples/dont-run-me-i-will-fail.rs", - r#" - fn main() { panic!("Examples should not be run by 'cargo test'"); } - "#, + r#"fn main() { panic!("Examples should not be run by 'cargo test'"); }"#, ) .build(); assert_that(p.cargo("bench"), execs().with_status(0)); @@ -876,15 +874,7 @@ fn lib_with_standard_name() { } let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "syntax" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("syntax", "0.0.1")) .file( "src/lib.rs", " @@ -952,12 +942,7 @@ fn lib_with_standard_name2() { doctest = false "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/main.rs", " @@ -1051,12 +1036,7 @@ fn bench_dylib() { crate_type = ["dylib"] "#, ) - .file( - "bar/src/lib.rs", - " - pub fn baz() {} - ", - ) + .file("bar/src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -1271,13 +1251,7 @@ fn test_a_bench() { "#, ) .file("src/lib.rs", "") - .file( - "benches/b.rs", - r#" - #[test] - fn foo() {} - "#, - ) + .file("benches/b.rs", "#[test] fn foo() {}") .build(); assert_that( @@ -1491,12 +1465,7 @@ fn bench_all_workspace() { [workspace] "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file( "benches/foo.rs", r#" @@ -1509,20 +1478,8 @@ fn bench_all_workspace() { fn bench_foo(_: &mut Bencher) -> () { () } "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .file( "bar/benches/bar.rs", r#" @@ -1566,20 +1523,8 @@ fn bench_all_exclude() { members = ["bar", "baz"] "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file( "bar/src/lib.rs", r#" @@ -1593,23 +1538,8 @@ fn bench_all_exclude() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - #[test] - pub fn baz() { - break_the_build(); - } - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "#[test] pub fn baz() { break_the_build(); }") .build(); assert_that( @@ -1636,20 +1566,8 @@ fn bench_all_virtual_manifest() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .file( "bar/benches/bar.rs", r#" @@ -1662,20 +1580,8 @@ fn bench_all_virtual_manifest() { fn bench_bar(_: &mut Bencher) -> () { () } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .file( "baz/benches/baz.rs", r#" @@ -1721,12 +1627,7 @@ fn legacy_bench_name() { name = "bench" "#, ) - .file( - "src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/bench.rs", r#" @@ -1765,20 +1666,8 @@ fn bench_virtual_manifest_all_implied() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn foo() {}") .file( "bar/benches/bar.rs", r#" @@ -1789,20 +1678,8 @@ fn bench_virtual_manifest_all_implied() { fn bench_bar(_: &mut Bencher) -> () { () } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .file( "baz/benches/baz.rs", r#" diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 1f05dc5dace..34e91825294 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4,10 +4,10 @@ use std::io::prelude::*; use cargo::util::paths::dylib_path_envvar; use cargo::util::{process, ProcessBuilder}; -use support::{is_nightly, rustc_host, sleep_ms}; +use support::{basic_manifest, basic_bin_manifest, basic_lib_manifest, is_nightly, rustc_host, sleep_ms}; use support::paths::{root, CargoPathExt}; use support::ProjectBuilder; -use support::{BASIC_MANIFEST, basic_bin_manifest, execs, main_file, project}; +use support::{execs, main_file, project}; use support::registry::Package; use support::ChannelChanger; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; @@ -275,13 +275,7 @@ fn cargo_compile_duplicate_build_targets() { [dependencies] "#, ) - .file( - "src/main.rs", - r#" - #![allow(warnings)] - fn main() {} - "#, - ) + .file("src/main.rs", "#![allow(warnings)] fn main() {}") .build(); assert_that( @@ -299,15 +293,7 @@ warning: file found to be present in multiple build targets: [..]main.rs #[test] fn cargo_compile_with_invalid_version() { let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - authors = [] - version = "1.0" - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "1.0")) .build(); assert_that( @@ -317,7 +303,7 @@ fn cargo_compile_with_invalid_version() { [ERROR] failed to parse manifest at `[..]` Caused by: - Expected dot for key `project.version` + Expected dot for key `package.version` ", ), ) @@ -326,15 +312,7 @@ Caused by: #[test] fn cargo_compile_with_invalid_package_name() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "" - authors = [] - version = "0.0.0" - "#, - ) + .file("Cargo.toml", &basic_manifest("", "0.0.0")) .build(); assert_that( @@ -603,20 +581,7 @@ fn cargo_compile_with_warnings_in_a_dep_package() { "#, ) .file("src/foo.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"])) - .file( - "bar/Cargo.toml", - r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - - name = "bar" - "#, - ) + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) .file( "bar/src/bar.rs", r#" @@ -687,16 +652,7 @@ fn cargo_compile_with_nested_deps_inferred() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.5.0")) .file( "baz/src/lib.rs", r#" @@ -762,16 +718,7 @@ fn cargo_compile_with_nested_deps_correct_bin() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.5.0")) .file( "baz/src/lib.rs", r#" @@ -838,20 +785,7 @@ fn cargo_compile_with_nested_deps_shorthand() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - - name = "baz" - "#, - ) + .file("baz/Cargo.toml", &basic_lib_manifest("baz")) .file( "baz/src/baz.rs", r#" @@ -924,20 +858,7 @@ fn cargo_compile_with_nested_deps_longhand() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - - name = "baz" - "#, - ) + .file("baz/Cargo.toml", &basic_lib_manifest("baz")) .file( "baz/src/baz.rs", r#" @@ -1011,12 +932,7 @@ fn cargo_compile_with_filename() { fn main() { println!("hello a.rs"); } "#, ) - .file( - "examples/a.rs", - r#" - fn main() { println!("example"); } - "#, - ) + .file("examples/a.rs", r#"fn main() { println!("example"); }"#) .build(); assert_that( @@ -1070,15 +986,7 @@ fn cargo_compile_path_with_offline() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -1093,14 +1001,7 @@ fn cargo_compile_path_with_offline() { #[test] fn cargo_compile_with_downloaded_dependency_with_offline() { Package::new("present_dep", "1.2.3") - .file( - "Cargo.toml", - r#" - [project] - name = "present_dep" - version = "1.2.3" - "#, - ) + .file("Cargo.toml", &basic_manifest("present_dep", "1.2.3")) .file("src/lib.rs", "") .publish(); @@ -1191,29 +1092,12 @@ fn compile_offline_without_maxvers_cached() { Package::new("present_dep", "1.2.2").publish(); Package::new("present_dep", "1.2.3") - .file( - "Cargo.toml", - r#" - [project] - name = "present_dep" - version = "1.2.3" - "#, - ) - .file( - "src/lib.rs", - r#"pub fn get_version()->&'static str {"1.2.3"}"#, - ) + .file("Cargo.toml", &basic_manifest("present_dep", "1.2.3")) + .file("src/lib.rs", r#"pub fn get_version()->&'static str {"1.2.3"}"#) .publish(); Package::new("present_dep", "1.2.5") - .file( - "Cargo.toml", - r#" - [project] - name = "present_dep" - version = "1.2.5" - "#, - ) + .file("Cargo.toml", &basic_manifest("present_dep", "1.2.5")) .file("src/lib.rs", r#"pub fn get_version(){"1.2.5"}"#) .publish(); @@ -1444,15 +1328,7 @@ fn compile_path_dep_then_change_version() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -1460,14 +1336,7 @@ fn compile_path_dep_then_change_version() { File::create(&p.root().join("bar/Cargo.toml")) .unwrap() - .write_all( - br#" - [package] - name = "bar" - version = "0.0.2" - authors = [] - "#, - ) + .write_all(basic_manifest("bar", "0.0.2").as_bytes()) .unwrap(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -1476,12 +1345,7 @@ fn compile_path_dep_then_change_version() { #[test] fn ignores_carriage_return_in_lockfile() { let p = project() - .file( - "src/main.rs", - r#" - mod a; fn main() {} - "#, - ) + .file("src/main.rs", r"mod a; fn main() {}") .file("src/a.rs", "") .build(); @@ -1765,12 +1629,7 @@ fn crate_library_path_env_var() { #[test] fn build_with_fake_libc_not_loading() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .file("libc.so.6", r#""#) .build(); @@ -1800,12 +1659,7 @@ fn many_crate_types_old_style_lib_location() { crate_type = ["rlib", "dylib"] "#, ) - .file( - "src/foo.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/foo.rs", "pub fn foo() {}") .build(); assert_that( p.cargo("build"), @@ -1839,12 +1693,7 @@ fn many_crate_types_correct() { crate_type = ["rlib", "dylib"] "#, ) - .file( - "src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -2367,12 +2216,7 @@ fn release_build_ndebug() { #[test] fn inferred_main_bin() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -2394,48 +2238,20 @@ fn deletion_causes_failure() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); assert_that(p.cargo("build"), execs().with_status(0)); - p.change_file("Cargo.toml", BASIC_MANIFEST); + p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1")); assert_that(p.cargo("build"), execs().with_status(101)); } #[test] fn bad_cargo_toml_in_target_dir() { let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("target/Cargo.toml", "bad-toml") .build(); @@ -2446,28 +2262,9 @@ fn bad_cargo_toml_in_target_dir() { #[test] fn lib_with_standard_name() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "syntax" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) - .file( - "src/main.rs", - " - extern crate syntax; - fn main() { syntax::foo() } - ", - ) + .file("Cargo.toml", &basic_manifest("syntax", "0.0.1")) + .file("src/lib.rs", "pub fn foo() {}") + .file("src/main.rs", "extern crate syntax; fn main() { syntax::foo() }") .build(); assert_that( @@ -2525,15 +2322,7 @@ fn staticlib_rlib_and_bin() { "#, ) .file("src/lib.rs", "pub fn foo() {}") - .file( - "src/main.rs", - r#" - extern crate foo; - - fn main() { - foo::foo(); - }"#, - ) + .file("src/main.rs", "extern crate foo; fn main() { foo::foo(); }") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -2694,15 +2483,7 @@ fn dep_no_libs() { "#, ) .file("src/lib.rs", "pub fn bar() -> i32 { 1 }") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.0")) .file("bar/src/main.rs", "") .build(); assert_that(foo.cargo("build"), execs().with_status(0)); @@ -2736,15 +2517,7 @@ fn recompile_space_in_name() { fn ignore_bad_directories() { use std::os::unix::prelude::*; let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) .file("src/lib.rs", "") .build(); let dir = foo.root().join("tmp"); @@ -2761,22 +2534,9 @@ fn ignore_bad_directories() { #[test] fn bad_cargo_config() { let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) .file("src/lib.rs", "") - .file( - ".cargo/config", - r#" - this is not valid toml - "#, - ) + .file(".cargo/config", "this is not valid toml") .build(); assert_that( foo.cargo("build").arg("-v"), @@ -2791,7 +2551,7 @@ Caused by: could not parse input as TOML Caused by: - expected an equals, found an identifier at line 2 + expected an equals, found an identifier at line 1 ", ), ); @@ -2821,71 +2581,28 @@ fn cargo_platform_specific_dependency() { host = host ), ) + .file("src/main.rs", "extern crate dep; fn main() { dep::dep() }") + .file("tests/foo.rs", "extern crate dev; #[test] fn foo() { dev::dev() }") + .file("build.rs", "extern crate build; fn main() { build::build(); }") + .file("dep/Cargo.toml", &basic_manifest("dep", "0.5.0")) + .file("dep/src/lib.rs", "pub fn dep() {}") + .file("build/Cargo.toml", &basic_manifest("build", "0.5.0")) + .file("build/src/lib.rs", "pub fn build() {}") + .file("dev/Cargo.toml", &basic_manifest("dev", "0.5.0")) + .file("dev/src/lib.rs", "pub fn dev() {}") + .build(); + + assert_that(p.cargo("build"), execs().with_status(0)); + + assert_that(&p.bin("foo"), existing_file()); + assert_that(p.cargo("test"), execs().with_status(0)); +} + +#[test] +fn bad_platform_specific_dependency() { + let p = project() .file( - "src/main.rs", - r#" - extern crate dep; - fn main() { dep::dep() } - "#, - ) - .file( - "tests/foo.rs", - r#" - extern crate dev; - #[test] - fn foo() { dev::dev() } - "#, - ) - .file( - "build.rs", - r#" - extern crate build; - fn main() { build::build(); } - "#, - ) - .file( - "dep/Cargo.toml", - r#" - [project] - name = "dep" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) - .file("dep/src/lib.rs", "pub fn dep() {}") - .file( - "build/Cargo.toml", - r#" - [project] - name = "build" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) - .file("build/src/lib.rs", "pub fn build() {}") - .file( - "dev/Cargo.toml", - r#" - [project] - name = "dev" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) - .file("dev/src/lib.rs", "pub fn dev() {}") - .build(); - - assert_that(p.cargo("build"), execs().with_status(0)); - - assert_that(&p.bin("foo"), existing_file()); - assert_that(p.cargo("test"), execs().with_status(0)); -} - -#[test] -fn bad_platform_specific_dependency() { - let p = project() - .file( - "Cargo.toml", + "Cargo.toml", r#" [project] @@ -2898,26 +2615,8 @@ fn bad_platform_specific_dependency() { "#, ) .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"])) - .file( - "bar/Cargo.toml", - r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - extern crate baz; - - pub fn gimme() -> String { - format!("") - } - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) + .file("bar/src/lib.rs", r#"extern crate baz; pub fn gimme() -> String { format!("") }"#) .build(); assert_that(p.cargo("build"), execs().with_status(101)); @@ -2939,28 +2638,9 @@ fn cargo_platform_specific_dependency_wrong_platform() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - invalid rust file, should not be compiled - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) + .file("bar/src/lib.rs", "invalid rust file, should not be compiled") .build(); p.cargo("build").exec_with_output().unwrap(); @@ -3080,15 +2760,6 @@ fn example_as_proc_macro() { #[test] fn example_bin_same_name() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .file("examples/foo.rs", "fn main() {}") .build(); @@ -3117,15 +2788,6 @@ fn example_bin_same_name() { #[test] fn compile_then_delete() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .build(); @@ -3171,15 +2833,7 @@ fn transitive_dependencies_not_available() { "#, ) .file("a/src/lib.rs", "extern crate bbbbb;") - .file( - "b/Cargo.toml", - r#" - [package] - name = "bbbbb" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("bbbbb", "0.0.1")) .file("b/src/lib.rs", "") .build(); @@ -3261,15 +2915,7 @@ fn predictable_filenames() { #[test] fn dashes_to_underscores() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo-bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo-bar", "0.0.1")) .file("src/lib.rs", "") .file("src/main.rs", "extern crate foo_bar; fn main() {}") .build(); @@ -3303,15 +2949,6 @@ fn dashes_in_crate_name_bad() { #[test] fn rustc_env_var() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/lib.rs", "") .build(); @@ -3334,15 +2971,6 @@ Caused by: #[test] fn filtering() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/lib.rs", "") .file("src/bin/a.rs", "fn main() {}") .file("src/bin/b.rs", "fn main() {}") @@ -3366,15 +2994,6 @@ fn filtering() { #[test] fn filtering_implicit_bins() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/lib.rs", "") .file("src/bin/a.rs", "fn main() {}") .file("src/bin/b.rs", "fn main() {}") @@ -3392,15 +3011,6 @@ fn filtering_implicit_bins() { #[test] fn filtering_implicit_examples() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/lib.rs", "") .file("src/bin/a.rs", "fn main() {}") .file("src/bin/b.rs", "fn main() {}") @@ -3418,15 +3028,6 @@ fn filtering_implicit_examples() { #[test] fn ignore_dotfile() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/bin/.a.rs", "") .file("src/bin/a.rs", "fn main() {}") .build(); @@ -3437,15 +3038,6 @@ fn ignore_dotfile() { #[test] fn ignore_dotdirs() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/bin/a.rs", "fn main() {}") .file(".git/Cargo.toml", "") .file(".pc/dummy-fix.patch/Cargo.toml", "") @@ -3457,15 +3049,6 @@ fn ignore_dotdirs() { #[test] fn dotdir_root() { let p = ProjectBuilder::new(root().join(".foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/bin/a.rs", "fn main() {}") .build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -3474,15 +3057,6 @@ fn dotdir_root() { #[test] fn custom_target_dir_env() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .build(); @@ -3542,15 +3116,6 @@ fn custom_target_dir_env() { #[test] fn custom_target_dir_line_parameter() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .build(); @@ -3650,18 +3215,7 @@ fn build_multiple_packages() { "#, ) .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) - .file( - "d1/Cargo.toml", - r#" - [package] - name = "d1" - version = "0.0.1" - authors = [] - - [[bin]] - name = "d1" - "#, - ) + .file("d1/Cargo.toml", &basic_bin_manifest("d1")) .file("d1/src/lib.rs", "") .file("d1/src/main.rs", "fn main() { println!(\"d1\"); }") .file( @@ -3721,18 +3275,7 @@ fn invalid_spec() { "#, ) .file("src/bin/foo.rs", &main_file(r#""i am foo""#, &[])) - .file( - "d1/Cargo.toml", - r#" - [package] - name = "d1" - version = "0.0.1" - authors = [] - - [[bin]] - name = "d1" - "#, - ) + .file("d1/Cargo.toml", &basic_bin_manifest("d1")) .file("d1/src/lib.rs", "") .file("d1/src/main.rs", "fn main() { println!(\"d1\"); }") .build(); @@ -3801,16 +3344,7 @@ fn panic_abort_compiles_with_panic_abort() { #[test] fn explicit_color_config_is_propagated_to_rustc() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - - name = "test" - version = "0.0.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("test", "0.0.0")) .file("src/lib.rs", "") .build(); assert_that( @@ -3852,16 +3386,7 @@ fn compiler_json_error_format() { ) .file("build.rs", "fn main() { println!(\"cargo:rustc-cfg=xyz\") }") .file("src/main.rs", "fn main() { let unused = 92; }") - .file( - "bar/Cargo.toml", - r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("bar/src/lib.rs", r#"fn dead() {}"#) .build(); @@ -4184,26 +3709,9 @@ fn build_all_workspace() { [workspace] "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -4230,42 +3738,11 @@ fn build_all_exclude() { members = ["bar", "baz"] "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() { - break_the_build(); - } - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() { break_the_build(); }") .build(); assert_that( @@ -4299,14 +3776,7 @@ fn build_all_workspace_implicit_examples() { .file("src/bin/b.rs", "fn main() {}") .file("examples/c.rs", "fn main() {}") .file("examples/d.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .file("bar/src/bin/e.rs", "fn main() {}") .file("bar/src/bin/f.rs", "fn main() {}") @@ -4342,34 +3812,10 @@ fn build_all_virtual_manifest() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .build(); // The order in which bar and baz are built is not guaranteed @@ -4397,34 +3843,10 @@ fn build_virtual_manifest_all_implied() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .build(); // The order in which bar and baz are built is not guaranteed @@ -4452,34 +3874,10 @@ fn build_virtual_manifest_one_project() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file( "bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file( "baz/src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -4505,27 +3903,13 @@ fn build_all_virtual_manifest_implicit_examples() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .file("bar/src/bin/a.rs", "fn main() {}") .file("bar/src/bin/b.rs", "fn main() {}") .file("bar/examples/c.rs", "fn main() {}") .file("bar/examples/d.rs", "fn main() {}") - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) .file("baz/src/lib.rs", "") .file("baz/src/bin/e.rs", "fn main() {}") .file("baz/src/bin/f.rs", "fn main() {}") @@ -4577,12 +3961,7 @@ fn build_all_member_dependency_same_name() { a = "0.1.0" "#, ) - .file( - "a/src/lib.rs", - r#" - pub fn a() {} - "#, - ) + .file("a/src/lib.rs", "pub fn a() {}") .build(); Package::new("a", "0.1.0").publish(); @@ -4616,21 +3995,8 @@ fn run_proper_binary() { "#, ) .file("src/lib.rs", "") - .file( - "src/bin/main.rs", - r#" - fn main() { - panic!("This should never be run."); - } - "#, - ) - .file( - "src/bin/other.rs", - r#" - fn main() { - } - "#, - ) + .file("src/bin/main.rs", r#"fn main() { panic!("This should never be run."); }"#) + .file("src/bin/other.rs", "fn main() {}") .build(); assert_that( @@ -4642,25 +4008,9 @@ fn run_proper_binary() { #[test] fn run_proper_binary_main_rs() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - authors = [] - version = "0.0.0" - [[bin]] - name = "foo" - "#, - ) + .file("Cargo.toml", &basic_bin_manifest("foo")) .file("src/lib.rs", "") - .file( - "src/bin/main.rs", - r#" - fn main() { - } - "#, - ) + .file("src/bin/main.rs", "fn main() {}") .build(); assert_that( @@ -4685,22 +4035,8 @@ fn run_proper_alias_binary_from_src() { name = "bar" "#, ) - .file( - "src/foo.rs", - r#" - fn main() { - println!("foo"); - } - "#, - ) - .file( - "src/bar.rs", - r#" - fn main() { - println!("bar"); - } - "#, - ) + .file("src/foo.rs", r#"fn main() { println!("foo"); }"#) + .file("src/bar.rs", r#"fn main() { println!("bar"); }"#) .build(); assert_that(p.cargo("build").arg("--all"), execs().with_status(0)); @@ -4730,14 +4066,7 @@ fn run_proper_alias_binary_main_rs() { name = "bar" "#, ) - .file( - "src/main.rs", - r#" - fn main() { - println!("main"); - } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("main"); }"#) .build(); assert_that(p.cargo("build").arg("--all"), execs().with_status(0)); @@ -4754,32 +4083,9 @@ fn run_proper_alias_binary_main_rs() { #[test] fn run_proper_binary_main_rs_as_foo() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - authors = [] - version = "0.0.0" - [[bin]] - name = "foo" - "#, - ) - .file( - "src/foo.rs", - r#" - fn main() { - panic!("This should never be run."); - } - "#, - ) - .file( - "src/main.rs", - r#" - fn main() { - } - "#, - ) + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", r#" fn main() { panic!("This should never be run."); }"#) + .file("src/main.rs", "fn main() {}") .build(); assert_that( @@ -4915,12 +4221,7 @@ fn deterministic_cfg_flags() { } "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( @@ -4968,18 +4269,7 @@ fn explicit_bins_without_paths() { #[test] fn no_bin_in_src_with_lib() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - - [[bin]] - name = "foo" - "#, - ) + .file("Cargo.toml", &basic_bin_manifest("foo")) .file("src/lib.rs", "") .file("src/foo.rs", "fn main() {}") .build(); @@ -4999,15 +4289,6 @@ Caused by: #[test] fn inferred_bins() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .file("src/bin/bar.rs", "fn main() {}") .file("src/bin/baz/main.rs", "fn main() {}") @@ -5023,15 +4304,6 @@ fn inferred_bins() { fn inferred_bins_duplicate_name() { // this should fail, because we have two binaries with the same name let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .file("src/bin/bar.rs", "fn main() {}") .file("src/bin/bar/main.rs", "fn main() {}") @@ -5071,15 +4343,6 @@ fn inferred_bin_path() { #[test] fn inferred_examples() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/lib.rs", "fn main() {}") .file("examples/bar.rs", "fn main() {}") .file("examples/baz/main.rs", "fn main() {}") @@ -5093,15 +4356,6 @@ fn inferred_examples() { #[test] fn inferred_tests() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/lib.rs", "fn main() {}") .file("tests/bar.rs", "fn main() {}") .file("tests/baz/main.rs", "fn main() {}") @@ -5116,15 +4370,6 @@ fn inferred_tests() { #[test] fn inferred_benchmarks() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/lib.rs", "fn main() {}") .file("benches/bar.rs", "fn main() {}") .file("benches/baz/main.rs", "fn main() {}") @@ -5211,14 +4456,6 @@ fn uplift_dsym_of_bin_on_mac() { return; } let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - "#, - ) .file("src/main.rs", "fn main() { panic!(); }") .file("src/bin/b.rs", "fn main() { panic!(); }") .file("examples/c.rs", "fn main() { panic!(); }") @@ -5251,14 +4488,6 @@ fn uplift_pdb_of_bin_on_windows() { return; } let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - "#, - ) .file("src/main.rs", "fn main() { panic!(); }") .file("src/bin/b.rs", "fn main() { panic!(); }") .file("examples/c.rs", "fn main() { panic!(); }") @@ -5283,15 +4512,6 @@ fn uplift_pdb_of_bin_on_windows() { #[test] fn build_filter_infer_profile() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/lib.rs", "") .file("src/main.rs", "fn main() {}") .file("tests/t1.rs", "") @@ -5361,15 +4581,6 @@ fn build_filter_infer_profile() { #[test] fn targets_selected_default() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .build(); assert_that( @@ -5393,15 +4604,6 @@ fn targets_selected_default() { #[test] fn targets_selected_all() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .build(); assert_that( @@ -5425,15 +4627,6 @@ fn targets_selected_all() { #[test] fn all_targets_no_lib() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/main.rs", "fn main() {}") .build(); assert_that( diff --git a/tests/testsuite/build_auth.rs b/tests/testsuite/build_auth.rs index 3c3450f195e..869b6d1289b 100644 --- a/tests/testsuite/build_auth.rs +++ b/tests/testsuite/build_auth.rs @@ -7,7 +7,7 @@ use std::thread; use git2; use bufstream::BufStream; use support::paths; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; // Test that HTTP auth is offered from `credential.helper` @@ -72,15 +72,7 @@ fn http_auth_offered() { }); let script = project().at("script") - .file( - "Cargo.toml", - r#" - [project] - name = "script" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("script", "0.1.0")) .file( "src/main.rs", r#" diff --git a/tests/testsuite/build_lib.rs b/tests/testsuite/build_lib.rs index d619f804910..28265000009 100644 --- a/tests/testsuite/build_lib.rs +++ b/tests/testsuite/build_lib.rs @@ -1,4 +1,4 @@ -use support::{basic_bin_manifest, execs, project, Project}; +use support::{basic_manifest, basic_bin_manifest, execs, project, Project}; use support::hamcrest::assert_that; fn verbose_output_for_lib(p: &Project) -> String { @@ -22,12 +22,7 @@ fn verbose_output_for_lib(p: &Project) -> String { #[test] fn build_lib_only() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -43,12 +38,7 @@ fn build_lib_only() { fn build_with_no_lib() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( @@ -76,23 +66,9 @@ fn build_with_relative_cargo_home_path() { "test-dependency" = { path = "src/test_dependency" } "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/test_dependency/src/lib.rs", r#" "#) - .file( - "src/test_dependency/Cargo.toml", - r#" - [package] - - name = "test-dependency" - version = "0.0.1" - authors = ["wycats@example.com"] - "#, - ) + .file("src/test_dependency/Cargo.toml", &basic_manifest("test-dependency", "0.0.1")) .build(); assert_that( diff --git a/tests/testsuite/build_plan.rs b/tests/testsuite/build_plan.rs index 8e275c76ef5..f266e726ca6 100644 --- a/tests/testsuite/build_plan.rs +++ b/tests/testsuite/build_plan.rs @@ -1,5 +1,5 @@ use support::ChannelChanger; -use support::{basic_bin_manifest, execs, main_file, project}; +use support::{basic_manifest, basic_bin_manifest, execs, main_file, project}; use support::hamcrest::{assert_that, existing_file, is_not}; #[test] @@ -67,15 +67,7 @@ fn cargo_build_plan_single_dep() { fn test() { foo(); } "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 89a760ee9c8..0e84b8445d3 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -8,7 +8,7 @@ use std::time::Duration; use cargo::util::paths::remove_dir_all; use support::{rustc_host, sleep_ms}; -use support::{cross_compile, execs, project}; +use support::{basic_manifest, cross_compile, execs, project}; use support::paths::CargoPathExt; use support::registry::Package; use support::hamcrest::{assert_that, existing_dir, existing_file}; @@ -27,20 +27,8 @@ fn custom_build_script_failed() { build = "build.rs" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "build.rs", - r#" - fn main() { - std::process::exit(101); - } - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("build.rs", "fn main() { std::process::exit(101); }") .build(); assert_that( p.cargo("build").arg("-v"), @@ -75,12 +63,7 @@ fn custom_build_env_vars() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file( "bar/Cargo.toml", r#" @@ -95,12 +78,7 @@ fn custom_build_env_vars() { foo = [] "#, ) - .file( - "bar/src/lib.rs", - r#" - pub fn hello() {} - "#, - ); + .file("bar/src/lib.rs", "pub fn hello() {}"); let file_content = format!( r#" @@ -208,20 +186,8 @@ fn custom_build_script_wrong_rustc_flags() { build = "build.rs" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-flags=-aaa -bbb"); - } - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("build.rs", r#"fn main() { println!("cargo:rustc-flags=-aaa -bbb"); }"#) .build(); assert_that( @@ -249,9 +215,7 @@ fn custom_build_script_rustc_flags() { [dependencies.foo] path = "foo" "#) - .file("src/main.rs", r#" - fn main() {} - "#) + .file("src/main.rs", "fn main() {}") .file("foo/Cargo.toml", r#" [project] @@ -608,12 +572,7 @@ fn only_rerun_build_script() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() {} - "#, - ) + .file("build.rs", "fn main() {}") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -717,12 +676,7 @@ fn testing_and_such() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() {} - "#, - ) + .file("build.rs", "fn main() {}") .build(); println!("build"); @@ -811,14 +765,7 @@ fn propagation_of_l_flags() { "#, ) .file("a/src/lib.rs", "") - .file( - "a/build.rs", - r#" - fn main() { - println!("cargo:rustc-flags=-L bar"); - } - "#, - ) + .file("a/build.rs", r#"fn main() { println!("cargo:rustc-flags=-L bar"); }"#) .file( "b/Cargo.toml", r#" @@ -956,15 +903,7 @@ fn build_deps_simple() { fn main() {} ", ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.5.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.5.0")) .file("a/src/lib.rs", "") .build(); @@ -1012,15 +951,7 @@ fn build_deps_not_for_normal() { fn main() {} ", ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "aaaaa" - version = "0.5.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("aaaaa", "0.5.0")) .file("a/src/lib.rs", "") .build(); @@ -1083,15 +1014,7 @@ fn build_cmd_with_a_build_cmd() { "a/build.rs", "#[allow(unused_extern_crates)] extern crate b; fn main() {}", ) - .file( - "b/Cargo.toml", - r#" - [project] - name = "b" - version = "0.5.0" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.5.0")) .file("b/src/lib.rs", "") .build(); @@ -1585,13 +1508,7 @@ fn build_script_with_dynamic_native_dependency() { plugin = true "#, ) - .file( - "src/lib.rs", - r#" - #[no_mangle] - pub extern fn foo() {} - "#, - ) + .file("src/lib.rs", "#[no_mangle] pub extern fn foo() {}") .build(); let foo = project().at("ws/foo") @@ -1608,13 +1525,7 @@ fn build_script_with_dynamic_native_dependency() { path = "bar" "#, ) - .file( - "build.rs", - r#" - extern crate bar; - fn main() { bar::bar() } - "#, - ) + .file("build.rs", "extern crate bar; fn main() { bar::bar() }") .file("src/lib.rs", "") .file( "bar/Cargo.toml", @@ -1747,13 +1658,7 @@ fn build_script_with_lto() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() { - } - "#, - ) + .file("build.rs", "fn main() {}") .build(); assert_that(p.cargo("build"), execs().with_status(0)); } @@ -1791,15 +1696,7 @@ fn test_duplicate_deps() { fn main() { bar::do_nothing() } "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "pub fn do_nothing() {}") .build(); @@ -1819,21 +1716,8 @@ fn cfg_feedback() { build = "build.rs" "#, ) - .file( - "src/main.rs", - " - #[cfg(foo)] - fn main() {} - ", - ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-cfg=foo"); - } - "#, - ) + .file("src/main.rs", "#[cfg(foo)] fn main() {}") + .file("build.rs", r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#) .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); } @@ -1854,13 +1738,7 @@ fn cfg_override() { build = "build.rs" "#, ) - .file( - "src/main.rs", - " - #[cfg(foo)] - fn main() {} - ", - ) + .file("src/main.rs", "#[cfg(foo)] fn main() {}") .file("build.rs", "") .file( ".cargo/config", @@ -1890,14 +1768,7 @@ fn cfg_test() { build = "build.rs" "#, ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-cfg=foo"); - } - "#, - ) + .file("build.rs", r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#) .file( "src/lib.rs", r#" @@ -1920,14 +1791,7 @@ fn cfg_test() { } "#, ) - .file( - "tests/test.rs", - r#" - #[cfg(foo)] - #[test] - fn test_bar() {} - "#, - ) + .file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}") .build(); assert_that( p.cargo("test").arg("-v"), @@ -1969,21 +1833,8 @@ fn cfg_doc() { path = "bar" "#, ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-cfg=foo"); - } - "#, - ) - .file( - "src/lib.rs", - r#" - #[cfg(foo)] - pub fn foo() {} - "#, - ) + .file("build.rs", r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#) + .file("src/lib.rs", "#[cfg(foo)] pub fn foo() {}") .file( "bar/Cargo.toml", r#" @@ -1994,21 +1845,8 @@ fn cfg_doc() { build = "build.rs" "#, ) - .file( - "bar/build.rs", - r#" - fn main() { - println!("cargo:rustc-cfg=bar"); - } - "#, - ) - .file( - "bar/src/lib.rs", - r#" - #[cfg(bar)] - pub fn bar() {} - "#, - ) + .file("bar/build.rs", r#"fn main() { println!("cargo:rustc-cfg=bar"); }"#) + .file("bar/src/lib.rs", "#[cfg(bar)] pub fn bar() {}") .build(); assert_that(p.cargo("doc"), execs().with_status(0)); assert_that(&p.root().join("target/doc"), existing_dir()); @@ -2069,14 +1907,7 @@ fn cfg_override_test() { } "#, ) - .file( - "tests/test.rs", - r#" - #[cfg(foo)] - #[test] - fn test_bar() {} - "#, - ) + .file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}") .build(); assert_that( p.cargo("test").arg("-v"), @@ -2130,13 +1961,7 @@ fn cfg_override_doc() { ), ) .file("build.rs", "") - .file( - "src/lib.rs", - r#" - #[cfg(foo)] - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "#[cfg(foo)] pub fn foo() {}") .file( "bar/Cargo.toml", r#" @@ -2149,13 +1974,7 @@ fn cfg_override_doc() { "#, ) .file("bar/build.rs", "") - .file( - "bar/src/lib.rs", - r#" - #[cfg(bar)] - pub fn bar() {} - "#, - ) + .file("bar/src/lib.rs", "#[cfg(bar)] pub fn bar() {}") .build(); assert_that(p.cargo("doc"), execs().with_status(0)); assert_that(&p.root().join("target/doc"), existing_dir()); @@ -2191,14 +2010,7 @@ fn env_build() { } "#, ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-env=FOO=foo"); - } - "#, - ) + .file("build.rs", r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#) .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); assert_that( @@ -2220,20 +2032,8 @@ fn env_test() { build = "build.rs" "#, ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-env=FOO=foo"); - } - "#, - ) - .file( - "src/lib.rs", - r#" - pub const FOO: &'static str = env!("FOO"); - "#, - ) + .file("build.rs", r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#) + .file("src/lib.rs", r#"pub const FOO: &'static str = env!("FOO"); "#) .file( "tests/test.rs", r#" @@ -2289,13 +2089,7 @@ fn env_doc() { fn main() {} "#, ) - .file( - "build.rs", - r#" - fn main() { - println!("cargo:rustc-env=FOO=foo"); - } - "#, + .file("build.rs", r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#, ) .build(); assert_that(p.cargo("doc").arg("-v"), execs().with_status(0)); @@ -2963,13 +2757,7 @@ fn non_utf8_output() { } "#, ) - .file( - "src/main.rs", - r#" - #[cfg(foo)] - fn main() {} - "#, - ) + .file("src/main.rs", "#[cfg(foo)] fn main() {}") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -3620,12 +3408,7 @@ fn deterministic_rustc_dependency_flags() { dep4 = "*" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( @@ -3719,27 +3502,13 @@ fn rename_with_link_search_path() { crate-type = ["cdylib"] "#, ) - .file( - "src/lib.rs", - " - #[no_mangle] - pub extern fn cargo_test_foo() {} - ", - ); + .file("src/lib.rs", "#[no_mangle] pub extern fn cargo_test_foo() {}"); let p = p.build(); assert_that(p.cargo("build"), execs().with_status(0)); let p2 = project().at("bar") - .file( - "Cargo.toml", - r#" - [project] - name = "bar" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file( "build.rs", r#" @@ -3890,21 +3659,8 @@ fn optional_build_script_dep() { } "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.5.0" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() -> u32 { 1 } - "#, - ); + .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) + .file("bar/src/lib.rs", "pub fn bar() -> u32 { 1 }"); let p = p.build(); assert_that(p.cargo("run"), execs().with_status(0).with_stdout("0\n")); @@ -3933,13 +3689,7 @@ fn optional_build_dep_and_required_normal_dep() { bar = { path = "./bar" } "#, ) - .file( - "build.rs", - r#" - extern crate bar; - fn main() { bar::bar(); } - "#, - ) + .file("build.rs", "extern crate bar; fn main() { bar::bar(); }") .file( "src/main.rs", r#" @@ -3956,21 +3706,8 @@ fn optional_build_dep_and_required_normal_dep() { } "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.5.0" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() -> u32 { 1 } - "#, - ); + .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) + .file("bar/src/lib.rs", "pub fn bar() -> u32 { 1 }"); let p = p.build(); assert_that( diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index fdf06b1e6db..2aa9d549086 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -7,12 +7,7 @@ use support::hamcrest::assert_that; #[test] fn rerun_if_env_changes() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file( "build.rs", r#" @@ -68,12 +63,7 @@ fn rerun_if_env_changes() { #[test] fn rerun_if_env_or_file_changes() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file( "build.rs", r#" diff --git a/tests/testsuite/cargo_alias_config.rs b/tests/testsuite/cargo_alias_config.rs index 6f5447a153b..5e136467869 100644 --- a/tests/testsuite/cargo_alias_config.rs +++ b/tests/testsuite/cargo_alias_config.rs @@ -5,12 +5,7 @@ use support::hamcrest::assert_that; fn alias_incorrect_config_type() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -34,12 +29,7 @@ expected a list, but found a integer for [..]", fn alias_default_config_overrides_config() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -61,12 +51,7 @@ fn alias_default_config_overrides_config() { fn alias_config() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -92,12 +77,7 @@ fn alias_config() { fn recursive_alias() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", r"fn main() {}") .file( ".cargo/config", r#" @@ -122,12 +102,7 @@ fn recursive_alias() { fn alias_list_test() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -150,12 +125,7 @@ fn alias_list_test() { fn alias_with_flags_config() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -178,12 +148,7 @@ fn alias_with_flags_config() { fn cant_shadow_builtin() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - fn main() { - }"#, - ) + .file("src/main.rs", "fn main() {}") .file( ".cargo/config", r#" diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index ac306e16c0b..a754eeefe47 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -8,7 +8,7 @@ use cargo; use support::cargo_process; use support::paths::{self, CargoPathExt}; use support::registry::Package; -use support::{basic_bin_manifest, cargo_exe, execs, project, Project}; +use support::{basic_manifest, basic_bin_manifest, cargo_exe, execs, project, Project}; use support::hamcrest::{assert_that, existing_file}; #[cfg_attr(windows, allow(dead_code))] @@ -261,15 +261,7 @@ fn cargo_subcommand_env() { #[test] fn cargo_subcommand_args() { let p = project().at("cargo-foo") - .file( - "Cargo.toml", - r#" - [package] - name = "cargo-foo" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("cargo-foo", "0.0.1")) .file( "src/main.rs", r#" diff --git a/tests/testsuite/cfg.rs b/tests/testsuite/cfg.rs index ef1c321b759..190150f46e4 100644 --- a/tests/testsuite/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -4,7 +4,7 @@ use std::fmt; use cargo::util::{Cfg, CfgExpr}; use support::rustc_host; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; macro_rules! c { @@ -159,15 +159,7 @@ fn cfg_easy() { "#, ) .file("src/lib.rs", "extern crate b;") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -193,15 +185,7 @@ fn dont_include() { ), ) .file("src/lib.rs", "") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); assert_that( @@ -236,10 +220,7 @@ fn works_through_the_registry() { bar = "0.1.0" "#, ) - .file( - "src/lib.rs", - "#[allow(unused_extern_crates)] extern crate bar;", - ) + .file("src/lib.rs", "#[allow(unused_extern_crates)] extern crate bar;") .build(); assert_that( @@ -284,10 +265,7 @@ fn ignore_version_from_other_platform() { this_family, other_family ), ) - .file( - "src/lib.rs", - "#[allow(unused_extern_crates)] extern crate bar;", - ) + .file("src/lib.rs", "#[allow(unused_extern_crates)] extern crate bar;") .build(); assert_that( @@ -402,15 +380,7 @@ fn multiple_match_ok() { ), ) .file("src/lib.rs", "extern crate b;") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -432,15 +402,7 @@ fn any_ok() { "#, ) .file("src/lib.rs", "extern crate b;") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -472,15 +434,7 @@ fn cfg_looks_at_rustflags_for_target() { fn main() { b::foo(); } "#, ) - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "pub fn foo() {}") .build(); diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index a7812133590..153b3210d34 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -2,7 +2,7 @@ use support::install::exe; use support::is_nightly; use support::paths::CargoPathExt; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use glob::glob; use support::hamcrest::{assert_that, existing_file, is_not}; @@ -21,32 +21,11 @@ fn check_success() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - ::bar::baz(); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { ::bar::baz(); }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that(foo.cargo("check"), execs().with_status(0)); @@ -67,32 +46,11 @@ fn check_fail() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - ::bar::baz(42); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { ::bar::baz(42); }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that(foo.cargo("check"), execs().with_status(101)); @@ -178,33 +136,12 @@ fn check_build() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - ::bar::baz(); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { ::bar::baz(); }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that(foo.cargo("check"), execs().with_status(0)); @@ -226,33 +163,12 @@ fn build_check() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - ::bar::baz(); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { ::bar::baz(); }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that(foo.cargo("build"), execs().with_status(0)); @@ -395,32 +311,11 @@ fn rustc_check() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - ::bar::baz(); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { ::bar::baz(); }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -448,32 +343,11 @@ fn rustc_check_err() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - ::bar::qux(); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { ::bar::qux(); }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -506,15 +380,7 @@ fn check_all() { .file("examples/a.rs", "fn main() {}") .file("tests/a.rs", "") .file("src/lib.rs", "") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/main.rs", "fn main() {}") .file("b/src/lib.rs", "") .build(); @@ -540,34 +406,10 @@ fn check_virtual_all_implied() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .build(); assert_that( diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index 8ca4d673838..c07436e0a5b 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -1,6 +1,6 @@ use std::env; -use support::{basic_bin_manifest, execs, git, main_file, project}; +use support::{basic_manifest, basic_bin_manifest, execs, git, main_file, project}; use support::registry::Package; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; @@ -57,31 +57,9 @@ fn clean_multiple_packages() { "#, ) .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) - .file( - "d1/Cargo.toml", - r#" - [package] - name = "d1" - version = "0.0.1" - authors = [] - - [[bin]] - name = "d1" - "#, - ) + .file("d1/Cargo.toml", &basic_bin_manifest("d1")) .file("d1/src/main.rs", "fn main() { println!(\"d1\"); }") - .file( - "d2/Cargo.toml", - r#" - [package] - name = "d2" - version = "0.0.1" - authors = [] - - [[bin]] - name = "d2" - "#, - ) + .file("d2/Cargo.toml", &basic_bin_manifest("d2")) .file("d2/src/main.rs", "fn main() { println!(\"d2\"); }") .build(); @@ -123,15 +101,7 @@ fn clean_release() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -177,15 +147,7 @@ fn clean_doc() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -257,15 +219,7 @@ fn build_script() { fn clean_git() { let git = git::new("dep", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "dep" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); diff --git a/tests/testsuite/concurrent.rs b/tests/testsuite/concurrent.rs index 4a918116280..645eb3c5ad9 100644 --- a/tests/testsuite/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -12,7 +12,7 @@ use support; use support::install::{cargo_home, has_installed_exe}; use support::git; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::{assert_that, existing_file}; fn pkg(name: &str, vers: &str) { @@ -25,25 +25,9 @@ fn pkg(name: &str, vers: &str) { fn multiple_installs() { let p = project() .no_manifest() - .file( - "a/Cargo.toml", - r#" - [package] - name = "foo" - authors = [] - version = "0.0.0" - "#, - ) + .file("a/Cargo.toml", &basic_manifest("foo", "0.0.0")) .file("a/src/main.rs", "fn main() {}") - .file( - "b/Cargo.toml", - r#" - [package] - name = "bar" - authors = [] - version = "0.0.0" - "#, - ) + .file("b/Cargo.toml", &basic_manifest("bar", "0.0.0")) .file("b/src/main.rs", "fn main() {}"); let p = p.build(); @@ -105,25 +89,9 @@ fn concurrent_installs() { fn one_install_should_be_bad() { let p = project() .no_manifest() - .file( - "a/Cargo.toml", - r#" - [package] - name = "foo" - authors = [] - version = "0.0.0" - "#, - ) + .file("a/Cargo.toml", &basic_manifest("foo", "0.0.0")) .file("a/src/main.rs", "fn main() {}") - .file( - "b/Cargo.toml", - r#" - [package] - name = "foo" - authors = [] - version = "0.0.0" - "#, - ) + .file("b/Cargo.toml", &basic_manifest("foo", "0.0.0")) .file("b/src/main.rs", "fn main() {}"); let p = p.build(); @@ -234,15 +202,7 @@ fn multiple_registry_fetches() { fn git_same_repo_different_tags() { let a = git::new("dep", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "dep" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep", "0.5.0")) .file("src/lib.rs", "pub fn tag1() {}") }).unwrap(); @@ -274,10 +234,7 @@ fn git_same_repo_different_tags() { a.url() ), ) - .file( - "a/src/main.rs", - "extern crate dep; fn main() { dep::tag1(); }", - ) + .file("a/src/main.rs", "extern crate dep; fn main() { dep::tag1(); }") .file( "b/Cargo.toml", &format!( @@ -293,10 +250,7 @@ fn git_same_repo_different_tags() { a.url() ), ) - .file( - "b/src/main.rs", - "extern crate dep; fn main() { dep::tag2(); }", - ); + .file("b/src/main.rs", "extern crate dep; fn main() { dep::tag2(); }"); let p = p.build(); let mut a = p.cargo("build") @@ -325,15 +279,7 @@ fn git_same_repo_different_tags() { fn git_same_branch_different_revs() { let a = git::new("dep", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "dep" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep", "0.5.0")) .file("src/lib.rs", "pub fn f1() {}") }).unwrap(); @@ -354,10 +300,7 @@ fn git_same_branch_different_revs() { a.url() ), ) - .file( - "a/src/main.rs", - "extern crate dep; fn main() { dep::f1(); }", - ) + .file("a/src/main.rs", "extern crate dep; fn main() { dep::f1(); }") .file( "b/Cargo.toml", &format!( @@ -373,10 +316,7 @@ fn git_same_branch_different_revs() { a.url() ), ) - .file( - "b/src/main.rs", - "extern crate dep; fn main() { dep::f2(); }", - ); + .file("b/src/main.rs", "extern crate dep; fn main() { dep::f2(); }"); let p = p.build(); // Generate a Cargo.lock pointing at the current rev, then clear out the @@ -545,29 +485,13 @@ fn debug_release_ok() { fn no_deadlock_with_git_dependencies() { let dep1 = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "dep1" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); let dep2 = git::new("dep2", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "dep2" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep2", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); diff --git a/tests/testsuite/corrupt_git.rs b/tests/testsuite/corrupt_git.rs index 465165e7112..105b0ad42a2 100644 --- a/tests/testsuite/corrupt_git.rs +++ b/tests/testsuite/corrupt_git.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use cargo::util::paths as cargopaths; use support::paths; -use support::{execs, git, project}; +use support::{basic_manifest, execs, git, project}; use support::hamcrest::assert_that; #[test] @@ -11,15 +11,7 @@ fn deleting_database_files() { let project = project(); let git_project = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "bar" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); @@ -83,15 +75,7 @@ fn deleting_checkout_files() { let project = project(); let git_project = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "bar" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 896fd209ff9..7e927fd53e8 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -1,6 +1,6 @@ use cargo::util::process; use support::{is_nightly, rustc_host}; -use support::{basic_bin_manifest, cross_compile, execs, project}; +use support::{basic_manifest, basic_bin_manifest, cross_compile, execs, project}; use support::hamcrest::{assert_that, existing_file}; #[test] @@ -139,24 +139,10 @@ fn simple_deps() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { bar::bar(); } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::bar(); }") .build(); let _p2 = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -252,15 +238,7 @@ fn plugin_deps() { ) .build(); let _baz = project().at("baz") - .file( - "Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("src/lib.rs", "pub fn baz() -> i32 { 1 }") .build(); @@ -363,15 +341,7 @@ fn plugin_to_the_max() { ) .build(); let _baz = project().at("baz") - .file( - "Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("src/lib.rs", "pub fn baz() -> i32 { 1 }") .build(); @@ -811,12 +781,7 @@ fn build_script_needed_for_host_and_target() { build = 'build.rs' "#, ) - .file( - "d1/src/lib.rs", - " - pub fn d1() {} - ", - ) + .file("d1/src/lib.rs", "pub fn d1() {}") .file( "d1/build.rs", r#" @@ -912,21 +877,8 @@ fn build_deps_for_the_right_arch() { "#, ) .file("src/main.rs", "extern crate d2; fn main() {}") - .file( - "d1/Cargo.toml", - r#" - [package] - name = "d1" - version = "0.0.0" - authors = [] - "#, - ) - .file( - "d1/src/lib.rs", - " - pub fn d1() {} - ", - ) + .file("d1/Cargo.toml", &basic_manifest("d1", "0.0.0")) + .file("d1/src/lib.rs", "pub fn d1() {}") .file( "d2/Cargo.toml", r#" @@ -983,12 +935,7 @@ fn build_script_only_host() { build = "build.rs" "#, ) - .file( - "d1/src/lib.rs", - " - pub fn d1() {} - ", - ) + .file("d1/src/lib.rs", "pub fn d1() {}") .file( "d1/build.rs", r#" @@ -1097,22 +1044,8 @@ fn build_script_with_platform_specific_dependencies() { host ), ) - .file( - "d1/src/lib.rs", - " - #[allow(unused_extern_crates)] - extern crate d2; - ", - ) - .file( - "d2/Cargo.toml", - r#" - [package] - name = "d2" - version = "0.0.0" - authors = [] - "#, - ) + .file("d1/src/lib.rs", "#[allow(unused_extern_crates)] extern crate d2;") + .file("d2/Cargo.toml", &basic_manifest("d2", "0.0.0")) .file("d2/src/lib.rs", "") .build(); @@ -1179,15 +1112,7 @@ fn platform_specific_dependencies_do_not_leak() { ), ) .file("d1/src/lib.rs", "extern crate d2;") - .file( - "d2/Cargo.toml", - r#" - [package] - name = "d2" - version = "0.0.0" - authors = [] - "#, - ) + .file("d1/Cargo.toml", &basic_manifest("d1", "0.0.0")) .file("d2/src/lib.rs", "") .build(); @@ -1264,12 +1189,7 @@ fn platform_specific_variables_reflected_in_build_scripts() { build = "build.rs" "#, ) - .file( - "d1/build.rs", - r#" - fn main() { println!("cargo:val=1") } - "#, - ) + .file("d1/build.rs", r#"fn main() { println!("cargo:val=1") }"#) .file("d1/src/lib.rs", "") .file( "d2/Cargo.toml", @@ -1282,12 +1202,7 @@ fn platform_specific_variables_reflected_in_build_scripts() { build = "build.rs" "#, ) - .file( - "d2/build.rs", - r#" - fn main() { println!("cargo:val=1") } - "#, - ) + .file("d2/build.rs", r#"fn main() { println!("cargo:val=1") }"#) .file("d2/src/lib.rs", "") .build(); diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs index f422a254152..29605cf9bb8 100644 --- a/tests/testsuite/custom_target.rs +++ b/tests/testsuite/custom_target.rs @@ -1,5 +1,5 @@ use support::is_nightly; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; #[test] @@ -101,16 +101,7 @@ fn custom_target_dependency() { unsafe auto trait Freeze {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - - name = "bar" - version = "0.0.1" - authors = ["author@example.com"] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file( "bar/src/lib.rs", r#" diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index e19d8ef3071..20067c87b2a 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -8,7 +8,7 @@ use support::cargo_process; use support::git; use support::paths; use support::registry::{cksum, Package}; -use support::{execs, project, ProjectBuilder}; +use support::{basic_manifest, execs, project, ProjectBuilder}; use support::hamcrest::assert_that; fn setup() { @@ -78,15 +78,7 @@ fn simple() { setup(); VendorPackage::new("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -103,16 +95,7 @@ fn simple() { bar = "0.1.0" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -148,16 +131,7 @@ fn simple_install() { foo = "0.0.1" "#, ) - .file( - "src/main.rs", - r#" - extern crate foo; - - pub fn main() { - foo::foo(); - } - "#, - ) + .file("src/main.rs", "extern crate foo; pub fn main() { foo::foo(); }") .build(); assert_that( @@ -196,16 +170,7 @@ fn simple_install_fail() { baz = "9.8.7" "#, ) - .file( - "src/main.rs", - r#" - extern crate foo; - - pub fn main() { - foo::foo(); - } - "#, - ) + .file("src/main.rs", "extern crate foo; pub fn main() { foo::foo(); }") .build(); assert_that( @@ -229,15 +194,6 @@ fn install_without_feature_dep() { setup(); VendorPackage::new("foo") - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) .file("src/lib.rs", "pub fn foo() {}") .build(); @@ -251,30 +207,21 @@ fn install_without_feature_dep() { authors = [] [dependencies] - foo = "0.1.0" + foo = "0.0.1" baz = { version = "9.8.7", optional = true } [features] wantbaz = ["baz"] "#, ) - .file( - "src/main.rs", - r#" - extern crate foo; - - pub fn main() { - foo::foo(); - } - "#, - ) + .file("src/main.rs", "extern crate foo; pub fn main() { foo::foo(); }") .build(); assert_that( cargo_process().arg("install").arg("bar"), execs().with_status(0).with_stderr( " Installing bar v0.1.0 - Compiling foo v0.1.0 + Compiling foo v0.0.1 Compiling bar v0.1.0 Finished release [optimized] target(s) in [..]s Installing [..]bar[..] @@ -303,16 +250,7 @@ fn not_there() { bar = "0.1.0" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -332,29 +270,13 @@ fn multiple() { setup(); VendorPackage::new("bar-0.1.0") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .file(".cargo-checksum", "") .build(); VendorPackage::new("bar-0.2.0") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.2.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.2.0")) .file("src/lib.rs", "pub fn bar() {}") .file(".cargo-checksum", "") .build(); @@ -372,16 +294,7 @@ fn multiple() { bar = "0.1.0" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -411,16 +324,7 @@ fn crates_io_then_directory() { bar = "0.1.0" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); let cksum = Package::new("bar", "0.1.0") @@ -443,15 +347,7 @@ fn crates_io_then_directory() { setup(); let mut v = VendorPackage::new("bar"); - v.file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ); + v.file("Cargo.toml", &basic_manifest("bar", "0.1.0")); v.file("src/lib.rs", "pub fn bar() -> u32 { 1 }"); v.cksum.package = Some(cksum); v.build(); @@ -492,15 +388,7 @@ fn crates_io_then_bad_checksum() { setup(); VendorPackage::new("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "") .build(); @@ -528,15 +416,7 @@ fn bad_file_checksum() { setup(); VendorPackage::new("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "") .build(); @@ -580,15 +460,7 @@ fn only_dot_files_ok() { setup(); VendorPackage::new("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "") .build(); VendorPackage::new("foo").no_manifest().file(".bar", "").build(); @@ -617,15 +489,7 @@ fn random_files_ok() { setup(); VendorPackage::new("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "") .build(); VendorPackage::new("foo") @@ -656,27 +520,12 @@ fn random_files_ok() { #[test] fn git_lock_file_doesnt_change() { let git = git::new("git", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "git" - version = "0.5.0" - authors = [] - "#, - ).file("src/lib.rs", "") + p.file("Cargo.toml", &basic_manifest("git", "0.5.0")) + .file("src/lib.rs", "") }).unwrap(); VendorPackage::new("git") - .file( - "Cargo.toml", - r#" - [package] - name = "git" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("git", "0.5.0")) .file("src/lib.rs", "") .disable_checksum() .build(); @@ -740,15 +589,7 @@ fn git_lock_file_doesnt_change() { #[test] fn git_override_requires_lockfile() { VendorPackage::new("git") - .file( - "Cargo.toml", - r#" - [package] - name = "git" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("git", "0.5.0")) .file("src/lib.rs", "") .disable_checksum() .build(); diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index b346998a080..7feecccedfe 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -4,7 +4,7 @@ use std::fs::{self, File}; use std::io::Read; use support::{is_nightly, rustc_host, ChannelChanger}; -use support::{basic_lib_manifest, execs, git, project, path2url}; +use support::{basic_manifest, basic_lib_manifest, execs, git, project, path2url}; use support::paths::CargoPathExt; use support::registry::Package; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; @@ -25,12 +25,7 @@ fn simple() { "#, ) .file("build.rs", "fn main() {}") - .file( - "src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); assert_that( @@ -64,12 +59,7 @@ fn doc_no_libs() { doc = false "#, ) - .file( - "src/main.rs", - r#" - bad code - "#, - ) + .file("src/main.rs", "bad code") .build(); assert_that(p.cargo("doc"), execs().with_status(0)); @@ -78,12 +68,7 @@ fn doc_no_libs() { #[test] fn doc_twice() { let p = project() - .file( - "src/lib.rs", - r#" - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); assert_that( @@ -115,28 +100,9 @@ fn doc_deps() { path = "bar" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -196,28 +162,9 @@ fn doc_no_deps() { path = "bar" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -255,28 +202,9 @@ fn doc_only_bin() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - pub fn foo() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/main.rs", "extern crate bar; pub fn foo() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that(p.cargo("doc").arg("-v"), execs().with_status(0)); @@ -296,8 +224,7 @@ fn doc_multiple_targets_same_name_lib() { members = ["foo", "bar"] "#, ) - .file( - "foo/Cargo.toml", + .file("foo/Cargo.toml", r#" [package] name = "foo" @@ -669,15 +596,7 @@ fn doc_dash_p() { "#, ) .file("a/src/lib.rs", "extern crate b;") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); @@ -755,15 +674,7 @@ fn target_specific_not_documented() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "not rust") .build(); @@ -786,15 +697,7 @@ fn output_not_captured() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file( "a/src/lib.rs", " @@ -854,15 +757,7 @@ fn target_specific_documented() { pub fn foo() {} ", ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file( "a/src/lib.rs", " @@ -890,21 +785,8 @@ fn no_document_build_deps() { a = { path = "a" } "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file( "a/src/lib.rs", " @@ -956,43 +838,11 @@ fn doc_multiple_deps() { path = "baz" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) + .file("baz/src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -1028,13 +878,7 @@ fn features() { foo = ["bar/bar"] "#, ) - .file( - "src/lib.rs", - r#" - #[cfg(feature = "foo")] - pub fn foo() {} - "#, - ) + .file("src/lib.rs", r#"#[cfg(feature = "foo")] pub fn foo() {}"#) .file( "bar/Cargo.toml", r#" @@ -1055,13 +899,7 @@ fn features() { } "#, ) - .file( - "bar/src/lib.rs", - r#" - #[cfg(feature = "bar")] - pub fn bar() {} - "#, - ) + .file("bar/src/lib.rs", r#"#[cfg(feature = "bar")] pub fn bar() {}"#) .build(); assert_that( p.cargo("doc").arg("--features").arg("foo"), @@ -1168,26 +1006,9 @@ fn doc_all_workspace() { [workspace] "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); // The order in which bar is compiled or documented is not deterministic @@ -1211,34 +1032,10 @@ fn doc_all_virtual_manifest() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .build(); // The order in which bar and baz are documented is not guaranteed @@ -1261,34 +1058,10 @@ fn doc_virtual_manifest_all_implied() { members = ["bar", "baz"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() {}") .build(); // The order in which bar and baz are documented is not guaranteed @@ -1326,12 +1099,7 @@ fn doc_all_member_dependency_same_name() { bar = "0.1.0" "#, ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); Package::new("bar", "0.1.0").publish(); @@ -1355,23 +1123,9 @@ fn doc_workspace_open_help_message() { members = ["foo", "bar"] "#, ) - .file( - "foo/Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .build(); diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 39b160d0ee0..97eaa039cb9 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::io::prelude::*; use support::paths::CargoPathExt; -use support::{BASIC_MANIFEST, execs, project}; +use support::{basic_manifest, execs, project}; use support::ChannelChanger; use support::hamcrest::assert_that; use support::registry::Package; @@ -124,15 +124,7 @@ fn invalid4() { "#, ) .file("src/main.rs", "") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -151,7 +143,7 @@ failed to select a version for `bar` which could resolve this conflict", ), ); - p.change_file("Cargo.toml", BASIC_MANIFEST); + p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1")); assert_that( p.cargo("build").arg("--features").arg("test"), @@ -273,15 +265,7 @@ fn invalid8() { "#, ) .file("src/main.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -309,15 +293,7 @@ fn invalid9() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -361,15 +337,7 @@ fn invalid10() { "#, ) .file("bar/src/lib.rs", "") - .file( - "bar/baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("bar/baz/src/lib.rs", "") .build(); @@ -421,13 +389,7 @@ fn no_transitive_dep_feature_requirement() { path = "../bar" "#, ) - .file( - "derived/src/lib.rs", - r#" - extern crate bar; - pub use bar::test; - "#, - ) + .file("derived/src/lib.rs", "extern crate bar; pub use bar::test;") .file( "bar/Cargo.toml", r#" @@ -483,15 +445,7 @@ fn no_feature_doesnt_build() { fn main() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") .build(); @@ -557,15 +511,7 @@ fn default_feature_pulled_in() { fn main() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") .build(); @@ -689,25 +635,9 @@ fn groups_on_groups_on_groups() { fn main() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("baz/src/lib.rs", "pub fn baz() {}") .build(); @@ -755,25 +685,9 @@ fn many_cli_features() { fn main() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("baz/src/lib.rs", "pub fn baz() {}") .build(); @@ -967,13 +881,7 @@ fn transitive_features() { path = "bar" "#, ) - .file( - "src/main.rs", - " - extern crate bar; - fn main() { bar::baz(); } - ", - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::baz(); }") .file( "bar/Cargo.toml", r#" @@ -986,13 +894,7 @@ fn transitive_features() { baz = [] "#, ) - .file( - "bar/src/lib.rs", - r#" - #[cfg(feature = "baz")] - pub fn baz() {} - "#, - ) + .file("bar/src/lib.rs", r#"#[cfg(feature = "baz")] pub fn baz() {}"#) .build(); assert_that( @@ -1040,15 +942,7 @@ fn everything_in_the_lockfile() { "#, ) .file("d1/src/lib.rs", "") - .file( - "d2/Cargo.toml", - r#" - [package] - name = "d2" - version = "0.0.2" - authors = [] - "#, - ) + .file("d2/Cargo.toml", &basic_manifest("d2", "0.0.2")) .file("d2/src/lib.rs", "") .file( "d3/Cargo.toml", @@ -1153,13 +1047,7 @@ fn unions_work_with_no_default_features() { b = { path = "b" } "#, ) - .file( - "src/lib.rs", - r#" - extern crate a; - pub fn foo() { a::a(); } - "#, - ) + .file("src/lib.rs", "extern crate a; pub fn foo() { a::a(); }") .file( "b/Cargo.toml", r#" @@ -1186,13 +1074,7 @@ fn unions_work_with_no_default_features() { f1 = [] "#, ) - .file( - "a/src/lib.rs", - r#" - #[cfg(feature = "f1")] - pub fn a() {} - "#, - ) + .file("a/src/lib.rs", r#"#[cfg(feature = "f1")] pub fn a() {}"#) .build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -1218,15 +1100,7 @@ fn optional_and_dev_dep() { "#, ) .file("src/lib.rs", "") - .file( - "foo/Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "") .build(); @@ -1259,15 +1133,7 @@ fn activating_feature_activates_dep() { a = ["foo/a"] "#, ) - .file( - "src/lib.rs", - " - extern crate foo; - pub fn bar() { - foo::bar(); - } - ", - ) + .file("src/lib.rs", "extern crate foo; pub fn bar() { foo::bar(); }") .file( "foo/Cargo.toml", r#" @@ -1280,13 +1146,7 @@ fn activating_feature_activates_dep() { a = [] "#, ) - .file( - "foo/src/lib.rs", - r#" - #[cfg(feature = "a")] - pub fn bar() {} - "#, - ) + .file("foo/src/lib.rs", r#"#[cfg(feature = "a")] pub fn bar() {}"#) .build(); assert_that( @@ -1333,13 +1193,7 @@ fn dep_feature_in_cmd_line() { derived-feat = ["bar/some-feat"] "#, ) - .file( - "derived/src/lib.rs", - r#" - extern crate bar; - pub use bar::test; - "#, - ) + .file("derived/src/lib.rs", "extern crate bar; pub use bar::test;") .file( "bar/Cargo.toml", r#" @@ -1431,15 +1285,7 @@ fn all_features_flag_enables_all_features() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("baz/src/lib.rs", "pub fn baz() {}") .build(); @@ -1479,25 +1325,9 @@ fn many_cli_features_comma_delimited() { fn main() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("baz/src/lib.rs", "pub fn baz() {}") .build(); @@ -1557,45 +1387,13 @@ fn many_cli_features_comma_and_space_delimited() { fn main() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("baz/src/lib.rs", "pub fn baz() {}") - .file( - "bam/Cargo.toml", - r#" - [package] - name = "bam" - version = "0.0.1" - authors = [] - "#, - ) + .file("bam/Cargo.toml", &basic_manifest("bam", "0.0.1")) .file("bam/src/lib.rs", "pub fn bam() {}") - .file( - "bap/Cargo.toml", - r#" - [package] - name = "bap" - version = "0.0.1" - authors = [] - "#, - ) + .file("bap/Cargo.toml", &basic_manifest("bap", "0.0.1")) .file("bap/src/lib.rs", "pub fn bap() {}") .build(); diff --git a/tests/testsuite/fetch.rs b/tests/testsuite/fetch.rs index 646bf1c6132..3e64c9f0698 100644 --- a/tests/testsuite/fetch.rs +++ b/tests/testsuite/fetch.rs @@ -1,17 +1,12 @@ use support::rustc_host; use support::registry::Package; -use support::{cross_compile, execs, project}; +use support::{basic_manifest, cross_compile, execs, project}; use support::hamcrest::assert_that; #[test] fn no_deps() { let p = project() - .file( - "src/main.rs", - r#" - mod a; fn main() {} - "#, - ) + .file("src/main.rs", "mod a; fn main() {}") .file("src/a.rs", "") .build(); @@ -21,26 +16,12 @@ fn no_deps() { #[test] fn fetch_all_platform_dependencies_when_no_target_is_given() { Package::new("d1", "1.2.3") - .file( - "Cargo.toml", - r#" - [project] - name = "d1" - version = "1.2.3" - "#, - ) + .file("Cargo.toml", &basic_manifest("d1", "1.2.3")) .file("src/lib.rs", "") .publish(); Package::new("d2", "0.1.2") - .file( - "Cargo.toml", - r#" - [project] - name = "d2" - version = "0.1.2" - "#, - ) + .file("Cargo.toml", &basic_manifest("d2", "0.1.2")) .file("src/lib.rs", "") .publish(); @@ -81,26 +62,12 @@ fn fetch_all_platform_dependencies_when_no_target_is_given() { #[test] fn fetch_platform_specific_dependencies() { Package::new("d1", "1.2.3") - .file( - "Cargo.toml", - r#" - [project] - name = "d1" - version = "1.2.3" - "#, - ) + .file("Cargo.toml", &basic_manifest("d1", "1.2.3")) .file("src/lib.rs", "") .publish(); Package::new("d2", "0.1.2") - .file( - "Cargo.toml", - r#" - [project] - name = "d2" - version = "0.1.2" - "#, - ) + .file("Cargo.toml", &basic_manifest("d2", "0.1.2")) .file("src/lib.rs", "") .publish(); diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index ffb3fce9c5c..f797774342e 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -3,7 +3,7 @@ use std::fs::File; use git2; use support::git; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::{is_nightly, ChannelChanger}; use support::hamcrest::assert_that; @@ -183,14 +183,7 @@ fn fix_path_deps() { } "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file( "bar/src/lib.rs", r#" @@ -236,14 +229,7 @@ fn do_not_fix_non_relevant_deps() { "#, ) .file("foo/src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file( "bar/src/lib.rs", r#" @@ -414,14 +400,7 @@ fn upgrade_extern_crate() { } "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "pub fn bar() {}") .build(); @@ -678,10 +657,7 @@ fn fix_two_files() { #[test] fn fixes_missing_ampersand() { let p = project() - .file( - "src/main.rs", - "fn main() { let mut x = 3; drop(x); }", - ) + .file("src/main.rs", "fn main() { let mut x = 3; drop(x); }") .file( "src/lib.rs", r#" @@ -698,18 +674,8 @@ fn fixes_missing_ampersand() { pub fn foo() { let mut x = 3; drop(x); } "#, ) - .file( - "examples/foo.rs", - r#" - fn main() { let mut x = 3; drop(x); } - "#, - ) - .file( - "build.rs", - r#" - fn main() { let mut x = 3; drop(x); } - "#, - ) + .file("examples/foo.rs", "fn main() { let mut x = 3; drop(x); }") + .file("build.rs", "fn main() { let mut x = 3; drop(x); }") .build(); assert_that( @@ -769,15 +735,7 @@ fn fix_features() { #[test] fn shows_warnings() { let p = project() - .file( - "src/lib.rs", - r#" - use std::default::Default; - - pub fn foo() { - } - "#, - ) + .file("src/lib.rs", "use std::default::Default; pub fn foo() {}") .build(); assert_that( @@ -790,13 +748,7 @@ fn shows_warnings() { fn warns_if_no_vcs_detected() { let p = project() .use_temp_dir() - .file( - "src/lib.rs", - r#" - pub fn foo() { - } - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); assert_that( @@ -817,13 +769,7 @@ destructive changes; if you'd like to suppress this error pass `--allow-no-vcs`\ #[test] fn warns_about_dirty_working_directory() { let p = project() - .file( - "src/lib.rs", - r#" - pub fn foo() { - } - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); let repo = git2::Repository::init(&p.root()).unwrap(); @@ -859,13 +805,7 @@ these files: #[test] fn does_not_warn_about_clean_working_directory() { let p = project() - .file( - "src/lib.rs", - r#" - pub fn foo() { - } - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .build(); let repo = git2::Repository::init(&p.root()).unwrap(); @@ -885,13 +825,7 @@ fn does_not_warn_about_clean_working_directory() { #[test] fn does_not_warn_about_dirty_ignored_files() { let p = project() - .file( - "src/lib.rs", - r#" - pub fn foo() { - } - "#, - ) + .file("src/lib.rs", "pub fn foo() {}") .file(".gitignore", "foo\n") .build(); diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 90ee17c28c7..59da71ea319 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -4,18 +4,13 @@ use std::io::prelude::*; use support::sleep_ms; use support::paths::CargoPathExt; use support::registry::Package; -use support::{execs, path2url, project}; +use support::{basic_manifest, execs, path2url, project}; use support::hamcrest::{assert_that, existing_file}; #[test] fn modifying_and_moving() { let p = project() - .file( - "src/main.rs", - r#" - mod a; fn main() {} - "#, - ) + .file("src/main.rs", "mod a; fn main() {}") .file("src/a.rs", "") .build(); @@ -58,13 +53,7 @@ fn modify_only_some_files() { let p = project() .file("src/lib.rs", "mod a;") .file("src/a.rs", "") - .file( - "src/main.rs", - r#" - mod b; - fn main() {} - "#, - ) + .file("src/main.rs", "mod b; fn main() {}") .file("src/b.rs", "") .file("tests/test.rs", "") .build(); @@ -141,15 +130,7 @@ fn rebuild_sub_package_then_while_package() { "#, ) .file("a/src/lib.rs", "extern crate b;") - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - authors = [] - version = "0.0.1" - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); @@ -157,24 +138,14 @@ fn rebuild_sub_package_then_while_package() { File::create(&p.root().join("b/src/lib.rs")) .unwrap() - .write_all( - br#" - pub fn b() {} - "#, - ) + .write_all(br#"pub fn b() {}"#) .unwrap(); assert_that(p.cargo("build").arg("-pb"), execs().with_status(0)); File::create(&p.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - extern crate a; - extern crate b; - pub fn toplevel() {} - "#, - ) + .write_all(br#"extern crate a; extern crate b; pub fn toplevel() {}"#) .unwrap(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -635,15 +606,7 @@ fn no_rebuild_transitive_target_deps() { "#, ) .file("b/src/lib.rs", "") - .file( - "c/Cargo.toml", - r#" - [package] - name = "c" - version = "0.0.1" - authors = [] - "#, - ) + .file("c/Cargo.toml", &basic_manifest("c", "0.0.1")) .file("c/src/lib.rs", "") .build(); @@ -754,15 +717,7 @@ fn same_build_dir_cached_packages() { "#, ) .file("c/src/lib.rs", "") - .file( - "d/Cargo.toml", - r#" - [package] - name = "d" - version = "0.0.1" - authors = [] - "#, - ) + .file("d/Cargo.toml", &basic_manifest("d", "0.0.1")) .file("d/src/lib.rs", "") .file( ".cargo/config", @@ -814,15 +769,7 @@ fn no_rebuild_if_build_artifacts_move_backwards_in_time() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -855,15 +802,7 @@ fn rebuild_if_build_artifacts_move_forward_in_time() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -966,15 +905,7 @@ fn no_rebuild_when_rename_dir() { "#, ) .file("src/lib.rs", "") - .file( - "foo/Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.0.1")) .file("foo/src/lib.rs", "") .build(); @@ -1119,15 +1050,7 @@ fn change_panic_mode() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1")) .file("bar/src/lib.rs", "") .file( "baz/Cargo.toml", @@ -1196,14 +1119,7 @@ fn dont_rebuild_based_on_plugins() { "#, ) .file("baz/src/main.rs", "fn main() {}") - .file( - "qux/Cargo.toml", - r#" - [package] - name = "qux" - version = "0.1.1" - "#, - ) + .file("qux/Cargo.toml", &basic_manifest("qux", "0.1.1")) .file("qux/src/lib.rs", "") .build(); @@ -1236,14 +1152,7 @@ fn reuse_workspace_lib() { "#, ) .file("src/lib.rs", "") - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.1.1" - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.1")) .file("baz/src/lib.rs", "") .build(); diff --git a/tests/testsuite/generate_lockfile.rs b/tests/testsuite/generate_lockfile.rs index 0101f2a7996..cac4fc1cadb 100644 --- a/tests/testsuite/generate_lockfile.rs +++ b/tests/testsuite/generate_lockfile.rs @@ -2,7 +2,7 @@ use std::fs::{self, File}; use std::io::prelude::*; use support::registry::Package; -use support::{execs, paths, project, ProjectBuilder}; +use support::{basic_manifest, execs, paths, project, ProjectBuilder}; use support::ChannelChanger; use support::hamcrest::{assert_that, existing_file, is_not}; @@ -10,15 +10,7 @@ use support::hamcrest::{assert_that, existing_file, is_not}; fn adding_and_removing_packages() { let p = project() .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - authors = [] - version = "0.0.1" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -49,14 +41,7 @@ fn adding_and_removing_packages() { // change the dep File::create(&p.root().join("bar/Cargo.toml")) .unwrap() - .write_all( - br#" - [package] - name = "bar" - authors = [] - version = "0.0.2" - "#, - ) + .write_all(basic_manifest("bar", "0.0.2").as_bytes()) .unwrap(); assert_that(p.cargo("generate-lockfile"), execs().with_status(0)); let lock3 = p.read_lockfile(); @@ -118,15 +103,7 @@ fn no_index_update() { fn preserve_metadata() { let p = project() .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - authors = [] - version = "0.0.1" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -160,15 +137,7 @@ foo = "bar" fn preserve_line_endings_issue_2076() { let p = project() .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - authors = [] - version = "0.0.1" - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); @@ -233,12 +202,7 @@ fn duplicate_entries_in_lockfile() { .file("src/lib.rs", "") .build(); - let common_toml = r#" - [package] - name = "common" - authors = [] - version = "0.0.1" - "#; + let common_toml = &basic_manifest("common", "0.0.1"); let _common_in_a = ProjectBuilder::new(paths::root().join("a/common")) .file("Cargo.toml", common_toml) diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 80e47c9079e..46820523dff 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -10,7 +10,7 @@ use std::thread; use cargo::util::process; use support::sleep_ms; use support::paths::{self, CargoPathExt}; -use support::{basic_lib_manifest, execs, git, main_file, project, path2url}; +use support::{basic_manifest, basic_lib_manifest, execs, git, main_file, project, path2url}; use support::ChannelChanger; use support::hamcrest::{assert_that, existing_file}; @@ -19,20 +19,7 @@ fn cargo_compile_simple_git_dep() { let project = project(); let git_project = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [project] - - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep1" - "#, - ) + .file("Cargo.toml", &basic_lib_manifest("dep1")) .file( "src/dep1.rs", r#" @@ -61,10 +48,7 @@ fn cargo_compile_simple_git_dep() { git_project.url() ), ) - .file( - "src/main.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); let root = project.root(); @@ -126,17 +110,7 @@ Caused by: fn cargo_compile_offline_with_cached_git_dep() { let git_project = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [project] - name = "dep1" - version = "0.5.0" - authors = ["chabapok@example.com"] - - [lib] - name = "dep1""#, - ) + .file("Cargo.toml", &basic_lib_manifest("dep1")) .file( "src/lib.rs", r#" @@ -151,11 +125,7 @@ fn cargo_compile_offline_with_cached_git_dep() { // Commit the changes and make sure we trigger a recompile File::create(&git_project.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - pub static COOL_STR:&str = "cached git repo rev2"; - "#, - ) + .write_all(br#"pub static COOL_STR:&str = "cached git repo rev2";"#) .unwrap(); git::add(&repo); let rev2 = git::commit(&repo); @@ -283,20 +253,7 @@ fn cargo_compile_git_dep_branch() { let project = project(); let git_project = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [project] - - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep1" - "#, - ) + .file("Cargo.toml", &basic_lib_manifest("dep1")) .file( "src/dep1.rs", r#" @@ -333,10 +290,7 @@ fn cargo_compile_git_dep_branch() { git_project.url() ), ) - .file( - "src/main.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); let root = project.root(); @@ -368,20 +322,7 @@ fn cargo_compile_git_dep_tag() { let project = project(); let git_project = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [project] - - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep1" - "#, - ) + .file("Cargo.toml", &basic_lib_manifest("dep1")) .file( "src/dep1.rs", r#" @@ -422,10 +363,7 @@ fn cargo_compile_git_dep_tag() { git_project.url() ), ) - .file( - "src/main.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); let root = project.root(); @@ -487,20 +425,7 @@ fn cargo_compile_with_nested_paths() { } "#, ) - .file( - "vendor/dep2/Cargo.toml", - r#" - [project] - - name = "dep2" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep2" - "#, - ) + .file("vendor/dep2/Cargo.toml", &basic_lib_manifest("dep2")) .file( "vendor/dep2/src/dep2.rs", r#" @@ -534,10 +459,7 @@ fn cargo_compile_with_nested_paths() { git_project.url() ), ) - .file( - "src/foo.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/foo.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); p.cargo("build").exec_with_output().unwrap(); @@ -554,20 +476,7 @@ fn cargo_compile_with_nested_paths() { fn cargo_compile_with_malformed_nested_paths() { let git_project = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [project] - - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep1" - "#, - ) + .file("Cargo.toml", &basic_lib_manifest("dep1")) .file( "src/dep1.rs", r#" @@ -576,12 +485,7 @@ fn cargo_compile_with_malformed_nested_paths() { } "#, ) - .file( - "vendor/dep2/Cargo.toml", - r#" - !INVALID! - "#, - ) + .file("vendor/dep2/Cargo.toml", "!INVALID!") }).unwrap(); let p = project() @@ -607,10 +511,7 @@ fn cargo_compile_with_malformed_nested_paths() { git_project.url() ), ) - .file( - "src/foo.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/foo.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); p.cargo("build").exec_with_output().unwrap(); @@ -627,20 +528,7 @@ fn cargo_compile_with_malformed_nested_paths() { fn cargo_compile_with_meta_package() { let git_project = git::new("meta-dep", |project| { project - .file( - "dep1/Cargo.toml", - r#" - [project] - - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep1" - "#, - ) + .file("dep1/Cargo.toml", &basic_lib_manifest("dep1")) .file( "dep1/src/dep1.rs", r#" @@ -649,20 +537,7 @@ fn cargo_compile_with_meta_package() { } "#, ) - .file( - "dep2/Cargo.toml", - r#" - [project] - - name = "dep2" - version = "0.5.0" - authors = ["carlhuda@example.com"] - - [lib] - - name = "dep2" - "#, - ) + .file("dep2/Cargo.toml", &basic_lib_manifest("dep2")) .file( "dep2/src/dep2.rs", r#" @@ -747,10 +622,7 @@ fn cargo_compile_with_short_ssh_git() { url ), ) - .file( - "src/foo.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/foo.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); assert_that( @@ -771,15 +643,7 @@ Caused by: fn two_revs_same_deps() { let bar = git::new("meta-dep", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.0")) .file("src/lib.rs", "pub fn bar() -> i32 { 1 }") }).unwrap(); @@ -789,11 +653,7 @@ fn two_revs_same_deps() { // Commit the changes and make sure we trigger a recompile File::create(&bar.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - pub fn bar() -> i32 { 2 } - "#, - ) + .write_all(br#"pub fn bar() -> i32 { 2 }"#) .unwrap(); git::add(&repo); let rev2 = git::commit(&repo); @@ -870,12 +730,7 @@ fn recompilation() { let git_project = git::new("bar", |project| { project .file("Cargo.toml", &basic_lib_manifest("bar")) - .file( - "src/bar.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/bar.rs", "pub fn bar() {}") }).unwrap(); let p = project() @@ -921,11 +776,7 @@ fn recompilation() { // Modify a file manually, shouldn't trigger a recompile File::create(&git_project.root().join("src/bar.rs")) .unwrap() - .write_all( - br#" - pub fn bar() { println!("hello!"); } - "#, - ) + .write_all(br#"pub fn bar() { println!("hello!"); }"#) .unwrap(); assert_that(p.cargo("build"), execs().with_stdout("")); @@ -994,12 +845,7 @@ fn update_with_shared_deps() { let git_project = git::new("bar", |project| { project .file("Cargo.toml", &basic_lib_manifest("bar")) - .file( - "src/bar.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/bar.rs", "pub fn bar() {}") }).unwrap(); let p = project() @@ -1082,11 +928,7 @@ fn update_with_shared_deps() { // Modify a file manually, and commit it File::create(&git_project.root().join("src/bar.rs")) .unwrap() - .write_all( - br#" - pub fn bar() { println!("hello!"); } - "#, - ) + .write_all(br#"pub fn bar() { println!("hello!"); }"#) .unwrap(); let repo = git2::Repository::open(&git_project.root()).unwrap(); let old_head = repo.head().unwrap().target().unwrap(); @@ -1175,15 +1017,7 @@ Caused by: fn dep_with_submodule() { let project = project(); let git_project = git::new("dep1", |project| { - project.file( - "Cargo.toml", - r#" - [package] - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - "#, - ) + project.file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) }).unwrap(); let git_project2 = git::new("dep2", |project| project.file("lib.rs", "pub fn dep() {}")).unwrap(); @@ -1211,13 +1045,7 @@ fn dep_with_submodule() { git_project.url() ), ) - .file( - "src/lib.rs", - " - extern crate dep1; - pub fn foo() { dep1::dep() } - ", - ) + .file("src/lib.rs", "extern crate dep1; pub fn foo() { dep1::dep() }") .build(); assert_that( @@ -1238,15 +1066,7 @@ fn dep_with_submodule() { fn dep_with_bad_submodule() { let project = project(); let git_project = git::new("dep1", |project| { - project.file( - "Cargo.toml", - r#" - [package] - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - "#, - ) + project.file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) }).unwrap(); let git_project2 = git::new("dep2", |project| project.file("lib.rs", "pub fn dep() {}")).unwrap(); @@ -1290,13 +1110,7 @@ fn dep_with_bad_submodule() { git_project.url() ), ) - .file( - "src/lib.rs", - " - extern crate dep1; - pub fn foo() { dep1::dep() } - ", - ) + .file("src/lib.rs", "extern crate dep1; pub fn foo() { dep1::dep() }") .build(); let expected = format!( @@ -1327,28 +1141,12 @@ fn two_deps_only_update_one() { let project = project(); let git1 = git::new("dep1", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); let git2 = git::new("dep2", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "dep2" - version = "0.5.0" - authors = ["carlhuda@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("dep2", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); @@ -1390,11 +1188,7 @@ fn two_deps_only_update_one() { File::create(&git1.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - pub fn foo() {} - "#, - ) + .write_all(br#"pub fn foo() {}"#) .unwrap(); let repo = git2::Repository::open(&git1.root()).unwrap(); git::add(&repo); @@ -1415,15 +1209,7 @@ fn two_deps_only_update_one() { fn stale_cached_version() { let bar = git::new("meta-dep", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.0")) .file("src/lib.rs", "pub fn bar() -> i32 { 1 }") }).unwrap(); @@ -1462,11 +1248,7 @@ fn stale_cached_version() { // us pulling it down. File::create(&bar.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - pub fn bar() -> i32 { 1 + 0 } - "#, - ) + .write_all(br#"pub fn bar() -> i32 { 1 + 0 }"#) .unwrap(); let repo = git2::Repository::open(&bar.root()).unwrap(); git::add(&repo); @@ -1520,15 +1302,7 @@ fn stale_cached_version() { fn dep_with_changed_submodule() { let project = project(); let git_project = git::new("dep1", |project| { - project.file( - "Cargo.toml", - r#" - [package] - name = "dep1" - version = "0.5.0" - authors = ["carlhuda@example.com"] - "#, - ) + project.file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) }).unwrap(); let git_project2 = git::new("dep2", |project| { @@ -1646,15 +1420,7 @@ fn dep_with_changed_submodule() { fn dev_deps_with_testing() { let p2 = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file( "src/lib.rs", r#" @@ -1742,12 +1508,7 @@ fn git_build_cmd_freshness() { ) .file("build.rs", "fn main() {}") .file("src/lib.rs", "pub fn bar() -> i32 { 1 }") - .file( - ".gitignore", - " - src/bar.rs - ", - ) + .file(".gitignore", "src/bar.rs") }).unwrap(); foo.root().move_into_the_past(); @@ -1778,15 +1539,7 @@ fn git_build_cmd_freshness() { fn git_name_not_always_needed() { let p2 = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file( "src/lib.rs", r#" @@ -1839,15 +1592,7 @@ fn git_name_not_always_needed() { fn git_repo_changing_no_rebuild() { let bar = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "pub fn bar() -> i32 { 1 }") }).unwrap(); @@ -1888,11 +1633,7 @@ fn git_repo_changing_no_rebuild() { // Make a commit to lock p2 to a different rev File::create(&bar.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - pub fn bar() -> i32 { 2 } - "#, - ) + .write_all(br#"pub fn bar() -> i32 { 2 }"#) .unwrap(); let repo = git2::Repository::open(&bar.root()).unwrap(); git::add(&repo); @@ -2011,15 +1752,7 @@ fn git_dep_build_cmd() { fn fetch_downloads() { let bar = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "pub fn bar() -> i32 { 1 }") }).unwrap(); @@ -2055,15 +1788,7 @@ fn fetch_downloads() { fn warnings_in_git_dep() { let bar = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "fn unused() {}") }).unwrap(); @@ -2103,28 +1828,12 @@ fn warnings_in_git_dep() { fn update_ambiguous() { let bar1 = git::new("bar1", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); let bar2 = git::new("bar2", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.6.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.6.0")) .file("src/lib.rs", "") }).unwrap(); let baz = git::new("baz", |project| { @@ -2188,25 +1897,9 @@ following: fn update_one_dep_in_repo_with_many_deps() { let bar = git::new("bar", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.5.0")) .file("a/src/lib.rs", "") }).unwrap(); @@ -2244,15 +1937,7 @@ fn update_one_dep_in_repo_with_many_deps() { fn switch_deps_does_not_update_transitive() { let transitive = git::new("transitive", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "transitive" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("transitive", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); let dep1 = git::new("dep1", |project| { @@ -2378,15 +2063,7 @@ fn update_one_source_updates_all_packages_in_that_git_source() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.5.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.5.0")) .file("a/src/lib.rs", "") }).unwrap(); @@ -2416,11 +2093,7 @@ fn update_one_source_updates_all_packages_in_that_git_source() { // Just be sure to change a file File::create(&dep.root().join("src/lib.rs")) .unwrap() - .write_all( - br#" - pub fn bar() -> i32 { 2 } - "#, - ) + .write_all(br#"pub fn bar() -> i32 { 2 }"#) .unwrap(); git::add(&repo); git::commit(&repo); @@ -2446,28 +2119,12 @@ fn update_one_source_updates_all_packages_in_that_git_source() { fn switch_sources() { let a1 = git::new("a1", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "a" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("a", "0.5.0")) .file("src/lib.rs", "") }).unwrap(); let a2 = git::new("a2", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "a" - version = "0.5.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("a", "0.5.1")) .file("src/lib.rs", "") }).unwrap(); @@ -2583,15 +2240,8 @@ fn dont_require_submodules_are_checked_out() { #[test] fn doctest_same_name() { let a2 = git::new("a2", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "a" - version = "0.5.0" - authors = [] - "#, - ).file("src/lib.rs", "pub fn a2() {}") + p.file("Cargo.toml", &basic_manifest("a", "0.5.0")) + .file("src/lib.rs", "pub fn a2() {}") }).unwrap(); let a1 = git::new("a1", |p| { @@ -2642,15 +2292,8 @@ fn doctest_same_name() { #[test] fn lints_are_suppressed() { let a = git::new("a", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "a" - version = "0.5.0" - authors = [] - "#, - ).file( + p.file("Cargo.toml", &basic_manifest("a", "0.5.0")) + .file( "src/lib.rs", " use std::option; @@ -2693,15 +2336,8 @@ fn lints_are_suppressed() { #[test] fn denied_lints_are_allowed() { let a = git::new("a", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "a" - version = "0.5.0" - authors = [] - "#, - ).file( + p.file("Cargo.toml", &basic_manifest("a", "0.5.0")) + .file( "src/lib.rs", " #![deny(warnings)] @@ -2745,15 +2381,8 @@ fn denied_lints_are_allowed() { #[test] fn add_a_git_dep() { let git = git::new("git", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "git" - version = "0.5.0" - authors = [] - "#, - ).file("src/lib.rs", "") + p.file("Cargo.toml", &basic_manifest("git", "0.5.0")) + .file("src/lib.rs", "") }).unwrap(); let p = project() @@ -2774,15 +2403,7 @@ fn add_a_git_dep() { ), ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -2812,25 +2433,10 @@ fn add_a_git_dep() { #[test] fn two_at_rev_instead_of_tag() { let git = git::new("git", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "git1" - version = "0.5.0" - authors = [] - "#, - ).file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [project] - name = "git2" - version = "0.5.0" - authors = [] - "#, - ) - .file("a/src/lib.rs", "") + p.file("Cargo.toml", &basic_manifest("git1", "0.5.0")) + .file("src/lib.rs", "") + .file("a/Cargo.toml", &basic_manifest("git2", "0.5.0")) + .file("a/src/lib.rs", "") }).unwrap(); // Make a tag corresponding to the current HEAD @@ -2920,13 +2526,7 @@ fn include_overrides_gitignore() { } "#, ) - .file( - "src/lib.rs", - r#" - mod not_incl; - mod incl; - "#, - ) + .file("src/lib.rs", "mod not_incl; mod incl;") .file( "src/mod.md", r#" @@ -3057,10 +2657,7 @@ fn invalid_git_dependency_manifest() { git_project.url() ), ) - .file( - "src/main.rs", - &main_file(r#""{}", dep1::hello()"#, &["dep1"]), - ) + .file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"])) .build(); let git_root = git_project.root(); @@ -3092,15 +2689,7 @@ fn invalid_git_dependency_manifest() { fn failed_submodule_checkout() { let project = project(); let git_project = git::new("dep1", |project| { - project.file( - "Cargo.toml", - r#" - [package] - name = "dep1" - version = "0.5.0" - authors = [""] - "#, - ) + project.file("Cargo.toml", &basic_manifest("dep1", "0.5.0")) }).unwrap(); let git_project2 = git::new("dep2", |project| project.file("lib.rs", "")).unwrap(); diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index cc41010000f..bc2fdbfaf60 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -167,26 +167,14 @@ fn confused_by_multiple_lib_files() { File::create(&sourcefile_path1) .unwrap() - .write_all( - br#" - fn qqq () { - println!("Hello, world 2!"); - } - "#, - ) + .write_all(br#"fn qqq () { println!("Hello, world 2!"); }"#) .unwrap(); let sourcefile_path2 = path.join("lib.rs"); File::create(&sourcefile_path2) .unwrap() - .write_all( - br#" - fn qqq () { - println!("Hello, world 3!"); - } - "#, - ) + .write_all(br#" fn qqq () { println!("Hello, world 3!"); }"#) .unwrap(); assert_that( @@ -215,26 +203,14 @@ fn multibin_project_name_clash() { File::create(&sourcefile_path1) .unwrap() - .write_all( - br#" - fn main () { - println!("Hello, world 2!"); - } - "#, - ) + .write_all(br#"fn main () { println!("Hello, world 2!"); }"#) .unwrap(); let sourcefile_path2 = path.join("main.rs"); File::create(&sourcefile_path2) .unwrap() - .write_all( - br#" - fn main () { - println!("Hello, world 3!"); - } - "#, - ) + .write_all(br#"fn main () { println!("Hello, world 3!"); }"#) .unwrap(); assert_that( diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index f2aa6f087c1..867b4ab56b1 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -8,7 +8,7 @@ use support::cross_compile; use support::git; use support::paths; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::ChannelChanger; use git2; use support::hamcrest::{assert_that, existing_dir, is_not}; @@ -22,16 +22,7 @@ fn cargo_process(s: &str) -> ProcessBuilder { fn pkg(name: &str, vers: &str) { Package::new(name, vers) .file("src/lib.rs", "") - .file( - "src/main.rs", - &format!( - " - extern crate {}; - fn main() {{}} - ", - name - ), - ) + .file("src/main.rs", &format!("extern crate {}; fn main() {{}}", name)) .publish(); } @@ -142,15 +133,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina #[test] fn installs_beta_version_by_explicit_name_from_git() { let p = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.3.0-beta.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.3.0-beta.1")) .file("src/main.rs", "fn main() {}") .build(); @@ -301,25 +284,9 @@ Add --force to overwrite #[test] fn multiple_crates_error() { let p = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") - .file( - "a/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("a/src/main.rs", "fn main() {}") .build(); @@ -339,25 +306,9 @@ fn multiple_crates_error() { #[test] fn multiple_crates_select() { let p = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") - .file( - "a/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("a/src/main.rs", "fn main() {}") .build(); @@ -397,15 +348,7 @@ fn multiple_crates_auto_binaries() { "#, ) .file("src/main.rs", "extern crate bar; fn main() {}") - .file( - "a/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("a/src/lib.rs", "") .build(); @@ -440,15 +383,7 @@ fn multiple_crates_auto_examples() { fn main() {} ", ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("a/src/lib.rs", "") .build(); @@ -478,15 +413,7 @@ fn no_binaries_or_examples() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("a/src/lib.rs", "") .build(); @@ -572,15 +499,7 @@ fn install_force() { ); let p = project().at("foo2") - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.2.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.2.0")) .file("src/main.rs", "fn main() {}") .build(); @@ -625,15 +544,7 @@ fn install_force_partial_overlap() { ); let p = project().at("foo2") - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.2.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.2.0")) .file("src/bin/foo-bin2.rs", "fn main() {}") .file("src/bin/foo-bin3.rs", "fn main() {}") .build(); @@ -683,15 +594,7 @@ fn install_force_bin() { ); let p = project().at("foo2") - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.2.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.2.0")) .file("src/bin/foo-bin1.rs", "fn main() {}") .file("src/bin/foo-bin2.rs", "fn main() {}") .build(); @@ -753,15 +656,7 @@ To learn more, run the command again with --verbose. #[test] fn git_repo() { let p = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") .build(); @@ -918,14 +813,7 @@ fn uninstall_piecemeal() { #[test] fn subcommand_works_out_of_the_box() { Package::new("cargo-foo", "1.0.0") - .file( - "src/main.rs", - r#" - fn main() { - println!("bar"); - } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("bar"); }"#) .publish(); assert_that( cargo_process("install").arg("cargo-foo"), @@ -1022,14 +910,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina #[test] fn reports_unsuccessful_subcommand_result() { Package::new("cargo-fail", "1.0.0") - .file( - "src/main.rs", - r#" - fn main() { - panic!(); - } - "#, - ) + .file("src/main.rs", "fn main() { panic!(); }") .publish(); assert_that( cargo_process("install").arg("cargo-fail"), @@ -1063,15 +944,7 @@ fn git_with_lockfile() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "fn main() {}") .file( "Cargo.lock", @@ -1208,15 +1081,7 @@ fn dev_dependencies_lock_file_untouched() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "a/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("a/src/lib.rs", "") .build(); @@ -1369,15 +1234,7 @@ error: some packages failed to uninstall #[test] fn custom_target_dir_for_git_source() { let p = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") .build(); @@ -1412,14 +1269,7 @@ fn install_respects_lock_file() { Package::new("foo", "0.1.0") .dep("bar", "0.1") .file("src/lib.rs", "") - .file( - "src/main.rs", - " - extern crate foo; - extern crate bar; - fn main() {} - ", - ) + .file("src/main.rs", "extern crate foo; extern crate bar; fn main() {}") .file( "Cargo.lock", r#" @@ -1448,14 +1298,7 @@ fn lock_file_path_deps_ok() { Package::new("foo", "0.1.0") .dep("bar", "0.1") .file("src/lib.rs", "") - .file( - "src/main.rs", - " - extern crate foo; - extern crate bar; - fn main() {} - ", - ) + .file("src/main.rs", "extern crate foo; extern crate bar; fn main() {}") .file( "Cargo.lock", r#" @@ -1490,15 +1333,7 @@ fn install_empty_argument() { #[test] fn git_repo_replace() { let p = git::repo(&paths::root().join("foo")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") .build(); let repo = git2::Repository::open(&p.root()).unwrap(); @@ -1552,15 +1387,7 @@ fn workspace_uses_workspace_target_dir() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}") .build(); diff --git a/tests/testsuite/local_registry.rs b/tests/testsuite/local_registry.rs index 66f6ca18f39..2c7a0816f4e 100644 --- a/tests/testsuite/local_registry.rs +++ b/tests/testsuite/local_registry.rs @@ -3,7 +3,7 @@ use std::io::prelude::*; use support::paths::{self, CargoPathExt}; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; fn setup() { @@ -42,15 +42,7 @@ fn simple() { bar = "0.0.1" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -94,15 +86,7 @@ fn multiple_versions() { bar = "*" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -265,15 +249,7 @@ fn path_dep_rewritten() { "#, ) .file("src/lib.rs", "extern crate bar; pub fn baz() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") .publish(); @@ -460,15 +436,7 @@ fn crates_io_registry_url_is_optional() { bar = "0.0.1" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index c31117540b9..d1e82e5b99e 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -1,6 +1,6 @@ use support::git; use support::registry::Package; -use support::{execs, lines_match, project}; +use support::{basic_manifest, execs, lines_match, project}; use support::hamcrest::assert_that; #[test] @@ -313,15 +313,8 @@ this could be indicative of a few possible situations: #[test] fn listed_checksum_bad_if_we_cannot_compute() { let git = git::new("bar", |p| { - p.file( - "Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ).file("src/lib.rs", "") + p.file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "") }).unwrap(); let p = project() diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 4e728d3933c..d847861dd56 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -30,12 +30,7 @@ fn setup_new_credentials() { let config = cargo_home().join("credentials"); t!(fs::create_dir_all(config.parent().unwrap())); t!(t!(File::create(&config)).write_all( - format!( - r#" - token = "{token}" - "#, - token = ORIGINAL_TOKEN - ).as_bytes() + format!(r#"token = "{token}""#, token = ORIGINAL_TOKEN).as_bytes() )); } diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index 991a4d9a534..970083f2492 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -5,7 +5,7 @@ use std::env; use support::hamcrest::assert_that; use support::{process, sleep_ms, ChannelChanger}; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; #[test] fn binary_with_debug() { @@ -164,15 +164,7 @@ fn include_only_the_binary_from_the_current_package() { } "#, ) - .file( - "utils/Cargo.toml", - r#" - [project] - name = "utils" - version = "0.0.1" - authors = [] - "#, - ) + .file("utils/Cargo.toml", &basic_manifest("utils", "0.0.1")) .file("utils/src/lib.rs", "") .build(); diff --git a/tests/testsuite/overrides.rs b/tests/testsuite/overrides.rs index 00df0b62db7..944a29bbed4 100644 --- a/tests/testsuite/overrides.rs +++ b/tests/testsuite/overrides.rs @@ -1,7 +1,7 @@ use support::git; use support::paths; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; #[test] @@ -9,15 +9,7 @@ fn override_simple() { Package::new("bar", "0.1.0").publish(); let bar = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -40,15 +32,7 @@ fn override_simple() { bar.url() ), ) - .file( - "src/lib.rs", - " - extern crate bar; - pub fn foo() { - bar::bar(); - } - ", - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -179,15 +163,7 @@ fn transitive() { .publish(); let foo = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -236,15 +212,7 @@ fn persists_across_rebuilds() { Package::new("bar", "0.1.0").publish(); let foo = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -267,15 +235,7 @@ fn persists_across_rebuilds() { foo.url() ), ) - .file( - "src/lib.rs", - " - extern crate bar; - pub fn foo() { - bar::bar(); - } - ", - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -299,15 +259,7 @@ fn replace_registry_with_path() { Package::new("bar", "0.1.0").publish(); let _ = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -327,15 +279,7 @@ fn replace_registry_with_path() { "bar:0.1.0" = { path = "../bar" } "#, ) - .file( - "src/lib.rs", - " - extern crate bar; - pub fn foo() { - bar::bar(); - } - ", - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -359,25 +303,11 @@ fn use_a_spec_to_select() { Package::new("baz", "0.2.0").publish(); Package::new("bar", "0.1.1") .dep("baz", "0.2") - .file( - "src/lib.rs", - " - extern crate baz; - pub fn bar() { baz::baz3(); } - ", - ) + .file("src/lib.rs", "extern crate baz; pub fn bar() { baz::baz3(); }") .publish(); let foo = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "baz" - version = "0.2.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("baz", "0.2.0")) .file("src/lib.rs", "pub fn baz3() {}") .build(); @@ -576,15 +506,7 @@ fn override_wrong_name() { Package::new("baz", "0.1.0").publish(); let foo = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "") .build(); @@ -708,15 +630,7 @@ fn multiple_specs() { Package::new("bar", "0.1.0").publish(); let bar = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -767,15 +681,7 @@ fn test_override_dep() { Package::new("bar", "0.1.0").publish(); let bar = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -819,15 +725,7 @@ fn update() { Package::new("bar", "0.1.0").publish(); let bar = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -870,15 +768,7 @@ fn update() { #[test] fn no_override_self() { let deps = git::repo(&paths::root().join("override")) - .file( - "far/Cargo.toml", - r#" - [package] - name = "far" - version = "0.1.0" - authors = [] - "#, - ) + .file("far/Cargo.toml", &basic_manifest("far", "0.1.0")) .file("far/src/lib.rs", "") .file( "near/Cargo.toml", @@ -892,13 +782,7 @@ fn no_override_self() { far = { path = "../far" } "#, ) - .file( - "near/src/lib.rs", - r#" - #![no_std] - pub extern crate far; - "#, - ) + .file("near/src/lib.rs", "#![no_std] pub extern crate far;") .build(); let p = project() @@ -920,13 +804,7 @@ fn no_override_self() { deps.url() ), ) - .file( - "src/lib.rs", - r#" - #![no_std] - pub extern crate near; - "#, - ) + .file("src/lib.rs", "#![no_std] pub extern crate near;") .build(); assert_that(p.cargo("build").arg("--verbose"), execs().with_status(0)); @@ -977,12 +855,7 @@ fn broken_path_override_warns() { "#, ) .file("a2/src/lib.rs", "") - .file( - ".cargo/config", - r#" - paths = ["a2"] - "#, - ) + .file(".cargo/config", r#"paths = ["a2"]"#) .build(); assert_that( @@ -1118,21 +991,8 @@ fn override_an_override() { } ", ) - .file( - "serde/Cargo.toml", - r#" - [package] - name = "serde" - version = "0.8.0" - authors = [] - "#, - ) - .file( - "serde/src/lib.rs", - " - pub fn serde08_override() {} - ", - ) + .file("serde/Cargo.toml", &basic_manifest("serde", "0.8.0")) + .file("serde/src/lib.rs", "pub fn serde08_override() {}") .build(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -1157,15 +1017,7 @@ fn overriding_nonexistent_no_spurious() { "#, ) .file("src/lib.rs", "pub fn bar() {}") - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.1.0" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) .file("baz/src/lib.rs", "pub fn baz() {}") .build(); @@ -1234,23 +1086,9 @@ fn no_warnings_when_replace_is_used_in_another_workspace_member() { "#, ) .file("first_crate/src/lib.rs", "") - .file( - "second_crate/Cargo.toml", - r#" - [package] - name = "second_crate" - version = "0.1.0" - "#, - ) + .file("second_crate/Cargo.toml", &basic_manifest("second_crate", "0.1.0")) .file("second_crate/src/lib.rs", "") - .file( - "local_bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - "#, - ) + .file("local_bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("local_bar/src/lib.rs", "") .build(); @@ -1307,22 +1145,9 @@ fn override_to_path_dep() { "#, ) .file("bar/src/lib.rs", "") - .file( - "bar/baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("bar/baz/src/lib.rs", "") - .file( - ".cargo/config", - r#" - paths = ["bar"] - "#, - ) + .file(".cargo/config", r#"paths = ["bar"]"#) .build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -1362,25 +1187,8 @@ fn replace_to_path_dep() { baz = { path = "baz" } "#, ) - .file( - "bar/src/lib.rs", - " - extern crate baz; - - pub fn bar() { - baz::baz(); - } - ", - ) - .file( - "bar/baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/src/lib.rs", "extern crate baz; pub fn bar() { baz::baz(); }") + .file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) .file("bar/baz/src/lib.rs", "pub fn baz() {}") .build(); @@ -1431,12 +1239,7 @@ fn paths_ok_with_optional() { "#, ) .file("bar2/src/lib.rs", "") - .file( - ".cargo/config", - r#" - paths = ["bar2"] - "#, - ) + .file(".cargo/config", r#"paths = ["bar2"]"#) .build(); assert_that( @@ -1469,15 +1272,7 @@ fn paths_add_optional_bad() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .file( "bar2/Cargo.toml", @@ -1492,12 +1287,7 @@ fn paths_add_optional_bad() { "#, ) .file("bar2/src/lib.rs", "") - .file( - ".cargo/config", - r#" - paths = ["bar2"] - "#, - ) + .file(".cargo/config", r#"paths = ["bar2"]"#) .build(); assert_that( @@ -1535,16 +1325,7 @@ fn override_with_default_feature() { 'bar:0.1.0' = { path = "bar" } "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - - fn main() { - bar::bar(); - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::bar(); }") .file( "bar/Cargo.toml", r#" diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 431783eccfb..e00f6517888 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use git2; use support::{cargo_process, process, sleep_ms, ChannelChanger}; -use support::{cargo_exe, execs, git, paths, project, registry, path2url}; +use support::{basic_manifest, cargo_exe, execs, git, paths, project, registry, path2url}; use support::registry::Package; use flate2::read::GzDecoder; use support::hamcrest::{assert_that, contains, existing_file}; @@ -23,9 +23,7 @@ fn simple() { license = "MIT" description = "foo" "#) - .file("src/main.rs", r#" - fn main() { println!("hello"); } - "#) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .file("src/bar.txt", "") // should be ignored when packaging .build(); @@ -79,12 +77,7 @@ src[/]main.rs #[test] fn metadata_warning() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( p.cargo("package"), @@ -113,12 +106,7 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. license = "MIT" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( p.cargo("package"), @@ -148,12 +136,7 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. repository = "bar" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( p.cargo("package"), @@ -173,30 +156,9 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. fn package_verbose() { let root = paths::root().join("all"); let p = git::repo(&root) - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.0.1")) + .file("src/main.rs", "fn main() {}") + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); let mut cargo = cargo_process(); @@ -239,12 +201,7 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. #[test] fn package_verification() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that(p.cargo("build"), execs().with_status(0)); assert_that( @@ -281,15 +238,7 @@ fn path_dependency_no_version() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .build(); @@ -342,9 +291,7 @@ fn exclude() { "dir_deep_5/**", # CHANGING (packaged -> ignored) ] "#) - .file("src/main.rs", r#" - fn main() { println!("hello"); } - "#) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .file("bar.txt", "") .file("src/bar.txt", "") // file in root @@ -458,9 +405,7 @@ fn include() { include = ["foo.txt", "**/*.rs", "Cargo.toml"] "#) .file("foo.txt", "") - .file("src/main.rs", r#" - fn main() { println!("hello"); } - "#) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .file("src/bar.txt", "") // should be ignored when packaging .build(); @@ -482,13 +427,7 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. #[test] fn package_lib_with_bin() { let p = project() - .file( - "src/main.rs", - r#" - extern crate foo; - fn main() {} - "#, - ) + .file("src/main.rs", "extern crate foo; fn main() {}") .file("src/lib.rs", "") .build(); @@ -545,29 +484,12 @@ fn package_git_submodule() { fn no_duplicates_from_modified_tracked_files() { let root = paths::root().join("all"); let p = git::repo(&root) - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.0.1")) + .file("src/main.rs", "fn main() {}") .build(); File::create(p.root().join("src/main.rs")) .unwrap() - .write_all( - br#" - fn main() { println!("A change!"); } - "#, - ) + .write_all(br#"fn main() { println!("A change!"); }"#) .unwrap(); let mut cargo = cargo_process(); cargo.cwd(p.root()); @@ -656,12 +578,7 @@ src[..]main.rs #[test] fn package_weird_characters() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .file("src/:foo", "") .build(); @@ -684,12 +601,7 @@ Caused by: #[test] fn repackage_on_source_change() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); assert_that(p.cargo("package"), execs().with_status(0)); @@ -703,11 +615,7 @@ fn repackage_on_source_change() { ) }); - file.write_all( - br#" - fn main() { println!("foo"); } - "#, - ).unwrap(); + file.write_all(br#"fn main() { println!("foo"); }"#).unwrap(); std::mem::drop(file); let mut pro = process(&cargo_exe()); @@ -765,12 +673,7 @@ fn broken_symlink() { repository = 'foo' "#, ) - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); t!(fs::symlink("nowhere", &p.root().join("src/foo.rs"))); @@ -876,15 +779,7 @@ fn generated_manifest() { "#, ) .file("src/main.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .build(); @@ -1375,9 +1270,7 @@ fn lock_file_and_workspace() { #[test] fn do_not_package_if_src_was_modified() { let p = project() - .file("src/main.rs", r#" - fn main() { println!("hello"); } - "#) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .file("build.rs", r#" use std::fs::File; use std::io::Write; diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index 3d2afff4568..2de96f86e41 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -5,22 +5,14 @@ use toml; use support::git; use support::paths; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; #[test] fn replace() { Package::new("bar", "0.1.0").publish(); Package::new("baz", "0.1.0") - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn baz() { - bar::bar(); - } - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn baz() { bar::bar(); }") .dep("bar", "0.1.0") .publish(); @@ -52,21 +44,8 @@ fn replace() { } ", ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -109,30 +88,9 @@ fn nonexistent() { bar = { path = "bar" } "#, ) - .file( - "src/lib.rs", - " - extern crate bar; - pub fn foo() { - bar::bar(); - } - ", - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -155,15 +113,7 @@ fn nonexistent() { #[test] fn patch_git() { let bar = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "") .build(); @@ -186,30 +136,9 @@ fn patch_git() { bar.url() ), ) - .file( - "src/lib.rs", - " - extern crate bar; - pub fn foo() { - bar::bar(); - } - ", - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -232,15 +161,7 @@ fn patch_git() { #[test] fn patch_to_git() { let bar = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("src/lib.rs", "pub fn bar() {}") .build(); @@ -265,15 +186,7 @@ fn patch_to_git() { bar.url() ), ) - .file( - "src/lib.rs", - " - extern crate bar; - pub fn foo() { - bar::bar(); - } - ", - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::bar(); }") .build(); assert_that( @@ -315,21 +228,8 @@ fn unused() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.2.0" - authors = [] - "#, - ) - .file( - "bar/src/lib.rs", - r#" - not rust code - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0")) + .file("bar/src/lib.rs", "not rust code") .build(); assert_that( @@ -369,15 +269,7 @@ fn unused_git() { Package::new("bar", "0.1.0").publish(); let foo = git::repo(&paths::root().join("override")) - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.2.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.2.0")) .file("src/lib.rs", "") .build(); @@ -440,15 +332,7 @@ fn add_patch() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", r#""#) .build(); @@ -518,15 +402,7 @@ fn add_ignored_patch() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1")) .file("bar/src/lib.rs", r#""#) .build(); @@ -595,15 +471,7 @@ fn new_minor() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1")) .file("bar/src/lib.rs", r#""#) .build(); @@ -654,15 +522,7 @@ fn transitive_new_minor() { "#, ) .file("bar/src/lib.rs", r#""#) - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.1.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.1")) .file("baz/src/lib.rs", r#""#) .build(); @@ -701,15 +561,7 @@ fn new_major() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.2.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0")) .file("bar/src/lib.rs", r#""#) .build(); @@ -793,15 +645,7 @@ fn transitive_new_major() { "#, ) .file("bar/src/lib.rs", r#""#) - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.2.0" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.2.0")) .file("baz/src/lib.rs", r#""#) .build(); @@ -842,25 +686,9 @@ fn remove_patch() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", r#""#) - .file( - "foo/Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", r#""#) .build(); @@ -929,15 +757,7 @@ fn non_crates_io() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", r#""#) .build(); @@ -972,15 +792,7 @@ fn replace_with_crates_io() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", r#""#) .build(); @@ -1014,15 +826,7 @@ fn patch_in_virtual() { bar = { path = "bar" } "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", r#""#) .file( "foo/Cargo.toml", @@ -1076,15 +880,7 @@ fn patch_depends_on_another_patch() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1")) .file("bar/src/lib.rs", r#""#) .file( "baz/Cargo.toml", @@ -1136,13 +932,7 @@ fn replace_prerelease() { baz = "1.1.0-pre.1" "#, ) - .file( - "bar/src/main.rs", - " - extern crate baz; - fn main() { baz::baz() } - ", - ) + .file("bar/src/main.rs", "extern crate baz; fn main() { baz::baz() }") .file( "baz/Cargo.toml", r#" diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index 900ab7e9a04..0e699b596d2 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -5,7 +5,7 @@ use cargo::util::process; use support::sleep_ms; use support::paths::{self, CargoPathExt}; use support::registry::Package; -use support::{execs, main_file, project}; +use support::{basic_manifest, basic_lib_manifest, execs, main_file, project}; use support::hamcrest::{assert_that, existing_file, is_not}; #[test] @@ -58,20 +58,7 @@ fn cargo_compile_with_nested_deps_shorthand() { } "#, ) - .file( - "bar/baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - - name = "baz" - "#, - ) + .file("bar/baz/Cargo.toml", &basic_lib_manifest("baz")) .file( "bar/baz/src/baz.rs", r#" @@ -156,16 +143,7 @@ fn cargo_compile_with_root_dev_deps() { .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"])) .build(); let _p2 = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file( "src/lib.rs", r#" @@ -203,16 +181,7 @@ fn cargo_compile_with_root_dev_deps_with_testing() { .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"])) .build(); let _p2 = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file( "src/lib.rs", r#" @@ -317,32 +286,9 @@ fn no_rebuild_dependency() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { bar::bar() } - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - name = "bar" - "#, - ) - .file( - "bar/src/bar.rs", - r#" - pub fn bar() {} - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::bar() }") + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) + .file("bar/src/bar.rs", "pub fn bar() {}") .build(); // First time around we should compile both foo and bar assert_that( @@ -393,13 +339,7 @@ fn deep_dependencies_trigger_rebuild() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { bar::bar() } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::bar() }") .file( "bar/Cargo.toml", r#" @@ -415,32 +355,9 @@ fn deep_dependencies_trigger_rebuild() { path = "../baz" "#, ) - .file( - "bar/src/bar.rs", - r#" - extern crate baz; - pub fn bar() { baz::baz() } - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - name = "baz" - "#, - ) - .file( - "baz/src/baz.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/src/bar.rs", "extern crate baz; pub fn bar() { baz::baz() }") + .file("baz/Cargo.toml", &basic_lib_manifest("baz")) + .file("baz/src/baz.rs", "pub fn baz() {}") .build(); assert_that( p.cargo("build"), @@ -464,11 +381,7 @@ fn deep_dependencies_trigger_rebuild() { sleep_ms(1000); File::create(&p.root().join("baz/src/baz.rs")) .unwrap() - .write_all( - br#" - pub fn baz() { println!("hello!"); } - "#, - ) + .write_all(br#"pub fn baz() { println!("hello!"); }"#) .unwrap(); assert_that( p.cargo("build"), @@ -526,13 +439,7 @@ fn no_rebuild_two_deps() { path = "baz" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { bar::bar() } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::bar() }") .file( "bar/Cargo.toml", r#" @@ -548,31 +455,9 @@ fn no_rebuild_two_deps() { path = "../baz" "#, ) - .file( - "bar/src/bar.rs", - r#" - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - - name = "baz" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - name = "baz" - "#, - ) - .file( - "baz/src/baz.rs", - r#" - pub fn baz() {} - "#, - ) + .file("bar/src/bar.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_lib_manifest("baz")) + .file("baz/src/baz.rs", "pub fn baz() {}") .build(); assert_that( p.cargo("build"), @@ -611,20 +496,7 @@ fn nested_deps_recompile() { "#, ) .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"])) - .file( - "src/bar/Cargo.toml", - r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [lib] - - name = "bar" - "#, - ) + .file("src/bar/Cargo.toml", &basic_lib_manifest("bar")) .file("src/bar/src/bar.rs", "pub fn gimme() -> i32 { 92 }") .build(); let bar = p.url(); @@ -644,11 +516,7 @@ fn nested_deps_recompile() { File::create(&p.root().join("src/main.rs")) .unwrap() - .write_all( - br#" - fn main() {} - "#, - ) + .write_all(br#"fn main() {}"#) .unwrap(); // This shouldn't recompile `bar` @@ -706,16 +574,7 @@ Caused by: #[test] fn override_relative() { let bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "") .build(); @@ -750,30 +609,15 @@ fn override_relative() { #[test] fn override_self() { let bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("src/lib.rs", "") .build(); let p = project(); let root = p.root().clone(); - let p = p.file( - ".cargo/config", - &format!( - r#" - paths = ['{}'] - "#, - root.display() - ), - ).file( + let p = p + .file(".cargo/config", &format!("paths = ['{}']", root.display())) + .file( "Cargo.toml", &format!( r#" @@ -813,15 +657,7 @@ fn override_path_dep() { "#, ) .file("p1/src/lib.rs", "") - .file( - "p2/Cargo.toml", - r#" - [package] - name = "p2" - version = "0.5.0" - authors = [] - "#, - ) + .file("p2/Cargo.toml", &basic_manifest("p2", "0.5.0")) .file("p2/src/lib.rs", "") .build(); @@ -829,9 +665,7 @@ fn override_path_dep() { .file( ".cargo/config", &format!( - r#" - paths = ['{}', '{}'] - "#, + "paths = ['{}', '{}']", bar.root().join("p1").display(), bar.root().join("p2").display() ), @@ -902,12 +736,7 @@ fn path_dep_build_cmd() { } "#, ) - .file( - "bar/src/bar.rs.in", - r#" - pub fn gimme() -> i32 { 0 } - "#, - ) + .file("bar/src/bar.rs.in", "pub fn gimme() -> i32 { 0 }") .build(); p.root().join("bar").move_into_the_past(); @@ -976,16 +805,7 @@ fn dev_deps_no_rebuild_lib() { #[cfg(not(test))] pub fn foo() { env!("FOO"); } "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that( @@ -1031,15 +851,7 @@ fn custom_target_no_rebuild() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.5.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.5.0")) .file("a/src/lib.rs", "") .file( "b/Cargo.toml", @@ -1098,15 +910,7 @@ fn override_and_depend() { "#, ) .file("a/a1/src/lib.rs", "") - .file( - "a/a2/Cargo.toml", - r#" - [project] - name = "a2" - version = "0.5.0" - authors = [] - "#, - ) + .file("a/a2/Cargo.toml", &basic_manifest("a2", "0.5.0")) .file("a/a2/src/lib.rs", "") .file( "b/Cargo.toml", @@ -1121,12 +925,7 @@ fn override_and_depend() { "#, ) .file("b/src/lib.rs", "") - .file( - "b/.cargo/config", - r#" - paths = ["../a"] - "#, - ) + .file("b/.cargo/config", r#"paths = ["../a"]"#) .build(); assert_that( p.cargo("build").cwd(p.root().join("b")), @@ -1144,22 +943,9 @@ fn override_and_depend() { #[test] fn missing_path_dependency() { let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "a" - version = "0.5.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("a", "0.5.0")) .file("src/lib.rs", "") - .file( - ".cargo/config", - r#" - paths = ["../whoa-this-does-not-exist"] - "#, - ) + .file(".cargo/config", r#"paths = ["../whoa-this-does-not-exist"]"#) .build(); assert_that( p.cargo("build"), @@ -1265,15 +1051,7 @@ fn workspace_produces_rlib() { "#, ) .file("src/lib.rs", "") - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.5.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.5.0")) .file("foo/src/lib.rs", "") .build(); diff --git a/tests/testsuite/plugins.rs b/tests/testsuite/plugins.rs index 6f903054e9a..b78e17a7394 100644 --- a/tests/testsuite/plugins.rs +++ b/tests/testsuite/plugins.rs @@ -2,7 +2,7 @@ use std::fs; use std::env; use support::{is_nightly, rustc_host}; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; #[test] @@ -132,13 +132,7 @@ fn plugin_with_dynamic_native_dependency() { crate-type = ["dylib"] "#, ) - .file( - "src/lib.rs", - r#" - #[no_mangle] - pub extern fn foo() {} - "#, - ) + .file("src/lib.rs", "#[no_mangle] pub extern fn foo() {}") .build(); let foo = project().at("ws/foo") @@ -268,13 +262,7 @@ fn doctest_a_plugin() { bar = { path = "bar" } "#, ) - .file( - "src/lib.rs", - r#" - #[macro_use] - extern crate bar; - "#, - ) + .file("src/lib.rs", "#[macro_use] extern crate bar;") .file( "bar/Cargo.toml", r#" @@ -288,12 +276,7 @@ fn doctest_a_plugin() { plugin = true "#, ) - .file( - "bar/src/lib.rs", - r#" - pub fn bar() {} - "#, - ) + .file("bar/src/lib.rs", "pub fn bar() {}") .build(); assert_that(p.cargo("test").arg("-v"), execs().with_status(0)); @@ -429,12 +412,7 @@ fn shared_panic_abort_plugins() { baz = { path = "baz" } "#, ) - .file( - "src/lib.rs", - " - extern crate baz; - ", - ) + .file("src/lib.rs", "extern crate baz;") .file( "bar/Cargo.toml", r#" @@ -458,15 +436,7 @@ fn shared_panic_abort_plugins() { extern crate baz; "#, ) - .file( - "baz/Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) .file("baz/src/lib.rs", "") .build(); diff --git a/tests/testsuite/profile_overrides.rs b/tests/testsuite/profile_overrides.rs index bde033da9e1..bd8384bbbbc 100644 --- a/tests/testsuite/profile_overrides.rs +++ b/tests/testsuite/profile_overrides.rs @@ -1,4 +1,4 @@ -use support::{basic_lib_manifest, execs, project}; +use support::{basic_manifest, basic_lib_manifest, execs, project}; use support::ChannelChanger; use support::hamcrest::assert_that; @@ -273,13 +273,8 @@ fn profile_override_hierarchy() { m2 = { path = "../m2" } dep = { path = "../../dep" } "#) - .file("m1/src/lib.rs", - r#" - extern crate m2; - extern crate dep; - "#) - .file("m1/build.rs", - r#"fn main() {}"#) + .file("m1/src/lib.rs", "extern crate m2; extern crate dep;") + .file("m1/build.rs", "fn main() {}") // m2 .file("m2/Cargo.toml", @@ -295,16 +290,8 @@ fn profile_override_hierarchy() { m3 = { path = "../m3" } dep = { path = "../../dep" } "#) - .file("m2/src/lib.rs", - r#" - extern crate m3; - "#) - .file("m2/build.rs", - r#" - extern crate m3; - extern crate dep; - fn main() {} - "#) + .file("m2/src/lib.rs", "extern crate m3;") + .file("m2/build.rs", "extern crate m3; extern crate dep; fn main() {}") // m3 .file("m3/Cargo.toml", &basic_lib_manifest("m3")) @@ -413,10 +400,7 @@ fn profile_override_spec() { [dependencies] dep = { path = "../../dep1" } "#) - .file("m1/src/lib.rs", - r#" - extern crate dep; - "#) + .file("m1/src/lib.rs", "extern crate dep;") // m2 .file("m2/Cargo.toml", @@ -428,34 +412,17 @@ fn profile_override_spec() { [dependencies] dep = {path = "../../dep2" } "#) - .file("m2/src/lib.rs", - r#" - extern crate dep; - "#) + .file("m2/src/lib.rs", "extern crate dep;") .build(); project().at("dep1") - .file( - "Cargo.toml", - r#" - [package] - name = "dep" - version = "1.0.0" - "#, - ) + .file("Cargo.toml", &basic_manifest("dep", "1.0.0")) .file("src/lib.rs", "") .build(); project().at("dep2") - .file( - "Cargo.toml", - r#" - [package] - name = "dep" - version = "2.0.0" - "#, - ) + .file("Cargo.toml", &basic_manifest("dep", "2.0.0")) .file("src/lib.rs", "") .build(); diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 5c954cba7ab..3bbcc4089fd 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -1,5 +1,5 @@ use support::is_nightly; -use support::{execs, project, Project}; +use support::{basic_manifest, execs, project, Project}; use support::hamcrest::assert_that; // These tests try to exercise exactly which profiles are selected for every @@ -35,14 +35,8 @@ fn all_target_project() -> Project { "#, ) .file("src/lib.rs", "extern crate bar;") - .file("src/main.rs", r#" - extern crate foo; - fn main() {} - "#) - .file("examples/ex1.rs", r#" - extern crate foo; - fn main() {} - "#) + .file("src/main.rs", "extern crate foo; fn main() {}") + .file("examples/ex1.rs", "extern crate foo; fn main() {}") .file("tests/test1.rs", "extern crate foo;") .file("benches/bench1.rs", "extern crate foo;") .file("build.rs", r#" @@ -57,11 +51,7 @@ fn all_target_project() -> Project { "#) // bar package - .file("bar/Cargo.toml", r#" - [package] - name = "bar" - version = "0.0.1" - "#) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") // bdep package diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 7ea87869953..f229bbd6d3e 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -5,7 +5,7 @@ use std::io::SeekFrom; use support::ChannelChanger; use support::git::repo; use support::paths; -use support::{execs, project, publish}; +use support::{basic_manifest, execs, project, publish}; use flate2::read::GzDecoder; use support::hamcrest::assert_that; use tar::Archive; @@ -87,11 +87,7 @@ fn old_token_location() { let credentials = paths::root().join("home/.cargo/credentials"); File::create(credentials) .unwrap() - .write_all( - br#" - token = "api-token" - "#, - ) + .write_all(br#"token = "api-token""#) .unwrap(); let p = project() @@ -376,15 +372,7 @@ fn path_dependency_no_version() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index d9f88107cca..fbb16ef2c15 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -7,7 +7,7 @@ use support::cargo_process; use support::git; use support::paths::{self, CargoPathExt}; use support::registry::{self, Package}; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; use url::Url; @@ -371,15 +371,7 @@ fn package_with_path_deps() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "notyet/Cargo.toml", - r#" - [package] - name = "notyet" - version = "0.0.1" - authors = [] - "#, - ) + .file("notyet/Cargo.toml", &basic_manifest("notyet", "0.0.1")) .file("notyet/src/lib.rs", "") .build(); @@ -869,12 +861,7 @@ fn bad_license_file() { repository = "baz" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); assert_that( p.cargo("publish") @@ -1330,15 +1317,7 @@ fn bundled_crate_in_registry() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/lib.rs", "") .publish(); @@ -1800,14 +1779,7 @@ fn toml_lies_but_index_is_truth() { #[test] fn vv_prints_warnings() { Package::new("foo", "0.2.0") - .file( - "src/lib.rs", - r#" - #![deny(warnings)] - - fn foo() {} // unused function - "#, - ) + .file("src/lib.rs", "#![deny(warnings)] fn foo() {} // unused function") .publish(); let p = project() diff --git a/tests/testsuite/rename_deps.rs b/tests/testsuite/rename_deps.rs index 84567faafc0..e65844b92f4 100644 --- a/tests/testsuite/rename_deps.rs +++ b/tests/testsuite/rename_deps.rs @@ -2,7 +2,7 @@ use support::ChannelChanger; use support::git; use support::paths; use support::registry::Package; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; #[test] @@ -89,13 +89,7 @@ fn rename_dependency() { baz = { version = "0.2.0", package = "bar" } "#, ) - .file( - "src/lib.rs", - " - extern crate bar; - extern crate baz; - ", - ) + .file("src/lib.rs", "extern crate bar; extern crate baz;") .build(); assert_that( @@ -121,12 +115,7 @@ fn rename_with_different_names() { baz = { path = "bar", package = "bar" } "#, ) - .file( - "src/lib.rs", - " - extern crate baz; - ", - ) + .file("src/lib.rs", "extern crate baz;") .file( "bar/Cargo.toml", r#" @@ -162,15 +151,7 @@ fn lots_of_names() { .publish(); let g = git::repo(&paths::root().join("another")) - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/lib.rs", "pub fn foo3() {}") .build(); @@ -212,15 +193,7 @@ fn lots_of_names() { } ", ) - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "pub fn foo4() {}") .build(); @@ -252,25 +225,8 @@ fn rename_and_patch() { foo = { path = "foo" } "#, ) - .file( - "src/lib.rs", - " - extern crate bar; - - pub fn foo() { - bar::foo(); - } - ", - ) - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() { bar::foo(); }") + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "pub fn foo() {}") .build(); diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index 25b4cd331c9..3890aecedee 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -36,13 +36,7 @@ fn build_bin_default_features() { fn main() {} "#, ) - .file( - "src/lib.rs", - r#" - #[cfg(feature = "a")] - pub fn foo() {} - "#, - ) + .file("src/lib.rs", r#"#[cfg(feature = "a")] pub fn foo() {}"#) .build(); assert_that(p.cargo("build"), execs().with_status(0)); diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 62bc8cdd5b3..6f64072078c 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -1,17 +1,12 @@ use cargo::util::paths::dylib_path_envvar; use support::{self, ChannelChanger}; -use support::{execs, project, Project, path2url}; +use support::{basic_bin_manifest, basic_lib_manifest, execs, project, Project, path2url}; use support::hamcrest::{assert_that, existing_file}; #[test] fn simple() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); assert_that( @@ -33,12 +28,7 @@ fn simple() { #[test] fn simple_quiet() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); assert_that( @@ -55,12 +45,7 @@ fn simple_quiet() { #[test] fn simple_quiet_and_verbose() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); assert_that( @@ -81,12 +66,7 @@ fn quiet_and_verbose_config() { verbose = true "#, ) - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); assert_that(p.cargo("run").arg("-q"), execs().with_status(0)); @@ -115,12 +95,7 @@ fn simple_with_args() { #[test] fn exit_code() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { std::process::exit(2); } - "#, - ) + .file("src/main.rs", "fn main() { std::process::exit(2); }") .build(); let mut output = String::from( @@ -141,12 +116,7 @@ fn exit_code() { #[test] fn exit_code_verbose() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { std::process::exit(2); } - "#, - ) + .file("src/main.rs", "fn main() { std::process::exit(2); }") .build(); let mut output = String::from( @@ -389,18 +359,8 @@ consider adding `cargo-features = ["default-run"]` to the manifest fn run_example() { let p = project() .file("src/lib.rs", "") - .file( - "examples/a.rs", - r#" - fn main() { println!("example"); } - "#, - ) - .file( - "src/bin/a.rs", - r#" - fn main() { println!("bin"); } - "#, - ) + .file("examples/a.rs", r#"fn main() { println!("example"); }"#) + .file("src/bin/a.rs", r#"fn main() { println!("bin"); }"#) .build(); assert_that( @@ -434,12 +394,7 @@ fn run_library_example() { "#, ) .file("src/lib.rs", "") - .file( - "examples/bar.rs", - r#" - fn foo() {} - "#, - ) + .file("examples/bar.rs", "fn foo() {}") .build(); assert_that( @@ -480,12 +435,7 @@ fn autodiscover_examples_project(rust_edition: &str, autoexamples: Option) autoexamples = autoexamples ), ) - .file( - "examples/a.rs", - r#" - fn main() { println!("example"); } - "#, - ) + .file("examples/a.rs", r#"fn main() { println!("example"); }"#) .file( "examples/do_magic.rs", r#" @@ -602,18 +552,8 @@ fn run_example_autodiscover_2018() { fn run_bins() { let p = project() .file("src/lib.rs", "") - .file( - "examples/a.rs", - r#" - fn main() { println!("example"); } - "#, - ) - .file( - "src/bin/a.rs", - r#" - fn main() { println!("bin"); } - "#, - ) + .file("examples/a.rs", r#"fn main() { println!("example"); }"#) + .file("src/bin/a.rs", r#"fn main() { println!("bin"); }"#) .build(); assert_that( @@ -635,12 +575,7 @@ fn run_with_filename() { fn main() { println!("hello a.rs"); } "#, ) - .file( - "examples/a.rs", - r#" - fn main() { println!("example"); } - "#, - ) + .file("examples/a.rs", r#"fn main() { println!("example"); }"#) .build(); assert_that( @@ -681,18 +616,8 @@ Did you mean `a`?", #[test] fn either_name_or_example() { let p = project() - .file( - "src/bin/a.rs", - r#" - fn main() { println!("hello a.rs"); } - "#, - ) - .file( - "examples/b.rs", - r#" - fn main() { println!("hello b.rs"); } - "#, - ) + .file("src/bin/a.rs", r#"fn main() { println!("hello a.rs"); }"#) + .file("examples/b.rs", r#"fn main() { println!("hello b.rs"); }"#) .build(); assert_that( @@ -713,24 +638,9 @@ fn either_name_or_example() { fn one_bin_multiple_examples() { let p = project() .file("src/lib.rs", "") - .file( - "src/bin/main.rs", - r#" - fn main() { println!("hello main.rs"); } - "#, - ) - .file( - "examples/a.rs", - r#" - fn main() { println!("hello a.rs"); } - "#, - ) - .file( - "examples/b.rs", - r#" - fn main() { println!("hello b.rs"); } - "#, - ) + .file("src/bin/main.rs", r#"fn main() { println!("hello main.rs"); }"#) + .file("examples/a.rs", r#"fn main() { println!("hello a.rs"); }"#) + .file("examples/b.rs", r#"fn main() { println!("hello b.rs"); }"#) .build(); assert_that( @@ -779,18 +689,7 @@ fn example_with_release_flag() { } "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - name = "bar" - "#, - ) + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) .file( "bar/src/bar.rs", r#" @@ -815,7 +714,7 @@ fn example_with_release_flag() { .with_status(0) .with_stderr(&format!( "\ -[COMPILING] bar v0.0.1 ({url}/bar) +[COMPILING] bar v0.5.0 ({url}/bar) [RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \ --emit=dep-info,link \ -C opt-level=3 \ @@ -849,7 +748,7 @@ fast2", .with_status(0) .with_stderr(&format!( "\ -[COMPILING] bar v0.0.1 ({url}/bar) +[COMPILING] bar v0.5.0 ({url}/bar) [RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \ --emit=dep-info,link \ -C debuginfo=2 \ @@ -893,13 +792,7 @@ fn run_dylib_dep() { path = "bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { bar::bar(); } - "#, - ) + .file("src/main.rs", r#"extern crate bar; fn main() { bar::bar(); }"#) .file( "bar/Cargo.toml", r#" @@ -962,12 +855,7 @@ fn run_bin_different_name() { name = "bar" "#, ) - .file( - "src/bar.rs", - r#" - fn main() { } - "#, - ) + .file("src/bar.rs", "fn main() {}") .build(); assert_that(p.cargo("run"), execs().with_status(0)); @@ -999,12 +887,7 @@ fn dashes_are_forwarded() { #[test] fn run_from_executable_folder() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { println!("hello"); } - "#, - ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); let cwd = p.root().join("target").join("debug"); @@ -1139,14 +1022,7 @@ fn library_paths_sorted_alphabetically() { #[test] fn fail_no_extra_verbose() { let p = project() - .file( - "src/main.rs", - r#" - fn main() { - std::process::exit(1); - } - "#, - ) + .file("src/main.rs", "fn main() { std::process::exit(1); }") .build(); assert_that( @@ -1179,42 +1055,12 @@ fn run_multiple_packages() { "#, ) .file("foo/src/foo.rs", "fn main() { println!(\"foo\"); }") - .file( - "foo/d1/Cargo.toml", - r#" - [package] - name = "d1" - version = "0.0.1" - authors = [] - - [[bin]] - name = "d1" - "#, - ) + .file("foo/d1/Cargo.toml", &basic_bin_manifest("d1")) .file("foo/d1/src/lib.rs", "") .file("foo/d1/src/main.rs", "fn main() { println!(\"d1\"); }") - .file( - "foo/d2/Cargo.toml", - r#" - [package] - name = "d2" - version = "0.0.1" - authors = [] - - [[bin]] - name = "d2" - "#, - ) + .file("foo/d2/Cargo.toml", &basic_bin_manifest("d2")) .file("foo/d2/src/main.rs", "fn main() { println!(\"d2\"); }") - .file( - "d3/Cargo.toml", - r#" - [package] - name = "d3" - version = "0.0.1" - authors = [] - "#, - ) + .file("d3/Cargo.toml", &basic_bin_manifest("d3")) .file("d3/src/main.rs", "fn main() { println!(\"d2\"); }") .build(); diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index 4cd322ac718..d5406d4d748 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -1,4 +1,4 @@ -use support::{basic_bin_manifest, basic_lib_manifest, execs, project}; +use support::{basic_manifest, basic_bin_manifest, basic_lib_manifest, execs, project}; use support::hamcrest::assert_that; const CARGO_RUSTC_ERROR: &'static str = @@ -8,12 +8,7 @@ the package by passing e.g. `--lib` or `--bin NAME` to specify a single target"; #[test] fn build_lib_for_foo() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -38,12 +33,7 @@ fn build_lib_for_foo() { #[test] fn lib() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -74,12 +64,7 @@ fn lib() { #[test] fn build_main_and_allow_unstable_options() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -113,12 +98,7 @@ fn build_main_and_allow_unstable_options() { #[test] fn fails_when_trying_to_build_main_and_lib_with_args() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -135,24 +115,9 @@ fn fails_when_trying_to_build_main_and_lib_with_args() { #[test] fn build_with_args_to_one_of_multiple_binaries() { let p = project() - .file( - "src/bin/foo.rs", - r#" - fn main() {} - "#, - ) - .file( - "src/bin/bar.rs", - r#" - fn main() {} - "#, - ) - .file( - "src/bin/baz.rs", - r#" - fn main() {} - "#, - ) + .file("src/bin/foo.rs", "fn main() {}") + .file("src/bin/bar.rs", "fn main() {}") + .file("src/bin/baz.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -176,24 +141,9 @@ fn build_with_args_to_one_of_multiple_binaries() { #[test] fn fails_with_args_to_all_binaries() { let p = project() - .file( - "src/bin/foo.rs", - r#" - fn main() {} - "#, - ) - .file( - "src/bin/bar.rs", - r#" - fn main() {} - "#, - ) - .file( - "src/bin/baz.rs", - r#" - fn main() {} - "#, - ) + .file("src/bin/foo.rs", "fn main() {}") + .file("src/bin/bar.rs", "fn main() {}") + .file("src/bin/baz.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); @@ -248,32 +198,11 @@ fn build_foo_with_bar_dependency() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - bar::baz() - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::baz() }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -310,32 +239,11 @@ fn build_only_bar_dependency() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - bar::baz() - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::baz() }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -414,24 +322,11 @@ fn fail_with_multiple_packages() { path = "../baz" "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) .file( "src/main.rs", r#" @@ -443,15 +338,7 @@ fn fail_with_multiple_packages() { .build(); let _baz = project().at("baz") - .file( - "Cargo.toml", - r#" - [package] - name = "baz" - version = "0.1.0" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("baz", "0.1.0")) .file( "src/main.rs", r#" @@ -497,15 +384,7 @@ fn rustc_with_other_profile() { fn foo() {} "#, ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) .file("a/src/lib.rs", "") .build(); diff --git a/tests/testsuite/rustc_info_cache.rs b/tests/testsuite/rustc_info_cache.rs index 4aa3378caff..f2a099d0519 100644 --- a/tests/testsuite/rustc_info_cache.rs +++ b/tests/testsuite/rustc_info_cache.rs @@ -1,4 +1,4 @@ -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::paths::CargoPathExt; use support::hamcrest::assert_that; use std::env; @@ -45,14 +45,7 @@ fn rustc_info_cache() { let other_rustc = { let p = project().at("compiler") - .file( - "Cargo.toml", - r#" - [package] - name = "compiler" - version = "0.1.0" - "#, - ) + .file("Cargo.toml", &basic_manifest("compiler", "0.1.0")) .file( "src/main.rs", r#" diff --git a/tests/testsuite/rustdoc.rs b/tests/testsuite/rustdoc.rs index 93132e642ac..8678496e624 100644 --- a/tests/testsuite/rustdoc.rs +++ b/tests/testsuite/rustdoc.rs @@ -1,10 +1,10 @@ -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::hamcrest::assert_that; #[test] fn rustdoc_simple() { let p = project() - .file("src/lib.rs", r#" "#) + .file("src/lib.rs", "") .build(); assert_that( @@ -26,7 +26,7 @@ fn rustdoc_simple() { #[test] fn rustdoc_args() { let p = project() - .file("src/lib.rs", r#" "#) + .file("src/lib.rs", "") .build(); assert_that( @@ -61,30 +61,11 @@ fn rustdoc_foo_with_bar_dependency() { path = "../bar" "#, ) - .file( - "src/lib.rs", - r#" - extern crate bar; - pub fn foo() {} - "#, - ) + .file("src/lib.rs", "extern crate bar; pub fn foo() {}") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -122,32 +103,11 @@ fn rustdoc_only_bar_dependency() { path = "../bar" "#, ) - .file( - "src/main.rs", - r#" - extern crate bar; - fn main() { - bar::baz() - } - "#, - ) + .file("src/main.rs", "extern crate bar; fn main() { bar::baz() }") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/lib.rs", - r#" - pub fn baz() {} - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -174,12 +134,7 @@ fn rustdoc_only_bar_dependency() { #[test] fn rustdoc_same_name_documents_lib() { let p = project() - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) + .file("src/main.rs", "fn main() {}") .file("src/lib.rs", r#" "#) .build(); diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index 3a28dcfea5a..825ba3e4a18 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -2,7 +2,7 @@ use std::io::Write; use std::fs::{self, File}; use support::rustc_host; -use support::{basic_lib_manifest, execs, paths, project, project_in_home}; +use support::{basic_manifest, basic_lib_manifest, execs, paths, project, project_in_home}; use support::hamcrest::assert_that; #[test] @@ -97,22 +97,10 @@ fn env_rustflags_build_script_dep() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() { } - "#, - ) + .file("build.rs", "fn main() {}") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) .file( "src/lib.rs", r#" @@ -184,12 +172,7 @@ fn env_rustflags_plugin_dep() { path = "../bar" "#, ) - .file( - "src/lib.rs", - r#" - fn foo() { } - "#, - ) + .file("src/lib.rs", "fn foo() {}") .build(); let _bar = project().at("bar") .file("Cargo.toml", &basic_lib_manifest("bar")) @@ -323,22 +306,10 @@ fn env_rustflags_build_script_dep_with_target() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() { } - "#, - ) + .file("build.rs", "fn main() {}") .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) .file( "src/lib.rs", r#" @@ -418,12 +389,7 @@ fn env_rustflags_plugin_dep_with_target() { path = "../bar" "#, ) - .file( - "src/lib.rs", - r#" - fn foo() { } - "#, - ) + .file("src/lib.rs", "fn foo() {}") .build(); let _bar = project().at("bar") .file("Cargo.toml", &basic_lib_manifest("bar")) @@ -582,12 +548,7 @@ fn build_rustflags_build_script_dep() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() { } - "#, - ) + .file("build.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -597,14 +558,7 @@ fn build_rustflags_build_script_dep() { ) .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) .file( "src/lib.rs", r#" @@ -677,12 +631,7 @@ fn build_rustflags_plugin_dep() { path = "../bar" "#, ) - .file( - "src/lib.rs", - r#" - fn foo() { } - "#, - ) + .file("src/lib.rs", "fn foo() {}") .file( ".cargo/config", r#" @@ -816,12 +765,7 @@ fn build_rustflags_build_script_dep_with_target() { "#, ) .file("src/lib.rs", "") - .file( - "build.rs", - r#" - fn main() { } - "#, - ) + .file("build.rs", "fn main() {}") .file( ".cargo/config", r#" @@ -831,14 +775,7 @@ fn build_rustflags_build_script_dep_with_target() { ) .build(); let _bar = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - "#, - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) .file( "src/lib.rs", r#" @@ -919,12 +856,7 @@ fn build_rustflags_plugin_dep_with_target() { path = "../bar" "#, ) - .file( - "src/lib.rs", - r#" - fn foo() { } - "#, - ) + .file("src/lib.rs", "fn foo() {}") .file( ".cargo/config", r#" diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 13e1373f103..0a295eaccac 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -67,16 +67,7 @@ fn setup() { // Init a new registry let _ = repo(®istry_path()) - .file( - "config.json", - &format!( - r#"{{ - "dl": "{0}", - "api": "{0}" - }}"#, - api() - ), - ) + .file("config.json", &format!(r#"{{"dl":"{0}","api":"{0}"}}"#, api())) .build(); let base = api_path().join("api/v1/crates"); diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index 88af98e3a6c..20e105012a7 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -118,13 +118,6 @@ pub mod paths; pub mod publish; pub mod registry; -pub const BASIC_MANIFEST: &str = r#" -[package] -name = "foo" -version = "0.0.1" -authors = [] -"#; - /* * * ===== Builders ===== @@ -265,7 +258,7 @@ impl ProjectBuilder { let manifest_path = self.root.root().join("Cargo.toml"); if !self.no_manifest && self.files.iter().all(|fb| fb.path != manifest_path) { - self._file(Path::new("Cargo.toml"), BASIC_MANIFEST) + self._file(Path::new("Cargo.toml"), &basic_manifest("foo", "0.0.1")) } for file in self.files.iter() { @@ -1231,6 +1224,18 @@ impl Tap for T { } } +pub fn basic_manifest(name: &str, version: &str) -> String { + format!( + r#" + [package] + name = "{}" + version = "{}" + authors = [] + "#, + name, version + ) +} + pub fn basic_bin_manifest(name: &str) -> String { format!( r#" diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 60a0b96bdf8..cf3c62095d8 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -6,7 +6,7 @@ use cargo; use cargo::util::process; use support::paths::CargoPathExt; use support::registry::Package; -use support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project}; +use support::{basic_manifest, basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project}; use support::{is_nightly, rustc_host, sleep_ms}; use support::hamcrest::{assert_that, existing_file, is_not}; @@ -89,15 +89,7 @@ fn cargo_test_release() { fn test() { foo::foo(); } "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "pub fn bar() {}") .build(); @@ -312,21 +304,8 @@ failures: fn cargo_test_failing_test_in_test() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file( - "src/main.rs", - r#" - pub fn main() { - println!("hello"); - }"#, - ) - .file( - "tests/footest.rs", - r#" - #[test] - fn test_hello() { - assert!(false) - }"#, - ) + .file("src/main.rs", r#"pub fn main() { println!("hello"); }"#) + .file("tests/footest.rs", "#[test] fn test_hello() { assert!(false) }") .build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -359,7 +338,7 @@ failures: ---- test_hello stdout ---- [..]thread 'test_hello' panicked at 'assertion failed: false', \ - tests[/]footest.rs:4[..] + tests[/]footest.rs:1[..] ", ) .with_stdout_contains( @@ -376,14 +355,7 @@ failures: fn cargo_test_failing_test_in_lib() { let p = project() .file("Cargo.toml", &basic_lib_manifest("foo")) - .file( - "src/lib.rs", - r#" - #[test] - fn test_hello() { - assert!(false) - }"#, - ) + .file("src/lib.rs", "#[test] fn test_hello() { assert!(false) }") .build(); assert_that( @@ -405,7 +377,7 @@ failures: ---- test_hello stdout ---- [..]thread 'test_hello' panicked at 'assertion failed: false', \ - src[/]lib.rs:4[..] + src[/]lib.rs:1[..] ", ) .with_stdout_contains( @@ -515,24 +487,8 @@ fn test_with_deep_lib_dep() { ) .build(); let _p2 = project().at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) - .file( - "src/lib.rs", - " - pub fn bar() {} - - #[test] - fn foo_test() {} - ", - ) + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", "pub fn bar() {} #[test] fn foo_test() {}") .build(); assert_that( @@ -624,13 +580,7 @@ fn external_test_named_test() { "#, ) .file("src/lib.rs", "") - .file( - "tests/test.rs", - r#" - #[test] - fn foo() { } - "#, - ) + .file("tests/test.rs", "#[test] fn foo() {}") .build(); assert_that(p.cargo("test"), execs().with_status(0)) @@ -681,11 +631,7 @@ fn external_test_implicit() { #[test] fn dont_run_examples() { let p = project() - .file( - "src/lib.rs", - r#" - "#, - ) + .file("src/lib.rs", "") .file( "examples/dont-run-me-i-will-fail.rs", r#" @@ -780,12 +726,7 @@ fn lib_bin_same_name() { name = "foo" "#, ) - .file( - "src/lib.rs", - " - #[test] fn lib_test() {} - ", - ) + .file("src/lib.rs", "#[test] fn lib_test() {}") .file( "src/main.rs", " @@ -819,15 +760,7 @@ fn lib_bin_same_name() { #[test] fn lib_with_standard_name() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "syntax" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("syntax", "0.0.1")) .file( "src/lib.rs", " @@ -887,12 +820,7 @@ fn lib_with_standard_name2() { doctest = false "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/main.rs", " @@ -937,12 +865,7 @@ fn lib_without_name() { doctest = false "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/main.rs", " @@ -990,12 +913,7 @@ fn bin_without_name() { path = "src/main.rs" "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/main.rs", " @@ -1040,12 +958,7 @@ fn bench_without_name() { path = "src/bench.rs" "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/main.rs", " @@ -1161,12 +1074,7 @@ fn example_without_name() { path = "examples/example.rs" "#, ) - .file( - "src/lib.rs", - " - pub fn foo() {} - ", - ) + .file("src/lib.rs", "pub fn foo() {}") .file( "src/main.rs", " @@ -1291,12 +1199,7 @@ fn test_dylib() { crate_type = ["dylib"] "#, ) - .file( - "bar/src/lib.rs", - " - pub fn baz() {} - ", - ) + .file("bar/src/lib.rs", "pub fn baz() {}") .build(); assert_that( @@ -1344,13 +1247,7 @@ fn test_twice_with_build_cmd() { "#, ) .file("build.rs", "fn main() {}") - .file( - "src/lib.rs", - " - #[test] - fn foo() {} - ", - ) + .file("src/lib.rs", "#[test] fn foo() {}") .build(); assert_that( @@ -1387,13 +1284,7 @@ fn test_twice_with_build_cmd() { #[test] fn test_then_build() { let p = project() - .file( - "src/lib.rs", - " - #[test] - fn foo() {} - ", - ) + .file("src/lib.rs", "#[test] fn foo() {}") .build(); assert_that( @@ -1418,13 +1309,7 @@ fn test_then_build() { #[test] fn test_no_run() { let p = project() - .file( - "src/lib.rs", - " - #[test] - fn foo() { panic!() } - ", - ) + .file("src/lib.rs", "#[test] fn foo() { panic!() }") .build(); assert_that( @@ -1915,15 +1800,7 @@ fn almost_cyclic_but_not_quite() { extern crate foo; "#, ) - .file( - "c/Cargo.toml", - r#" - [package] - name = "c" - version = "0.0.1" - authors = [] - "#, - ) + .file("c/Cargo.toml", &basic_manifest("c", "0.0.1")) .file("c/src/lib.rs", "") .build(); @@ -1946,10 +1823,7 @@ fn build_then_selective_test() { path = "b" "#, ) - .file( - "src/lib.rs", - "#[allow(unused_extern_crates)] extern crate b;", - ) + .file("src/lib.rs", "#[allow(unused_extern_crates)] extern crate b;") .file( "src/main.rs", r#" @@ -1960,15 +1834,7 @@ fn build_then_selective_test() { fn main() {} "#, ) - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); @@ -1992,27 +1858,9 @@ fn example_dev_dep() { path = "bar" "#, ) - .file( - "src/lib.rs", - r#" - "#, - ) - .file( - "examples/e1.rs", - r#" - extern crate bar; - fn main() { } - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("src/lib.rs", "") + .file("examples/e1.rs", "extern crate bar; fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file( "bar/src/lib.rs", r#" @@ -2182,15 +2030,7 @@ fn example_with_dev_dep() { "examples/ex.rs", "#[allow(unused_extern_crates)] extern crate a; fn main() {}", ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -2289,15 +2129,7 @@ fn doctest_feature() { #[test] fn dashes_to_underscores() { let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo-bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("Cargo.toml", &basic_manifest("foo-bar", "0.0.1")) .file( "src/lib.rs", r#" @@ -2336,15 +2168,7 @@ fn doctest_dev_dep() { pub fn foo() {} "#, ) - .file( - "b/Cargo.toml", - r#" - [package] - name = "b" - version = "0.0.1" - authors = [] - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.0.1")) .file("b/src/lib.rs", "") .build(); @@ -2729,15 +2553,7 @@ fn selective_test_wonky_profile() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", ""); let p = p.build(); @@ -2763,15 +2579,7 @@ fn selective_test_optional_dep() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", ""); let p = p.build(); @@ -2857,15 +2665,7 @@ fn test_panic_abort_with_dep() { fn foo() {} "#, ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) .file("bar/src/lib.rs", "") .build(); assert_that(p.cargo("test").arg("-v"), execs().with_status(0)); @@ -2887,15 +2687,7 @@ fn cfg_test_even_with_no_harness() { doctest = false "#, ) - .file( - "src/lib.rs", - r#" - #[cfg(test)] - fn main() { - println!("hello!"); - } - "#, - ) + .file("src/lib.rs", r#"#[cfg(test)] fn main() { println!("hello!"); }"#) .build(); assert_that( p.cargo("test").arg("-v"), @@ -2932,15 +2724,7 @@ fn panic_abort_multiple() { "src/lib.rs", "#[allow(unused_extern_crates)] extern crate a;", ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); assert_that( @@ -3014,25 +2798,9 @@ fn pass_correct_cfgs_flags_to_rustdoc() { } "#, ) - .file( - "libs/mock_serde_derive/Cargo.toml", - r#" - [package] - name = "mock_serde_derive" - version = "0.1.0" - authors = [] - "#, - ) + .file("libs/mock_serde_derive/Cargo.toml", &basic_manifest("mock_serde_derive", "0.1.0")) .file("libs/mock_serde_derive/src/lib.rs", "") - .file( - "libs/mock_serde_codegen/Cargo.toml", - r#" - [package] - name = "mock_serde_codegen" - version = "0.1.0" - authors = [] - "#, - ) + .file("libs/mock_serde_codegen/Cargo.toml", &basic_manifest("mock_serde_codegen", "0.1.0")) .file("libs/mock_serde_codegen/src/lib.rs", ""); let p = p.build(); @@ -3082,15 +2850,7 @@ fn test_release_ignore_panic() { "src/lib.rs", "#[allow(unused_extern_crates)] extern crate a;", ) - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", ""); let p = p.build(); println!("test"); @@ -3120,15 +2880,7 @@ fn test_many_with_features() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); @@ -3154,28 +2906,9 @@ fn test_all_workspace() { [workspace] "#, ) - .file( - "src/main.rs", - r#" - #[test] - fn foo_test() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - #[test] - fn bar_test() {} - "#, - ) + .file("src/main.rs", "#[test] fn foo_test() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "#[test] fn bar_test() {}") .build(); assert_that( @@ -3201,44 +2934,11 @@ fn test_all_exclude() { members = ["bar", "baz"] "#, ) - .file( - "src/main.rs", - r#" - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - "#, - ) - .file( - "bar/src/lib.rs", - r#" - #[test] - pub fn bar() {} - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - "#, - ) - .file( - "baz/src/lib.rs", - r#" - #[test] - pub fn baz() { - assert!(false); - } - "#, - ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "#[test] pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "#[test] pub fn baz() { assert!(false); }") .build(); assert_that( @@ -3260,36 +2960,10 @@ fn test_all_virtual_manifest() { members = ["a", "b"] "#, ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.1.0" - "#, - ) - .file( - "a/src/lib.rs", - r#" - #[test] - fn a() {} - "#, - ) - .file( - "b/Cargo.toml", - r#" - [project] - name = "b" - version = "0.1.0" - "#, - ) - .file( - "b/src/lib.rs", - r#" - #[test] - fn b() {} - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) + .file("a/src/lib.rs", "#[test] fn a() {}") + .file("b/Cargo.toml", &basic_manifest("b", "0.1.0")) + .file("b/src/lib.rs", "#[test] fn b() {}") .build(); assert_that( @@ -3311,36 +2985,10 @@ fn test_virtual_manifest_all_implied() { members = ["a", "b"] "#, ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.1.0" - "#, - ) - .file( - "a/src/lib.rs", - r#" - #[test] - fn a() {} - "#, - ) - .file( - "b/Cargo.toml", - r#" - [project] - name = "b" - version = "0.1.0" - "#, - ) - .file( - "b/src/lib.rs", - r#" - #[test] - fn b() {} - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) + .file("a/src/lib.rs", "#[test] fn a() {}") + .file("b/Cargo.toml", &basic_manifest("b", "0.1.0")) + .file("b/src/lib.rs", "#[test] fn b() {}") .build(); assert_that( @@ -3373,13 +3021,7 @@ fn test_all_member_dependency_same_name() { a = "0.1.0" "#, ) - .file( - "a/src/lib.rs", - r#" - #[test] - fn a() {} - "#, - ) + .file("a/src/lib.rs", "#[test] fn a() {}") .build(); Package::new("a", "0.1.0").publish(); @@ -3415,20 +3057,8 @@ fn doctest_only_with_dev_dep() { pub fn a() {} "#, ) - .file( - "b/Cargo.toml", - r#" - [project] - name = "b" - version = "0.1.0" - "#, - ) - .file( - "b/src/lib.rs", - r#" - pub fn b() {} - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.1.0")) + .file("b/src/lib.rs", "pub fn b() {}") .build(); assert_that( @@ -3475,30 +3105,10 @@ fn test_many_targets() { #[test] fn example_b() {} "#, ) - .file( - "examples/c.rs", - r#" - #[test] fn example_c() { panic!(); } - "#, - ) - .file( - "tests/a.rs", - r#" - #[test] fn test_a() {} - "#, - ) - .file( - "tests/b.rs", - r#" - #[test] fn test_b() {} - "#, - ) - .file( - "tests/c.rs", - r#" - does not compile - "#, - ) + .file("examples/c.rs", "#[test] fn example_c() { panic!(); }") + .file("tests/a.rs", "#[test] fn test_a() {}") + .file("tests/b.rs", "#[test] fn test_b() {}") + .file("tests/c.rs", "does not compile") .build(); assert_that( @@ -3545,14 +3155,7 @@ fn doctest_and_registry() { "#, ) .file("src/lib.rs", "") - .file( - "b/Cargo.toml", - r#" - [project] - name = "b" - version = "0.1.0" - "#, - ) + .file("b/Cargo.toml", &basic_manifest("b", "0.1.0")) .file( "b/src/lib.rs", " @@ -3621,24 +3224,9 @@ test env_test ... ok #[test] fn test_order() { let p = project() - .file( - "src/lib.rs", - r#" - #[test] fn test_lib() {} - "#, - ) - .file( - "tests/a.rs", - r#" - #[test] fn test_a() {} - "#, - ) - .file( - "tests/z.rs", - r#" - #[test] fn test_z() {} - "#, - ) + .file("src/lib.rs", "#[test] fn test_lib() {}") + .file("tests/a.rs", "#[test] fn test_a() {}") + .file("tests/z.rs", "#[test] fn test_z() {}") .build(); assert_that( @@ -3680,18 +3268,8 @@ fn cyclic_dev() { foo = { path = "." } "#, ) - .file( - "src/lib.rs", - r#" - #[test] fn test_lib() {} - "#, - ) - .file( - "tests/foo.rs", - r#" - extern crate foo; - "#, - ) + .file("src/lib.rs", "#[test] fn test_lib() {}") + .file("tests/foo.rs", "extern crate foo;") .build(); assert_that(p.cargo("test").arg("--all"), execs().with_status(0)); @@ -3862,36 +3440,10 @@ fn test_hint_workspace() { members = ["a", "b"] "#, ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.1.0" - "#, - ) - .file( - "a/src/lib.rs", - r#" - #[test] - fn t1() {} - "#, - ) - .file( - "b/Cargo.toml", - r#" - [project] - name = "b" - version = "0.1.0" - "#, - ) - .file( - "b/src/lib.rs", - r#" - #[test] - fn t1() {assert!(false)} - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) + .file("a/src/lib.rs", "#[test] fn t1() {}") + .file("b/Cargo.toml", &basic_manifest("b", "0.1.0")) + .file("b/src/lib.rs", "#[test] fn t1() {assert!(false)}") .build(); assert_that( diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index 761f3b07e75..9250307f1d9 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -106,18 +106,7 @@ fn relative_tools() { // by reference to the `.cargo/..` directory and not to (for example) the CWD. let p = project() .no_manifest() - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - name = "bar" - "#, - ) + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) .file("bar/src/lib.rs", "") .file( ".cargo/config", @@ -153,7 +142,7 @@ fn relative_tools() { p.cargo("build").cwd(foo_path).arg("--verbose"), execs().with_stderr(&format!( "\ -[COMPILING] bar v0.0.1 ({url}) +[COMPILING] bar v0.5.0 ({url}) [RUNNING] `rustc [..] -C ar={ar} -C linker={linker} [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 03918e359b8..e323fc4ff87 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::io::prelude::*; -use support::{execs, project}; +use support::{basic_manifest, execs, project}; use support::registry::Package; use support::hamcrest::assert_that; @@ -331,15 +331,7 @@ fn change_package_version() { "#, ) .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.2.0-alpha" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0-alpha")) .file("bar/src/lib.rs", "") .file( "Cargo.lock", diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 05b112d202e..0439c581197 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -3,7 +3,7 @@ use std::fs::{self, File}; use std::io::{Read, Write}; use support::sleep_ms; -use support::{basic_lib_manifest, execs, git, project}; +use support::{basic_manifest, basic_lib_manifest, execs, git, project}; use support::registry::Package; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; @@ -102,15 +102,7 @@ fn inferred_root() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); @@ -147,15 +139,7 @@ fn inferred_path_dep() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}") .file("bar/src/lib.rs", ""); let p = p.build(); @@ -207,15 +191,7 @@ fn transitive_path_dep() { ) .file("bar/src/main.rs", "fn main() {}") .file("bar/src/lib.rs", "") - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - authors = [] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) .file("baz/src/main.rs", "fn main() {}") .file("baz/src/lib.rs", ""); let p = p.build(); @@ -346,15 +322,7 @@ fn parent_doesnt_point_to_child() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); @@ -509,15 +477,7 @@ fn workspace_isnt_root() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); @@ -788,15 +748,7 @@ fn virtual_works() { members = ["bar"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); assert_that( @@ -818,15 +770,7 @@ fn explicit_package_argument_works_with_virtual_manifest() { members = ["bar"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); assert_that( @@ -847,15 +791,7 @@ fn virtual_misconfigure() { [workspace] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); assert_that( @@ -883,15 +819,7 @@ fn virtual_build_all_implied() { members = ["bar"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -908,24 +836,8 @@ fn virtual_default_members() { default-members = ["bar"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) .file("bar/src/main.rs", "fn main() {}") .file("baz/src/main.rs", "fn main() {}"); let p = p.build(); @@ -945,15 +857,7 @@ fn virtual_default_member_is_not_a_member() { default-members = ["something-else"] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); assert_that( @@ -1053,25 +957,9 @@ fn members_include_path_deps() { "#, ) .file("p1/src/lib.rs", "") - .file( - "p2/Cargo.toml", - r#" - [project] - name = "p2" - version = "0.1.0" - authors = [] - "#, - ) + .file("p2/Cargo.toml", &basic_manifest("p2", "0.1.0")) .file("p2/src/lib.rs", "") - .file( - "p3/Cargo.toml", - r#" - [project] - name = "p3" - version = "0.1.0" - authors = [] - "#, - ) + .file("p3/Cargo.toml", &basic_manifest("p3", "0.1.0")) .file("p3/src/lib.rs", ""); let p = p.build(); @@ -1194,14 +1082,7 @@ fn rebuild_please() { members = ['lib', 'bin'] "#, ) - .file( - "lib/Cargo.toml", - r#" - [package] - name = "lib" - version = "0.1.0" - "#, - ) + .file("lib/Cargo.toml", &basic_manifest("lib", "0.1.0")) .file( "lib/src/lib.rs", r#" @@ -1238,11 +1119,9 @@ fn rebuild_please() { sleep_ms(1000); - t!(t!(File::create(p.root().join("lib/src/lib.rs"))).write_all( - br#" - pub fn foo() -> u32 { 1 } - "# - )); + t!(t!(File::create(p.root().join("lib/src/lib.rs"))) + .write_all(br#"pub fn foo() -> u32 { 1 }"#) + ); assert_that( p.cargo("build").cwd(p.root().join("lib")), @@ -1266,14 +1145,7 @@ fn workspace_in_git() { members = ["foo"] "#, ) - .file( - "foo/Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "") }).unwrap(); let p = project() @@ -1312,15 +1184,7 @@ fn lockfile_can_specify_nonexistant_members() { members = ["a"] "#, ) - .file( - "a/Cargo.toml", - r#" - [project] - name = "a" - version = "0.1.0" - authors = [] - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) .file("a/src/main.rs", "fn main() {}") .file( "Cargo.lock", @@ -1352,15 +1216,7 @@ fn you_cannot_generate_lockfile_for_empty_workspaces() { [workspace] "#, ) - .file( - "bar/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); @@ -1416,15 +1272,7 @@ fn workspace_with_transitive_dev_deps() { } "#, ) - .file( - "baz/Cargo.toml", - r#" - [project] - name = "baz" - version = "0.5.0" - authors = ["mbrubeck@example.com"] - "#, - ) + .file("baz/Cargo.toml", &basic_manifest("baz", "0.5.0")) .file("baz/src/lib.rs", r#"pub fn do_stuff() {}"#); let p = p.build(); @@ -1435,15 +1283,7 @@ fn workspace_with_transitive_dev_deps() { fn error_if_parent_cargo_toml_is_invalid() { let p = project() .file("Cargo.toml", "Totally not a TOML file") - .file( - "bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); @@ -1512,15 +1352,7 @@ fn relative_path_for_root_works() { "#, ) .file("src/main.rs", "fn main() {}") - .file( - "subproj/Cargo.toml", - r#" - [project] - name = "subproj" - version = "0.1.0" - authors = [] - "#, - ) + .file("subproj/Cargo.toml", &basic_manifest("subproj", "0.1.0")) .file("subproj/src/main.rs", "fn main() {}"); let p = p.build(); @@ -1560,15 +1392,7 @@ fn path_dep_outside_workspace_is_not_member() { "#, ) .file("ws/src/lib.rs", r"extern crate foo;") - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", ""); let p = p.build(); @@ -1597,10 +1421,7 @@ fn test_in_and_out_of_workspace() { members = [ "../bar" ] "#, ) - .file( - "ws/src/lib.rs", - r"extern crate foo; pub fn f() { foo::f() }", - ) + .file("ws/src/lib.rs", r"extern crate foo; pub fn f() { foo::f() }") .file( "foo/Cargo.toml", r#" @@ -1613,10 +1434,7 @@ fn test_in_and_out_of_workspace() { bar = { path = "../bar" } "#, ) - .file( - "foo/src/lib.rs", - "extern crate bar; pub fn f() { bar::f() }", - ) + .file("foo/src/lib.rs", "extern crate bar; pub fn f() { bar::f() }") .file( "bar/Cargo.toml", r#" @@ -1669,10 +1487,7 @@ fn test_path_dependency_under_member() { [workspace] "#, ) - .file( - "ws/src/lib.rs", - r"extern crate foo; pub fn f() { foo::f() }", - ) + .file("ws/src/lib.rs", r"extern crate foo; pub fn f() { foo::f() }") .file( "foo/Cargo.toml", r#" @@ -1686,19 +1501,8 @@ fn test_path_dependency_under_member() { bar = { path = "./bar" } "#, ) - .file( - "foo/src/lib.rs", - "extern crate bar; pub fn f() { bar::f() }", - ) - .file( - "foo/bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/src/lib.rs", "extern crate bar; pub fn f() { bar::f() }") + .file("foo/bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("foo/bar/src/lib.rs", "pub fn f() { }"); let p = p.build(); @@ -1741,15 +1545,7 @@ fn excluded_simple() { "#, ) .file("src/lib.rs", "") - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", ""); let p = p.build(); @@ -1779,25 +1575,9 @@ fn exclude_members_preferred() { "#, ) .file("src/lib.rs", "") - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "") - .file( - "foo/bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("foo/bar/src/lib.rs", ""); let p = p.build(); @@ -1834,25 +1614,9 @@ fn exclude_but_also_depend() { "#, ) .file("src/lib.rs", "") - .file( - "foo/Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "") - .file( - "foo/bar/Cargo.toml", - r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#, - ) + .file("foo/bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("foo/bar/src/lib.rs", ""); let p = p.build(); @@ -2159,14 +1923,7 @@ fn dep_used_with_separate_features() { fn dont_recurse_out_of_cargo_home() { let git_project = git::new("dep", |project| { project - .file( - "Cargo.toml", - r#" - [package] - name = "dep" - version = "0.1.0" - "#, - ) + .file("Cargo.toml", &basic_manifest("dep", "0.1.0")) .file("src/lib.rs", "") .file( "build.rs", @@ -2226,19 +1983,9 @@ fn include_and_exclude() { members = ["foo"] exclude = ["foo/bar"] "#) - .file("foo/Cargo.toml", r#" - [project] - name = "foo" - version = "0.1.0" - authors = [] - "#) + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("foo/src/lib.rs", "") - .file("foo/bar/Cargo.toml", r#" - [project] - name = "bar" - version = "0.1.0" - authors = [] - "#) + .file("foo/bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) .file("foo/bar/src/lib.rs", ""); p.build(); @@ -2267,14 +2014,7 @@ fn cargo_home_at_root_works() { "#, ) .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.1.0" - "#, - ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) .file("a/src/lib.rs", ""); let p = p.build();