|
| 1 | +extern crate cargotest; |
| 2 | +extern crate hamcrest; |
| 3 | + |
| 4 | +use cargotest::is_nightly; |
| 5 | +use cargotest::support::{execs, project}; |
| 6 | +use hamcrest::assert_that; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn check_success() { |
| 10 | + let foo = project("foo") |
| 11 | + .file("Cargo.toml", r#" |
| 12 | + [package] |
| 13 | + name = "foo" |
| 14 | + version = "0.0.1" |
| 15 | + authors = [] |
| 16 | +
|
| 17 | + [dependencies.bar] |
| 18 | + path = "../bar" |
| 19 | + "#) |
| 20 | + .file("src/main.rs", r#" |
| 21 | + extern crate bar; |
| 22 | + fn main() { |
| 23 | + ::bar::baz(); |
| 24 | + } |
| 25 | + "#); |
| 26 | + let bar = project("bar") |
| 27 | + .file("Cargo.toml", r#" |
| 28 | + [package] |
| 29 | + name = "bar" |
| 30 | + version = "0.1.0" |
| 31 | + authors = [] |
| 32 | + "#) |
| 33 | + .file("src/lib.rs", r#" |
| 34 | + pub fn baz() {} |
| 35 | + "#); |
| 36 | + bar.build(); |
| 37 | + |
| 38 | + let expected = if is_nightly() { 0 } else { 101 }; |
| 39 | + assert_that(foo.cargo_process("check"), |
| 40 | + execs().with_status(expected)); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn check_fail() { |
| 45 | + let foo = project("foo") |
| 46 | + .file("Cargo.toml", r#" |
| 47 | + [package] |
| 48 | + name = "foo" |
| 49 | + version = "0.0.1" |
| 50 | + authors = [] |
| 51 | +
|
| 52 | + [dependencies.bar] |
| 53 | + path = "../bar" |
| 54 | + "#) |
| 55 | + .file("src/main.rs", r#" |
| 56 | + extern crate bar; |
| 57 | + fn main() { |
| 58 | + ::bar::baz(42); |
| 59 | + } |
| 60 | + "#); |
| 61 | + let bar = project("bar") |
| 62 | + .file("Cargo.toml", r#" |
| 63 | + [package] |
| 64 | + name = "bar" |
| 65 | + version = "0.1.0" |
| 66 | + authors = [] |
| 67 | + "#) |
| 68 | + .file("src/lib.rs", r#" |
| 69 | + pub fn baz() {} |
| 70 | + "#); |
| 71 | + bar.build(); |
| 72 | + |
| 73 | + assert_that(foo.cargo_process("check"), |
| 74 | + execs().with_status(101)); |
| 75 | +} |
| 76 | + |
| 77 | +#[test] |
| 78 | +fn custom_derive() { |
| 79 | + let foo = project("foo") |
| 80 | + .file("Cargo.toml", r#" |
| 81 | + [package] |
| 82 | + name = "foo" |
| 83 | + version = "0.0.1" |
| 84 | + authors = [] |
| 85 | +
|
| 86 | + [dependencies.bar] |
| 87 | + path = "../bar" |
| 88 | + "#) |
| 89 | + .file("src/main.rs", r#" |
| 90 | +#![feature(proc_macro)] |
| 91 | +
|
| 92 | +#[macro_use] |
| 93 | +extern crate bar; |
| 94 | +
|
| 95 | +trait B { |
| 96 | + fn b(&self); |
| 97 | +} |
| 98 | +
|
| 99 | +#[derive(B)] |
| 100 | +struct A; |
| 101 | +
|
| 102 | +fn main() { |
| 103 | + let a = A; |
| 104 | + a.b(); |
| 105 | +} |
| 106 | +"#); |
| 107 | + let bar = project("bar") |
| 108 | + .file("Cargo.toml", r#" |
| 109 | + [package] |
| 110 | + name = "bar" |
| 111 | + version = "0.1.0" |
| 112 | + authors = [] |
| 113 | + [lib] |
| 114 | + proc-macro = true |
| 115 | + "#) |
| 116 | + .file("src/lib.rs", r#" |
| 117 | +#![feature(proc_macro, proc_macro_lib)] |
| 118 | +#![crate_type = "proc-macro"] |
| 119 | +
|
| 120 | +extern crate proc_macro; |
| 121 | +
|
| 122 | +use proc_macro::TokenStream; |
| 123 | +
|
| 124 | +#[proc_macro_derive(B)] |
| 125 | +pub fn derive(_input: TokenStream) -> TokenStream { |
| 126 | + format!("impl B for A {{ fn b(&self) {{}} }}").parse().unwrap() |
| 127 | +} |
| 128 | +"#); |
| 129 | + bar.build(); |
| 130 | + |
| 131 | + let expected = if is_nightly() { 0 } else { 101 }; |
| 132 | + assert_that(foo.cargo_process("check"), |
| 133 | + execs().with_status(expected)); |
| 134 | +} |
| 135 | + |
| 136 | +#[test] |
| 137 | +fn check_build() { |
| 138 | + if !is_nightly() { |
| 139 | + return; |
| 140 | + } |
| 141 | + |
| 142 | + let foo = project("foo") |
| 143 | + .file("Cargo.toml", r#" |
| 144 | + [package] |
| 145 | + name = "foo" |
| 146 | + version = "0.0.1" |
| 147 | + authors = [] |
| 148 | +
|
| 149 | + [dependencies.bar] |
| 150 | + path = "../bar" |
| 151 | + "#) |
| 152 | + .file("src/main.rs", r#" |
| 153 | + extern crate bar; |
| 154 | + fn main() { |
| 155 | + ::bar::baz(); |
| 156 | + } |
| 157 | + "#); |
| 158 | + let bar = project("bar") |
| 159 | + .file("Cargo.toml", r#" |
| 160 | + [package] |
| 161 | + name = "bar" |
| 162 | + version = "0.1.0" |
| 163 | + authors = [] |
| 164 | + "#) |
| 165 | + .file("src/lib.rs", r#" |
| 166 | + pub fn baz() {} |
| 167 | + "#); |
| 168 | + bar.build(); |
| 169 | + |
| 170 | + assert_that(foo.cargo_process("check"), |
| 171 | + execs().with_status(0)); |
| 172 | + assert_that(foo.cargo_process("build"), |
| 173 | + execs().with_status(0)); |
| 174 | +} |
| 175 | + |
| 176 | +#[test] |
| 177 | +fn build_check() { |
| 178 | + if !is_nightly() { |
| 179 | + return; |
| 180 | + } |
| 181 | + |
| 182 | + let foo = project("foo") |
| 183 | + .file("Cargo.toml", r#" |
| 184 | + [package] |
| 185 | + name = "foo" |
| 186 | + version = "0.0.1" |
| 187 | + authors = [] |
| 188 | +
|
| 189 | + [dependencies.bar] |
| 190 | + path = "../bar" |
| 191 | + "#) |
| 192 | + .file("src/main.rs", r#" |
| 193 | + extern crate bar; |
| 194 | + fn main() { |
| 195 | + ::bar::baz(); |
| 196 | + } |
| 197 | + "#); |
| 198 | + let bar = project("bar") |
| 199 | + .file("Cargo.toml", r#" |
| 200 | + [package] |
| 201 | + name = "bar" |
| 202 | + version = "0.1.0" |
| 203 | + authors = [] |
| 204 | + "#) |
| 205 | + .file("src/lib.rs", r#" |
| 206 | + pub fn baz() {} |
| 207 | + "#); |
| 208 | + bar.build(); |
| 209 | + |
| 210 | + assert_that(foo.cargo_process("build"), |
| 211 | + execs().with_status(0)); |
| 212 | + assert_that(foo.cargo_process("check"), |
| 213 | + execs().with_status(0)); |
| 214 | +} |
0 commit comments