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

156 lines
2.7 KiB
Rust
Raw Normal View History

// xfail-fast
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2012-11-01 22:48:37 +00:00
// Crate use statements
#[cfg(bogus)]
use flippity;
#[cfg(bogus)]
2011-07-27 12:19:39 +00:00
const b: bool = false;
2011-07-27 12:19:39 +00:00
const b: bool = true;
#[cfg(bogus)]
#[abi = "cdecl"]
extern mod rustrt {
2011-07-27 12:19:39 +00:00
// This symbol doesn't exist and would be a link error if this
// module was translated
pub 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-16 01:46:55 +00:00
struct r {
2012-09-07 02:40:15 +00:00
i: int,
2012-09-05 22:58:43 +00:00
}
#[cfg(bogus)]
fn r(i:int) -> r {
r {
i: i
}
}
2012-08-16 01:46:55 +00:00
struct r {
2012-09-07 02:40:15 +00:00
i: int,
2012-09-05 22:58:43 +00:00
}
fn r(i:int) -> r {
r {
i: i
}
}
#[cfg(bogus)]
mod m {
2011-07-27 12:19:39 +00:00
// This needs to parse but would fail in typeck. Since it's not in
// the current config it should not be typechecked.
pub fn bogus() { return 0; }
}
mod m {
2011-07-27 12:19:39 +00: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)]
pub fn f() { }
pub 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() { die!() }
fn main() {
2011-07-27 12:19:39 +00: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 12:19:39 +00:00
test_in_fn_ctxt();
}
fn test_in_fn_ctxt() {
2011-07-27 12:19:39 +00:00
#[cfg(bogus)]
fn f() { die!() }
2011-07-27 12:19:39 +00:00
fn f() { }
f();
#[cfg(bogus)]
const i: int = 0;
const i: int = 1;
assert (i == 1);
}
mod test_foreign_items {
#[abi = "cdecl"]
pub extern mod rustrt {
2011-07-27 12:19:39 +00:00
#[cfg(bogus)]
pub fn rust_getcwd() -> ~str;
pub fn rust_getcwd() -> ~str;
2011-07-27 12:19:39 +00:00
}
}
mod test_use_statements {
#[cfg(bogus)]
use flippity_foo;
pub extern mod rustrt {
#[cfg(bogus)]
use flippity_foo;
}
2012-11-01 22:48:37 +00:00
}
mod test_methods {
struct Foo {
bar: uint
}
impl Foo: Fooable {
#[cfg(bogus)]
static fn what() { }
static fn what() { }
#[cfg(bogus)]
fn the() { }
fn the() { }
}
trait Fooable {
#[cfg(bogus)]
static fn what();
static fn what();
#[cfg(bogus)]
fn the();
fn the();
}
}