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