@@ -2540,36 +2540,47 @@ def test_module_print(self):
2540
2540
assert r'<{(123456789)}>' in output , output
2541
2541
2542
2542
def test_precompiled_headers (self ):
2543
- self .clear ()
2543
+ for suffix in ['gch' , 'pch' ]:
2544
+ print suffix
2545
+ self .clear ()
2544
2546
2545
- open ('header.h' , 'w' ).write ('#define X 5\n ' )
2546
- Popen ([PYTHON , EMCC , '-xc++-header' , 'header.h' , '-c' ]).communicate ()
2547
- assert os .path .exists ('header.h.gch' )
2547
+ open ('header.h' , 'w' ).write ('#define X 5\n ' )
2548
+ Popen ([PYTHON , EMCC , '-xc++-header' , 'header.h' , '-c' ]).communicate ()
2549
+ assert os .path .exists ('header.h.gch' ) # default output is gch
2550
+ if suffix != 'gch' :
2551
+ Popen ([PYTHON , EMCC , '-xc++-header' , 'header.h' , '-o' , 'header.h.' + suffix ]).communicate ()
2552
+ assert open ('header.h.gch' ).read () == open ('header.h.' + suffix ).read ()
2548
2553
2549
- open ('src.cpp' , 'w' ).write (r'''
2554
+ open ('src.cpp' , 'w' ).write (r'''
2550
2555
#include <stdio.h>
2551
2556
int main() {
2552
2557
printf("|%d|\n", X);
2553
2558
return 0;
2554
2559
}
2555
2560
''' )
2556
- Popen ([PYTHON , EMCC , 'src.cpp' , '-include' , 'header.h' ]).communicate ()
2557
-
2558
- output = run_js (self .in_dir ('a.out.js' ), stderr = PIPE , full_output = True , engine = NODE_JS )
2559
- assert '|5|' in output , output
2560
-
2561
- # also verify that the gch is actually used
2562
- err = Popen ([PYTHON , EMCC , 'src.cpp' , '-include' , 'header.h' , '-Xclang' , '-print-stats' ], stderr = PIPE ).communicate ()
2563
- self .assertTextDataContained ('*** PCH/Modules Loaded:\n Module: header.h.gch' , err [1 ])
2564
- # and sanity check it is not mentioned when not
2565
- try_delete ('header.h.gch' )
2566
- err = Popen ([PYTHON , EMCC , 'src.cpp' , '-include' , 'header.h' , '-Xclang' , '-print-stats' ], stderr = PIPE ).communicate ()
2567
- assert '*** PCH/Modules Loaded:\n Module: header.h.gch' not in err [1 ].replace ('\r \n ' , '\n ' ), err [1 ]
2568
-
2569
- # with specified target via -o
2570
- try_delete ('header.h.gch' )
2571
- Popen ([PYTHON , EMCC , '-xc++-header' , 'header.h' , '-o' , 'my.gch' ]).communicate ()
2572
- assert os .path .exists ('my.gch' )
2561
+ Popen ([PYTHON , EMCC , 'src.cpp' , '-include' , 'header.h' ]).communicate ()
2562
+
2563
+ output = run_js (self .in_dir ('a.out.js' ), stderr = PIPE , full_output = True , engine = NODE_JS )
2564
+ assert '|5|' in output , output
2565
+
2566
+ # also verify that the gch is actually used
2567
+ err = Popen ([PYTHON , EMCC , 'src.cpp' , '-include' , 'header.h' , '-Xclang' , '-print-stats' ], stderr = PIPE ).communicate ()
2568
+ self .assertTextDataContained ('*** PCH/Modules Loaded:\n Module: header.h.' + suffix , err [1 ])
2569
+ # and sanity check it is not mentioned when not
2570
+ try_delete ('header.h.' + suffix )
2571
+ err = Popen ([PYTHON , EMCC , 'src.cpp' , '-include' , 'header.h' , '-Xclang' , '-print-stats' ], stderr = PIPE ).communicate ()
2572
+ assert '*** PCH/Modules Loaded:\n Module: header.h.' + suffix not in err [1 ].replace ('\r \n ' , '\n ' ), err [1 ]
2573
+
2574
+ # with specified target via -o
2575
+ try_delete ('header.h.' + suffix )
2576
+ Popen ([PYTHON , EMCC , '-xc++-header' , 'header.h' , '-o' , 'my.' + suffix ]).communicate ()
2577
+ assert os .path .exists ('my.' + suffix )
2578
+
2579
+ # -include-pch flag
2580
+ Popen ([PYTHON , EMCC , '-xc++-header' , 'header.h' , '-o' , 'header.h.' + suffix ]).communicate ()
2581
+ check_execute ([PYTHON , EMCC , 'src.cpp' , '-include-pch' , 'header.h.' + suffix ])
2582
+ output = run_js ('a.out.js' )
2583
+ assert '|5|' in output , output
2573
2584
2574
2585
def test_warn_unaligned (self ):
2575
2586
open ('src.cpp' , 'w' ).write (r'''
0 commit comments