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

99 lines
1.7 KiB
Rust
Raw Normal View History

#[cfg(bogus)]
2011-07-27 07:19:39 -05:00
const b: bool = false;
2011-07-27 07:19:39 -05:00
const b: bool = true;
#[cfg(bogus)]
#[abi = "cdecl"]
extern mod rustrt {
2011-07-27 07:19:39 -05:00
// This symbol doesn't exist and would be a link error if this
// module was translated
fn bogus();
}
#[abi = "cdecl"]
extern mod rustrt { }
#[cfg(bogus)]
type t = int;
type t = bool;
#[cfg(bogus)]
enum tg { foo, }
enum tg { bar, }
#[cfg(bogus)]
2012-08-15 20:46:55 -05:00
struct r {
let i: int;
new(i:int) { self.i = i; }
}
2012-08-15 20:46:55 -05:00
struct r {
let i: int;
new(i:int) { self.i = i; }
}
#[cfg(bogus)]
mod m {
2011-07-27 07:19:39 -05:00
// This needs to parse but would fail in typeck. Since it's not in
// the current config it should not be typechecked.
2012-08-01 19:30:05 -05:00
fn bogus() { return 0; }
}
mod m {
2011-07-27 07:19:39 -05:00
// Submodules have slightly different code paths than the top-level
// module, so let's make sure this jazz works here as well
#[cfg(bogus)]
fn f() { }
2011-07-27 07:19:39 -05:00
fn f() { }
}
// Since the bogus configuration isn't defined main will just be
// parsed, but nothing further will be done with it
#[cfg(bogus)]
fn main() { fail }
fn main() {
2011-07-27 07:19:39 -05:00
// Exercise some of the configured items in ways that wouldn't be possible
// if they had the bogus definition
assert (b);
let x: t = true;
let y: tg = bar;
2011-07-27 07:19:39 -05:00
test_in_fn_ctxt();
}
fn test_in_fn_ctxt() {
2011-07-27 07:19:39 -05:00
#[cfg(bogus)]
fn f() { fail }
fn f() { }
f();
#[cfg(bogus)]
const i: int = 0;
const i: int = 1;
assert (i == 1);
}
mod test_foreign_items {
#[abi = "cdecl"]
extern mod rustrt {
2011-07-27 07:19:39 -05:00
#[cfg(bogus)]
2012-09-01 20:07:51 -05:00
fn rust_getcwd() -> ~str;
fn rust_getcwd() -> ~str;
2011-07-27 07:19:39 -05:00
}
}
mod test_use_statements {
#[cfg(bogus)]
use flippity_foo;
extern mod rustrt {
#[cfg(bogus)]
use flippity_foo;
}
}