1 use support
::{project, execs}
;
2 use support
::{COMPILING, RUNNING}
;
3 use hamcrest
::{assert_that}
;
8 test
!(custom_build_script_failed
{
10 .file("Cargo.toml", r
#"
15 authors = ["wycats@example.com"]
18 .file("src/main.rs", r
#"
23 std::os::set_exit_status(101);
26 assert_that(p
.cargo_process("build").arg("-v"),
27 execs().with_status(101)
28 .with_stdout(format
!("\
29 {compiling} foo v0.5.0 ({url})
30 {running} `rustc build.rs --crate-name build-script-build --crate-type bin [..]`
32 url
= p
.url(), compiling
= COMPILING
, running
= RUNNING
))
33 .with_stderr(format
!("\
34 Failed to run custom build command for `foo v0.5.0 ({})`
35 Process didn't exit successfully: `[..]build[..]build-script-build` (status=101)",
39 test
!(custom_build_env_vars
{
40 let p
= project("foo")
41 .file("Cargo.toml", r
#"
46 authors = ["wycats@example.com"]
49 bar_feat = ["bar/foo"]
54 .file("src/main.rs", r
#"
57 .file("bar/Cargo.toml", r
#"
62 authors = ["wycats@example.com"]
68 .file("bar/src/lib.rs", r
#"
72 let file_content
= format
!(r
#"
74 use std::io::fs::PathExtensions;
76 let _target = os::getenv("TARGET").unwrap();
78 let _ncpus = os::getenv("NUM_JOBS").unwrap();
80 let out = os::getenv("CARGO_MANIFEST_DIR").unwrap();
81 let p1 = Path::new(out);
82 let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path());
83 assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display());
85 let opt = os::getenv("OPT_LEVEL").unwrap();
86 assert_eq!(opt.as_slice(), "0");
88 let opt = os::getenv("PROFILE").unwrap();
89 assert_eq!(opt.as_slice(), "compile");
91 let debug = os::getenv("DEBUG").unwrap();
92 assert_eq!(debug.as_slice(), "true");
94 let out = os::getenv("OUT_DIR").unwrap();
95 assert!(out.as_slice().starts_with(r"{0}"));
96 assert!(Path::new(out).is_dir());
98 let _feat = os::getenv("CARGO_FEATURE_FOO").unwrap();
101 p
.root().join("target").join("native").display());
103 let p
= p
.file("bar/build.rs", file_content
);
106 assert_that(p
.cargo_process("build").arg("--features").arg("bar_feat"),
107 execs().with_status(0));
110 test
!(custom_build_script_wrong_rustc_flags
{
111 let p
= project("foo")
112 .file("Cargo.toml", r
#"
117 authors = ["wycats@example.com"]
120 .file("src/main.rs", r
#"
123 .file("build.rs", r
#"
125 println!("cargo:rustc-flags=-aaa -bbb");
129 assert_that(p
.cargo_process("build"),
130 execs().with_status(101)
131 .with_stderr(format
!("\
132 Only `-l` and `-L` flags are allowed in build script of `foo v0.5.0 ({})`: \
138 test!(custom_build_script_rustc_flags {
139 let p = project("foo")
140 .file("Cargo.toml", r#"
145 authors = ["wycats@example.com"]
150 .file("src/main.rs", r#"
153 .file("foo/Cargo.toml", r#"
158 authors = ["wycats@example.com"]
161 .file("foo/src/lib.rs", r#"
163 .file("foo/build.rs", r#"
165 println!("cargo:rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2");
169 // TODO: TEST FAILS BECAUSE OF WRONG STDOUT (but otherwise, the build works)
170 assert_that(p.cargo_process("build").arg("--verbose"),
171 execs().with_status(101)
172 .with_stdout(format!("\
173 {compiling} bar v0.5.0 ({url})
174 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib -g \
176 -C extra-filename=-[..] \
177 --out-dir {dir}{sep}target \
179 -L {dir}{sep}target \
180 -L {dir}{sep}target{sep}deps`
182 running = RUNNING, compiling = COMPILING, sep = path::SEP,
183 dir = p.root().display(),
189 test
!(links_no_build_cmd
{
190 let p
= project("foo")
191 .file("Cargo.toml", r
#"
198 .file("src/lib.rs", "");
200 assert_that(p
.cargo_process("build"),
201 execs().with_status(101)
203 package `foo v0.5.0 (file://[..])` specifies that it links to `a` but does \
204 not have a custom build script
208 test
!(links_duplicates
{
209 let p
= project("foo")
210 .file("Cargo.toml", r
#"
221 .file("src/lib.rs", "")
222 .file("build.rs", "")
223 .file("a/Cargo.toml", r
#"
231 .file("a/src/lib.rs", "")
232 .file("a/build.rs", "");
234 assert_that(p
.cargo_process("build"),
235 execs().with_status(101)
237 native library `a` is being linked to by more than one package, and can only be \
238 linked to by one package
240 foo v0.5.0 (file://[..])
241 a v0.5.0 (file://[..])
245 test
!(overrides_and_links
{
246 let (_
, target
) = ::cargo
::ops
::rustc_version().unwrap();
248 let p
= project("foo")
249 .file("Cargo.toml", r
#"
259 .file("src/lib.rs", "")
260 .file("build.rs", r
#"
263 assert_eq!(os::getenv("DEP_FOO_FOO").unwrap().as_slice(), "bar");
264 assert_eq!(os::getenv("DEP_FOO_BAR").unwrap().as_slice(), "baz");
267 .file(".cargo/config", format
!(r
#"
269 rustc-flags = "-l foo -L bar"
272 "#, target).as_slice())
273 .file("a/Cargo.toml", r
#"
281 .file("a/src/lib.rs", "")
282 .file("a/build.rs", "not valid rust code");
284 assert_that(p
.cargo_process("build").arg("-v"),
285 execs().with_status(0)
287 Compiling a v0.5.0 (file://[..])
288 Running `rustc [..] --crate-name a [..]`
289 Compiling foo v0.5.0 (file://[..])
290 Running `rustc build.rs [..]`
291 Running `rustc [..] --crate-name foo [..]`