Skip to content

Make freshness/rebuilding tests more robust #5953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use support::is_nightly;
use support::paths::CargoPathExt;
use support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};

#[test]
Expand All @@ -13,22 +12,23 @@ fn cargo_bench_simple() {
.file(
"src/main.rs",
r#"
#![feature(test)]
#[cfg(test)]
extern crate test;

fn hello() -> &'static str {
"hello"
}

pub fn main() {
println!("{}", hello())
}

#[bench]
fn bench_hello(_b: &mut test::Bencher) {
assert_eq!(hello(), "hello")
}"#,
#![feature(test)]
#[cfg(test)]
extern crate test;

fn hello() -> &'static str {
"hello"
}

pub fn main() {
println!("{}", hello())
}

#[bench]
fn bench_hello(_b: &mut test::Bencher) {
assert_eq!(hello(), "hello")
}
"#,
).build();

p.cargo("build").run();
Expand All @@ -42,7 +42,8 @@ fn cargo_bench_simple() {
[COMPILING] foo v0.5.0 (CWD)
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
).with_stdout_contains("test bench_hello ... bench: [..]")
)
.with_stdout_contains("test bench_hello ... bench: [..]")
.run();
}

Expand Down Expand Up @@ -844,7 +845,7 @@ fn bench_dylib() {
return;
}

let p = project()
let mut p = project()
.file(
"Cargo.toml",
r#"
Expand Down Expand Up @@ -913,7 +914,7 @@ fn bench_dylib() {
).with_stdout_contains_n("test foo ... bench: [..]", 2)
.run();

p.root().move_into_the_past();
p.write_file("foo", "bar");
p.cargo("bench -v")
.with_stderr(
"\
Expand Down
27 changes: 13 additions & 14 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::env;
use std::fs::{self, File};
use std::io::prelude::*;
use std::thread;
use std::time::Duration;

use cargo::util::paths::dylib_path_envvar;
use support::paths::{root, CargoPathExt};
use support::registry::Package;
use support::ProjectBuilder;
use support::{
basic_bin_manifest, basic_lib_manifest, basic_manifest, is_nightly, rustc_host, sleep_ms,
basic_bin_manifest, basic_lib_manifest, basic_manifest, is_nightly, rustc_host,
};
use support::{main_file, project, Execs};

Expand Down Expand Up @@ -1986,7 +1988,7 @@ fn inferred_main_bin() {

#[test]
fn deletion_causes_failure() {
let p = project()
let mut p = project()
.file(
"Cargo.toml",
r#"
Expand All @@ -2004,7 +2006,7 @@ fn deletion_causes_failure() {
.build();

p.cargo("build").run();
p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1"));
p.write_file("Cargo.toml", &basic_manifest("foo", "0.0.1"));
p.cargo("build").with_status(101).run();
}

Expand Down Expand Up @@ -2123,7 +2125,7 @@ fn single_lib() {

#[test]
fn freshness_ignores_excluded() {
let foo = project()
let mut foo = project()
.file(
"Cargo.toml",
r#"
Expand All @@ -2137,7 +2139,6 @@ fn freshness_ignores_excluded() {
).file("build.rs", "fn main() {}")
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
.build();
foo.root().move_into_the_past();

foo.cargo("build")
.with_stderr(
Expand All @@ -2149,17 +2150,17 @@ fn freshness_ignores_excluded() {

// Smoke test to make sure it doesn't compile again
println!("first pass");
foo.cargo("build").with_stdout("").run();
foo.cargo("build").with_stderr("[FINISHED] [..]\n").run();

// Modify an ignored file and make sure we don't rebuild
println!("second pass");
File::create(&foo.root().join("src/bar.rs")).unwrap();
foo.cargo("build").with_stdout("").run();
foo.write_file("src/bar.rs", "");
foo.cargo("build").with_stderr("[FINISHED] [..]\n").run();
}

#[test]
fn rebuild_preserves_out_dir() {
let foo = project()
let mut foo = project()
.file(
"Cargo.toml",
r#"
Expand Down Expand Up @@ -2187,7 +2188,6 @@ fn rebuild_preserves_out_dir() {
"#,
).file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
.build();
foo.root().move_into_the_past();

foo.cargo("build")
.env("FIRST", "1")
Expand All @@ -2198,7 +2198,7 @@ fn rebuild_preserves_out_dir() {
",
).run();

File::create(&foo.root().join("src/bar.rs")).unwrap();
foo.write_file("src/bar.rs", "");
foo.cargo("build")
.with_stderr(
"\
Expand Down Expand Up @@ -2247,8 +2247,7 @@ fn recompile_space_in_name() {
).file("src/my lib.rs", "")
.build();
foo.cargo("build").run();
foo.root().move_into_the_past();
foo.cargo("build").with_stdout("").run();
foo.cargo("build").with_stderr("[FINISHED] [..]\n").run();
}

#[cfg(unix)]
Expand Down Expand Up @@ -2524,7 +2523,7 @@ fn compile_then_delete() {
assert!(p.bin("foo").is_file());
if cfg!(windows) {
// On windows unlinking immediately after running often fails, so sleep
sleep_ms(100);
thread::sleep(Duration::from_millis(100));
}
fs::remove_file(&p.bin("foo")).unwrap();
p.cargo("run -v").run();
Expand Down
Loading