aboutsummaryrefslogtreecommitdiff
path: root/tests/cc/preprocessed/testscript
blob: 844e140f772059e0d45c90fbe53af8abf711de4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# file      : tests/cc/preprocessed/testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

crosstest = false
test.arguments = config.cxx="$recall($cxx.path)" update

.include ../../common.testscript

# Trace filter.
#
# trace: cxx::compile::apply extracting (headers|modules) from: .../obje{(test).o...}
#
filter = sed -n -e \
  \''s/^trace: cxx::compile_rule::apply: extracting ([^ ]+) from[^{]+\{([^.]+).*/\1 \2/p'\'

+cat <<EOI >=build/root.build
cxx.std = latest

using cxx

hxx{*}: extension = hxx
cxx{*}: extension = cxx

cxx.poptions =+ "-I$src_root"
EOI

: none
:
: Include a header (makes sure headers are handled) which defines the
: TEST_VALUE macro. Import a non-existent module unless this macro is
: defined (makes sure modules are extracted from preprocessed source).
: Use the macro (makes sure compilation happens on preprocessed source).
:
cat <<EOI >=test.hxx &!test.hxx;
  #define TEST_VALUE 0
  EOI
cat <<EOI >=test.cxx &!test.cxx;
  #include <none/test.hxx>

  #ifndef TEST_VALUE
  import foo;
  #endif

  int main () {return TEST_VALUE;}
  EOI
$* --verbose 5 &test* <<EOI 2>&1 | $filter >>EOO
  exe{test}: cxx{test}
  EOI
  headers test
  modules test
  EOO

: includes
:
cat <<EOI >=test.cxx &!test.cxx;
  #ifndef TEST_VALUE
  import foo;
  #endif

  int main () {return TEST_VALUE;}
  EOI
$* --verbose 5 &test* <<EOI 2>&1 | $filter >>EOO
  cxx.preprocessed = includes
  cxx.poptions += -DTEST_VALUE=0
  exe{test}: cxx{test}
  EOI
  modules test
  EOO

: modules
:
: Define and use macro to test that compilation inclused the preprocessor.
:
cat <<EOI >=test.cxx &!test.cxx;
  int main () {return TEST_VALUE;}
  EOI
$* --verbose 5 &test* <<EOI 2>&1 | $filter >>EOO
  cxx.preprocessed = modules
  cxx.poptions += -DTEST_VALUE=0
  exe{test}: cxx{test}
  EOI
  modules test
  EOO

: modules-extract
:
: Define macro that would have disabled the module import (makes sure
: modules are extracted directly from source).
:
cat <<EOI >=test.cxx &!test.cxx;
  #define TEST_VALUE
  #ifndef TEST_VALUE
  import foo;
  #endif
  EOI
$* &test* <<EOI 2>>EOE != 0
  cxx.preprocessed = modules
  exe{test}: cxx{test}
  EOI
  error: modules support required by cxx{test}
  EOE

: all
:
: Test handling of comments and line continuations. Define macro on the
: command line that would have affected the result.
:
cat <<EOI >=test.cxx &!test.cxx;
  // C++ comment
  /*
  C comment
  */

  int ma\
  in () {}
  EOI
$* --verbose &test* 5 <<EOI 2>&1 | $filter >>EOO
  cxx.preprocessed = all
  cxx.poptions += -Dmain=foo
  exe{test}: cxx{test}
  EOI
  modules test
  EOO