PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/run-pass/conditional-compile.rs

http://github.com/jruderman/rust
Rust | 99 lines | 68 code | 21 blank | 10 comment | 1 complexity | 426120b8506d9c224fb418dfde98f02d MD5 | raw file
 1#[cfg(bogus)]
 2const b: bool = false;
 3
 4const b: bool = true;
 5
 6#[cfg(bogus)]
 7#[abi = "cdecl"]
 8extern mod rustrt {
 9    // This symbol doesn't exist and would be a link error if this
10    // module was translated
11    fn bogus();
12}
13
14#[abi = "cdecl"]
15extern mod rustrt { }
16
17#[cfg(bogus)]
18type t = int;
19
20type t = bool;
21
22#[cfg(bogus)]
23enum tg { foo, }
24
25enum tg { bar, }
26
27#[cfg(bogus)]
28class r {
29  let i: int;
30  new(i:int) { self.i = i; }
31}
32
33class r {
34  let i: int;
35  new(i:int) { self.i = i; }
36}
37
38#[cfg(bogus)]
39mod m {
40    // This needs to parse but would fail in typeck. Since it's not in
41    // the current config it should not be typechecked.
42    fn bogus() { return 0; }
43}
44
45mod m {
46
47    // Submodules have slightly different code paths than the top-level
48    // module, so let's make sure this jazz works here as well
49    #[cfg(bogus)]
50    fn f() { }
51
52    fn f() { }
53}
54
55// Since the bogus configuration isn't defined main will just be
56// parsed, but nothing further will be done with it
57#[cfg(bogus)]
58fn main() { fail }
59
60fn main() {
61    // Exercise some of the configured items in ways that wouldn't be possible
62    // if they had the bogus definition
63    assert (b);
64    let x: t = true;
65    let y: tg = bar;
66
67    test_in_fn_ctxt();
68}
69
70fn test_in_fn_ctxt() {
71    #[cfg(bogus)]
72    fn f() { fail }
73    fn f() { }
74    f();
75
76    #[cfg(bogus)]
77    const i: int = 0;
78    const i: int = 1;
79    assert (i == 1);
80}
81
82mod test_foreign_items {
83    #[abi = "cdecl"]
84    extern mod rustrt {
85        #[cfg(bogus)]
86        fn vec_from_buf_shared();
87        fn vec_from_buf_shared();
88    }
89}
90
91mod test_use_statements {
92    #[cfg(bogus)]
93    use flippity_foo;
94
95    extern mod rustrt {
96        #[cfg(bogus)]
97        use flippity_foo;
98    }
99}