cargo/tests/testsuite/custom_target.rs
Dale Wijnand 7fe2fbc8a3
Remove the argument from the project test support function
By rewriting the tests, with rerast (https://github.com/google/rerast),
to use the newly introduced "at" method.

First I added the following temporary function to cargotest::support:

    pub fn project_foo() -> ProjectBuilder {
        project("foo")
    }

Then I defined the following rewrite.rs:

    use cargotest::support::{ project, project_foo };

    fn rule1(a: &'static str) {
        replace!(project("foo") => project_foo());
        replace!(project(a) => project_foo().at(a));
    }

Then I ran rerast:

    cargo +nightly rerast --rules_file=rewrite.rs --force --targets tests --file tests/testsuite/main.rs

Finally I searched and replaced the references to project_foo with
argument-less project (a little awkardly on macOS with a git clean).

    find tests -type f -exec sed -i -e 's/project_foo/project/g' {} +
    git clean -d tests
2018-07-20 13:31:50 +01:00

171 lines
3.8 KiB
Rust

use cargotest::is_nightly;
use cargotest::support::{execs, project};
use hamcrest::assert_that;
#[test]
fn custom_target_minimal() {
if !is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = ["author@example.com"]
"#,
)
.file(
"src/lib.rs",
r#"
#![feature(no_core)]
#![feature(lang_items)]
#![no_core]
pub fn foo() -> u32 {
42
}
#[lang = "sized"]
pub trait Sized {
// Empty.
}
#[lang = "copy"]
pub trait Copy {
// Empty.
}
"#,
)
.file(
"custom-target.json",
r#"
{
"llvm-target": "x86_64-unknown-none-gnu",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"linker-flavor": "ld.lld"
}
"#,
)
.build();
assert_that(
p.cargo("build")
.arg("--lib")
.arg("--target")
.arg("custom-target.json")
.arg("-v"),
execs().with_status(0),
);
assert_that(
p.cargo("build")
.arg("--lib")
.arg("--target")
.arg("src/../custom-target.json")
.arg("-v"),
execs().with_status(0),
);
}
#[test]
fn custom_target_dependency() {
if !is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = ["author@example.com"]
[dependencies]
bar = { path = "bar" }
"#,
)
.file(
"src/lib.rs",
r#"
#![feature(no_core)]
#![feature(lang_items)]
#![feature(optin_builtin_traits)]
#![no_core]
extern crate bar;
pub fn foo() -> u32 {
bar::bar()
}
#[lang = "freeze"]
unsafe auto trait Freeze {}
"#,
)
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = ["author@example.com"]
"#,
)
.file(
"bar/src/lib.rs",
r#"
#![feature(no_core)]
#![feature(lang_items)]
#![no_core]
pub fn bar() -> u32 {
42
}
#[lang = "sized"]
pub trait Sized {
// Empty.
}
#[lang = "copy"]
pub trait Copy {
// Empty.
}
"#,
)
.file(
"custom-target.json",
r#"
{
"llvm-target": "x86_64-unknown-none-gnu",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"linker-flavor": "ld.lld"
}
"#,
)
.build();
assert_that(
p.cargo("build")
.arg("--lib")
.arg("--target")
.arg("custom-target.json")
.arg("-v"),
execs().with_status(0),
);
}