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