]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/spike-neg2.rs
Add a testing mechanism and a simple spike test
[rust.git] / src / test / incremental / spike-neg2.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // A variant of the first "spike" test that serves to test the
12 // `rustc_partition_reused` and `rustc_partition_translated` tests.
13 // Here we change and say that the `y` module will be translated (when
14 // in fact it will not), and then indicate that the test itself
15 // should-fail (because an error will be reported, and hence the
16 // revision rpass2 will not compile, despite being named rpass).
17
18 // revisions:rpass1 rpass2
19 // should-fail
20
21 #![feature(rustc_attrs)]
22
23 #![rustc_partition_reused(module="spike_neg2", cfg="rpass2")]
24 #![rustc_partition_translated(module="spike_neg2-x", cfg="rpass2")]
25 #![rustc_partition_translated(module="spike_neg2-y", cfg="rpass2")] // this is wrong!
26
27 mod x {
28     pub struct X {
29         x: u32, y: u32,
30     }
31
32     #[cfg(rpass1)]
33     fn make() -> X {
34         X { x: 22, y: 0 }
35     }
36
37     #[cfg(rpass2)]
38     fn make() -> X {
39         X { x: 11, y: 11 }
40     }
41
42     #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
43     #[rustc_clean(label="ItemSignature", cfg="rpass2")]
44     pub fn new() -> X {
45         make()
46     }
47
48     #[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
49     #[rustc_clean(label="ItemSignature", cfg="rpass2")]
50     pub fn sum(x: &X) -> u32 {
51         x.x + x.y
52     }
53 }
54
55 mod y {
56     use x;
57
58     #[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
59     pub fn assert_sum() -> bool {
60         let x = x::new();
61         x::sum(&x) == 22
62     }
63 }
64
65 pub fn main() {
66     y::assert_sum();
67 }