aboutsummaryrefslogtreecommitdiff
path: root/tests/cc/modules/headers.testscript
blob: 6fc2ba79e43c3d689bc0c339de4fe2c4517be6ab (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# file      : tests/cc/modules/headers.testscript
# license   : MIT; see accompanying LICENSE file

# Test header units.
#

.include common.testscript

+$headers || exit

# Common source files that are symlinked in the test directories if used.
#
+cat <<EOI >=core.hxx
  #ifdef CORE_IN
  #  error macro isolation
  #endif
  #define CORE_OUT 1
  inline int f () {return 1;}
  EOI

+cat <<EOI >=base.mxx
  #define CORE_IN 1

  #ifdef BASE_INCLUDE
    // Cannot include (even if translated) in module purview.
    //
    module;
    #include "core.hxx"
    export module foo.base;
  #else
    export module foo.base;
    #ifdef BASE_RE_EXPORT
      export import "core.hxx";
    #else
      import "core.hxx";
    #endif
  #endif

  #ifndef CORE_OUT
  #  error macro export
  #endif

  export inline int g () {return f () - 1 /*CORE_OUT*/;} //@@ MODGCC
  EOI

+cat <<EOI >=core.hxx.in
  #ifdef CORE_IN
  #  error macro isolation
  #endif
  inline int f () {return 0;}
  EOI

: basics
:
ln -s ../core.hxx ./;
cat <<EOI >=driver-imp.cxx;
  #define CORE_IN 1
  import "core.hxx";
  #ifndef CORE_OUT
  #  error macro export
  #endif
  int main () {return f () - CORE_OUT;}
  EOI
cat <<EOI >=driver-inc.cxx;
  #define CORE_IN 1
  #include "core.hxx"
  #ifndef CORE_OUT
  #  error macro export
  #endif
  int main () {return f () - CORE_OUT;}
  EOI
$* test clean config.cxx.translatable_headers="$~/core.hxx" <<EOI
  ./: exe{test-imp}: cxx{driver-imp} hxx{core}
  ./: exe{test-inc}: cxx{driver-inc} hxx{core}
  EOI

: module
:
{
  +cat <<EOI >=driver.cxx
    #define CORE_IN 1
    import foo.base;
    #ifdef CORE_OUT
    #  error macro export
    #endif
    EOI

  : import
  :
  ln -s ../../core.hxx ../../base.mxx ./;
  cat ../driver.cxx - <<EOI >=driver.cxx;
    int main () {return g ();}
    EOI
  $* test clean <<EOI
    exe{test}: cxx{driver} hxx{core} mxx{base}
    EOI

  #\
  #@@ MODGCC
  : include
  :
  ln -s ../../core.hxx ../../base.mxx ./;
  cat ../driver.cxx - <<EOI >=driver.cxx;
    int main () {return g ();}
    EOI
  $* test clean config.cxx.poptions=-DBASE_INCLUDE \
     config.cxx.translatable_headers="$~/core.hxx" <<EOI
    exe{test}: cxx{driver} hxx{core} mxx{base}
    EOI
  #\

  : re-export
  :
  ln -s ../../core.hxx ../../base.mxx ./;
  cat ../driver.cxx - <<EOI >=driver.cxx;
    int main () {return g () + (f () - 1);}
    EOI
  $* test clean config.cxx.poptions=-DBASE_RE_EXPORT <<EOI
    exe{test}: cxx{driver} hxx{core} mxx{base}
    EOI
}

# @@ TODO
#
#\
: generated
:
ln -s ../core.hxx.in ./;
cat <<EOI >=driver-imp.cxx;
  import <generated/core.hxx>;
  int main () {return f ();}
  EOI
cat <<EOI >=driver-inc.cxx;
  #define CORE_IN 1
  #include <generated/core.hxx>
  int main () {return f ();}
  EOI
$* test clean config.cxx.translatable_headers="$~/core.hxx" <<EOI
  ./: exe{test-imp}: cxx{driver-imp} hxx{core}
  ./: exe{test-inc}: cxx{driver-inc} hxx{core}
  hxx{core}: in{core}
  EOI

: remapped
:
ln -s ../core.hxx.in ./;
cat <<EOI >=core.hxx;
  #error poison
  EOI
cat <<EOI >=driver-imp.cxx;
  import <remapped/core.hxx>;
  int main () {return f ();}
  EOI
cat <<EOI >=driver-inc.cxx;
  #define CORE_IN 1
  #include <remapped/core.hxx>
  int main () {return f ();}
  EOI
# Remapping can only be tested with an out of source build. Note that we
# need a private out because of module sidebuilds.
#
out = ../../headers-remapped-out;
$* 'test:' ./@$out/remapped/ \
   config.cxx.translatable_headers=$out/remapped/core.hxx <<EOI;
  ./: exe{test-imp}: cxx{driver-imp} hxx{core}
  ./: exe{test-inc}: cxx{driver-inc} hxx{core}
  hxx{core}: in{core}
  EOI
rm -rf $out
#\

# Clean module sidebuilds.
#
-$* clean <<EOI
./:
EOI