@@ -345,17 +345,18 @@ public void testMultiValueOptionImmutability() throws Exception {
345
345
346
346
@ Test
347
347
public void parsingResultTransform () throws Exception {
348
- BuildOptions original = BuildOptions .of (BUILD_CONFIG_OPTIONS , "--cpu=foo" );
348
+ BuildOptions original = BuildOptions .of (BUILD_CONFIG_OPTIONS , "--cpu=foo" , "--stamp" );
349
349
350
350
OptionsParser parser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
351
- parser .parse ("--cpu=bar" );
351
+ parser .parse ("--cpu=bar" , "--nostamp" );
352
352
parser .setStarlarkOptions (ImmutableMap .of ("//custom:flag" , "hello" ));
353
353
354
354
BuildOptions modified = original .applyParsingResult (parser );
355
355
356
356
assertThat (original .get (BuildConfiguration .Options .class ).cpu )
357
357
.isNotEqualTo (modified .get (BuildConfiguration .Options .class ).cpu );
358
358
assertThat (modified .get (BuildConfiguration .Options .class ).cpu ).isEqualTo ("bar" );
359
+ assertThat (modified .get (Options .class ).stampBinaries ).isFalse ();
359
360
assertThat (modified .getStarlarkOptions ().get (Label .parseAbsoluteUnchecked ("//custom:flag" )))
360
361
.isEqualTo ("hello" );
361
362
}
@@ -387,4 +388,110 @@ public void parsingResultTransformIllegalStarlarkLabel() throws Exception {
387
388
388
389
assertThrows (IllegalArgumentException .class , () -> original .applyParsingResult (parser ));
389
390
}
391
+
392
+ @ Test
393
+ public void parsingResultMatch () throws Exception {
394
+ BuildOptions original = BuildOptions .of (BUILD_CONFIG_OPTIONS , "--cpu=foo" , "--stamp" );
395
+
396
+ OptionsParser matchingParser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
397
+ matchingParser .parse ("--cpu=foo" , "--stamp" );
398
+
399
+ OptionsParser notMatchingParser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
400
+ notMatchingParser .parse ("--cpu=foo" , "--nostamp" );
401
+
402
+ assertThat (original .matches (matchingParser )).isTrue ();
403
+ assertThat (original .matches (notMatchingParser )).isFalse ();
404
+ }
405
+
406
+ @ Test
407
+ public void parsingResultMatchStarlark () throws Exception {
408
+ BuildOptions original =
409
+ BuildOptions .builder ()
410
+ .addStarlarkOption (Label .parseAbsoluteUnchecked ("//custom:flag" ), "hello" )
411
+ .build ();
412
+
413
+ OptionsParser matchingParser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
414
+ matchingParser .setStarlarkOptions (ImmutableMap .of ("//custom:flag" , "hello" ));
415
+
416
+ OptionsParser notMatchingParser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
417
+ notMatchingParser .setStarlarkOptions (ImmutableMap .of ("//custom:flag" , "foo" ));
418
+
419
+ assertThat (original .matches (matchingParser )).isTrue ();
420
+ assertThat (original .matches (notMatchingParser )).isFalse ();
421
+ }
422
+
423
+ @ Test
424
+ public void parsingResultMatchMissingFragment () throws Exception {
425
+ BuildOptions original = BuildOptions .of (BUILD_CONFIG_OPTIONS , "--cpu=foo" );
426
+
427
+ ImmutableList <Class <? extends FragmentOptions >> fragmentClasses =
428
+ ImmutableList .<Class <? extends FragmentOptions >>builder ()
429
+ .add (BuildConfiguration .Options .class )
430
+ .add (CppOptions .class )
431
+ .build ();
432
+
433
+ OptionsParser parser = OptionsParser .newOptionsParser (fragmentClasses );
434
+ parser .parse ("--cpu=foo" , "--cxxopt=bar" );
435
+
436
+ assertThat (original .matches (parser )).isTrue ();
437
+ }
438
+
439
+ @ Test
440
+ public void parsingResultMatchEmptyNativeMatch () throws Exception {
441
+ BuildOptions original = BuildOptions .of (BUILD_CONFIG_OPTIONS , "--cpu=foo" );
442
+
443
+ ImmutableList <Class <? extends FragmentOptions >> fragmentClasses =
444
+ ImmutableList .<Class <? extends FragmentOptions >>builder ()
445
+ .add (BuildConfiguration .Options .class )
446
+ .add (CppOptions .class )
447
+ .build ();
448
+
449
+ OptionsParser parser = OptionsParser .newOptionsParser (fragmentClasses );
450
+ parser .parse ("--cxxopt=bar" );
451
+
452
+ assertThat (original .matches (parser )).isFalse ();
453
+ }
454
+
455
+ @ Test
456
+ public void parsingResultMatchEmptyNativeMatchWithStarlark () throws Exception {
457
+ BuildOptions original =
458
+ BuildOptions .builder ()
459
+ .addStarlarkOption (Label .parseAbsoluteUnchecked ("//custom:flag" ), "hello" )
460
+ .build ();
461
+
462
+ ImmutableList <Class <? extends FragmentOptions >> fragmentClasses =
463
+ ImmutableList .<Class <? extends FragmentOptions >>builder ()
464
+ .add (BuildConfiguration .Options .class )
465
+ .add (CppOptions .class )
466
+ .build ();
467
+
468
+ OptionsParser parser = OptionsParser .newOptionsParser (fragmentClasses );
469
+ parser .parse ("--cxxopt=bar" );
470
+ parser .setStarlarkOptions (ImmutableMap .of ("//custom:flag" , "hello" ));
471
+
472
+ assertThat (original .matches (parser )).isTrue ();
473
+ }
474
+
475
+ @ Test
476
+ public void parsingResultMatchStarlarkOptionMissing () throws Exception {
477
+ BuildOptions original =
478
+ BuildOptions .builder ()
479
+ .addStarlarkOption (Label .parseAbsoluteUnchecked ("//custom:flag1" ), "hello" )
480
+ .build ();
481
+
482
+ OptionsParser parser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
483
+ parser .setStarlarkOptions (ImmutableMap .of ("//custom:flag2" , "foo" ));
484
+
485
+ assertThat (original .matches (parser )).isFalse ();
486
+ }
487
+
488
+ @ Test
489
+ public void parsingResultMatchNullOption () throws Exception {
490
+ BuildOptions original = BuildOptions .of (BUILD_CONFIG_OPTIONS );
491
+
492
+ OptionsParser parser = OptionsParser .newOptionsParser (BUILD_CONFIG_OPTIONS );
493
+ parser .parse ("--platform_suffix=foo" ); // Note: platform_suffix is null by default.
494
+
495
+ assertThat (original .matches (parser )).isFalse ();
496
+ }
390
497
}
0 commit comments