@@ -186,143 +186,6 @@ public void testStage1ErrorExitStatus() throws Exception {
186
186
assertThat (new String (outReader .toByteArray (), UTF_8 )).isEmpty ();
187
187
}
188
188
189
- // TODO(b/395966861): delete this test, `test3StageCompile` is the same test but uses the new
190
- // stage 2 flags.
191
- @ Test
192
- public void test3StageCompile_Old () throws Exception {
193
-
194
- // Create a message bundle to use
195
- File msgBundle = temporaryFolder .newFile ("messages.xtb" );
196
- final ImmutableList <String > lines =
197
- ImmutableList .of (
198
- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" ,
199
- "<!DOCTYPE translationbundle SYSTEM \" translationbundle.dtd\" >" ,
200
- "<translationbundle lang=\" es\" >" ,
201
- "<translation id=\" 6289482750305328564\" >hola</translation>" ,
202
- "</translationbundle>" ,
203
- "" );
204
- writeLinesToFile (msgBundle , lines );
205
-
206
- // Create test externs with a definition for goog.getMsg().
207
- final File externsFile = temporaryFolder .newFile ("externs.js" );
208
- writeLinesToFile (
209
- externsFile ,
210
- "/**" ,
211
- " * @fileoverview test externs" ,
212
- " * @externs" ,
213
- " */" ,
214
- "var goog = {};" ,
215
- "/**" ,
216
- " * @nosideeffects" ,
217
- " * @param {string} msg" ,
218
- " * @param {Object=} placeholderReplacements" ,
219
- " * @param {Object=} options" ,
220
- " * @return {string}" ,
221
- " */" ,
222
- "goog.getMsg = function(msg, placeholderReplacements, options) {};" );
223
-
224
- // Create an input file
225
- File srcFile = temporaryFolder .newFile ("input.js" );
226
- writeLinesToFile (
227
- srcFile ,
228
- "/** @desc greeting */" ,
229
- "const MSG_HELLO = goog.getMsg('hello');" ,
230
- "console.log(MSG_HELLO);" );
231
-
232
- // Create a path for the stage 1 output
233
- File stage1Save = temporaryFolder .newFile ("stage1.save" );
234
-
235
- ImmutableList <String > commonFlags =
236
- ImmutableList .of (
237
- "--compilation_level=ADVANCED_OPTIMIZATIONS" ,
238
- "--source_map_include_content" ,
239
- "--translations_file" ,
240
- msgBundle .toString (),
241
- "--externs" ,
242
- externsFile .toString (),
243
- "--js" ,
244
- srcFile .toString ());
245
-
246
- // Run the compiler to generate the stage 1 save file
247
- final ImmutableList <String > stage1Flags =
248
- createStringList (
249
- commonFlags , new String [] {"--save_stage1_to_file" , stage1Save .toString ()});
250
- verifyFlagsAreIncompatibleWithChecksOnly (stage1Flags );
251
- CommandLineRunner runner =
252
- new CommandLineRunner (
253
- stringListToArray (stage1Flags ), new PrintStream (outReader ), new PrintStream (errReader ));
254
- assertThat (runner .doRun ()).isEqualTo (0 );
255
- assertThat (new String (outReader .toByteArray (), UTF_8 )).isEmpty ();
256
-
257
- assertThat (runner .getCompiler ().toSource ())
258
- .isEqualTo ("const MSG_HELLO=goog.getMsg(\" hello\" );console.log(MSG_HELLO);" );
259
-
260
- // Create a path for the stage 2 output
261
- File stage2Save = temporaryFolder .newFile ("stage2.save" );
262
- // run the compiler to generate the stage 2 save file
263
- final ImmutableList <String > stage2Flags =
264
- createStringList (
265
- commonFlags ,
266
- new String [] {
267
- "--restore_stage1_from_file" ,
268
- stage1Save .toString (),
269
- "--save_stage2_to_file" ,
270
- stage2Save .toString ()
271
- });
272
- verifyFlagsAreIncompatibleWithChecksOnly (stage2Flags );
273
- runner = new CommandLineRunner (stringListToArray (stage2Flags ));
274
- assertThat (runner .doRun ()).isEqualTo (0 );
275
-
276
- // During stage 2 the message is wrapped in a function call to protect it from mangling by
277
- // optimizations.
278
- assertThat (runner .getCompiler ().toSource ())
279
- .isEqualTo (
280
- concatStrings (
281
- "console.log(" ,
282
- "__jscomp_define_msg__({\" key\" :\" MSG_HELLO\" ,\" msg_text\" :\" hello\" })" ,
283
- ");" ));
284
-
285
- // Create a path for the final output
286
- File compiledFile = temporaryFolder .newFile ("compiled.js" );
287
- // Create a path for the output source map
288
- File sourceMapFile = temporaryFolder .newFile ("compiled.sourcemap" );
289
-
290
- // run the compiler to generate the final output
291
- final ImmutableList <String > stage3Flags =
292
- createStringList (
293
- commonFlags ,
294
- new String [] {
295
- "--restore_stage2_from_file" ,
296
- stage2Save .toString (),
297
- "--js_output_file" ,
298
- compiledFile .toString (),
299
- "--create_source_map" ,
300
- sourceMapFile .toString ()
301
- });
302
- verifyFlagsAreIncompatibleWithChecksOnly (stage3Flags );
303
- runner = new CommandLineRunner (stringListToArray (stage3Flags ));
304
- assertThat (runner .doRun ()).isEqualTo (0 );
305
-
306
- // During stage 3 the message is actually replaced and the output written to the compiled
307
- // output file.
308
- final String compiledJs = java .nio .file .Files .readString (compiledFile .toPath ());
309
- assertThat (compiledJs ).isEqualTo ("console.log(\" hola\" );\n " );
310
-
311
- final JsonObject expectedSourceMap = new JsonObject ();
312
- expectedSourceMap .addProperty ("version" , 3 );
313
- expectedSourceMap .addProperty ("file" , compiledFile .getAbsolutePath ());
314
- expectedSourceMap .addProperty ("lineCount" , 1 );
315
- expectedSourceMap .addProperty ("mappings" , "AAEAA,OAAQC,CAAAA,GAAR,CADkBC,MAClB;" );
316
- expectedSourceMap .add ("sources" , newJsonArrayOfStrings (srcFile .getAbsolutePath ()));
317
- expectedSourceMap .add (
318
- "sourcesContent" , newJsonArrayOfStrings (java .nio .file .Files .readString (srcFile .toPath ())));
319
- expectedSourceMap .add ("names" , newJsonArrayOfStrings ("console" , "log" , "MSG_HELLO" ));
320
-
321
- final String sourceMapText = java .nio .file .Files .readString (sourceMapFile .toPath ());
322
- JsonObject actualSourceMap = getJsonObjectFromJson (sourceMapText );
323
- assertThat (actualSourceMap ).isEqualTo (expectedSourceMap );
324
- }
325
-
326
189
@ Test
327
190
public void test3StageCompile () throws Exception {
328
191
0 commit comments