preprocessor.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/python
  2. # Copyright 2003 Vladimir Prus
  3. # Copyright 2011 Steven Watanabe
  4. # Distributed under the Boost Software License, Version 1.0.
  5. # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
  6. # Test the C/C++ preprocessor.
  7. import BoostBuild
  8. t = BoostBuild.Tester()
  9. t.write("jamroot.jam", """
  10. project ;
  11. preprocessed hello : hello.cpp ;
  12. preprocessed a : a.c ;
  13. exe test : hello a : <define>FAIL ;
  14. """)
  15. t.write("hello.cpp", """
  16. #ifndef __cplusplus
  17. #error "This file must be compiled as C++"
  18. #endif
  19. #ifdef FAIL
  20. #error "Not preprocessed?"
  21. #endif
  22. extern "C" int foo();
  23. int main() { return foo(); }
  24. """)
  25. t.write("a.c", """
  26. /* This will not compile unless in C mode. */
  27. #ifdef __cplusplus
  28. #error "This file must be compiled as C"
  29. #endif
  30. #ifdef FAIL
  31. #error "Not preprocessed?"
  32. #endif
  33. int foo(void)
  34. {
  35. int new = 0;
  36. new = (new+1)*7;
  37. return new;
  38. }
  39. """)
  40. t.run_build_system()
  41. t.expect_addition("bin/$toolset/debug*/hello.ii")
  42. t.expect_addition("bin/$toolset/debug*/a.i")
  43. t.expect_addition("bin/$toolset/debug*/test.exe")
  44. t.cleanup()