Skip to content

Commit

Permalink
Tests for new package.build behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Woolcock committed Dec 2, 2016
1 parent ea2c6e8 commit 73e0244
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/build-script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2334,3 +2334,74 @@ fn switch_features_rerun() {
assert_that(build.cargo("run").arg("-v").arg("--features=foo"),
execs().with_status(0).with_stdout("foo\n"));
}

#[test]
fn assume_build_script_when_build_rs_present() {
let p = project("builder")
.file("Cargo.toml", r#"
[package]
name = "builder"
version = "0.0.1"
authors = []
"#)
.file("src/main.rs", r#"
fn main() {
println!(include_str!(concat!(env!("OUT_DIR"), "/output")));
}
"#)
.file("build.rs", r#"
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir).join("output");
let mut f = File::create(&out_dir).unwrap();
f.write_all(b"foo").unwrap();
}
"#);
p.build();

assert_that(p.cargo("run").arg("-v"),
execs().with_status(0).with_stdout("foo\n"));
}

#[test]
fn if_build_set_to_false_dont_tread_build_rs_as_build_script() {
let p = project("builder")
.file("Cargo.toml", r#"
[package]
name = "builder"
version = "0.0.1"
authors = []
build = false
"#)
.file("src/main.rs", r#"
use std::path::Path;
fn main() {
let f = env!("OUT_DIR");
assert!(
! Path::new(f).join("output").exists()
)
}
"#)
.file("build.rs", r#"
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir).join("output");
let mut f = File::create(&out_dir).unwrap();
f.write_all(b"foo").unwrap();
}
"#);
p.build();

assert_that(p.cargo("run").arg("-v"),
execs().with_status(0));
}

0 comments on commit 73e0244

Please sign in to comment.