diff options
author | jcater <jcater@google.com> | 2018-02-20 14:00:33 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-20 14:02:23 -0800 |
commit | 2dd46e6178a7e99e38c56a0fddc1a6e533b53bf0 (patch) | |
tree | 9bcf07b3577951466dbaea11b2e25069eeb8a18e /src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java | |
parent | 80a0633bbeef3f84ab6eb6513a5d36936cd1bdbb (diff) |
Update --flaky_test_attempts to also take a repeatable argument of the form
regex@attempts, similarly to --runs_per_test.
Also re-arrange some option converters to be closer to their options.
RELNOTES: flaky_test_attempts supports the regex@attempts syntax, like runs_per_test.
PiperOrigin-RevId: 186358437
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java index e50deeded7..e210a1effd 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java @@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration.RunsPerTestConverter; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment; import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory; @@ -30,10 +29,13 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.util.RegexFilter; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.OptionDocumentationCategory; import com.google.devtools.common.options.OptionEffectTag; +import com.google.devtools.common.options.OptionsParsingException; import com.google.devtools.common.options.TriState; +import java.util.Collections; import java.util.List; /** Test-related options. */ @@ -210,4 +212,58 @@ public class TestConfiguration extends Fragment { } return 1; } + + /** + * Option converter that han handle two styles of value for "--runs_per_test": + * + * <ul> + * <li>--runs_per_test=NUMBER: Run each test NUMBER times. + * <li>--runs_per_test=test_regex@NUMBER: Run each test that matches test_regex NUMBER times. + * This form can be repeated with multiple regexes. + * </ul> + */ + public static class RunsPerTestConverter extends PerLabelOptions.PerLabelOptionsConverter { + @Override + public PerLabelOptions convert(String input) throws OptionsParsingException { + try { + return parseAsInteger(input); + } catch (NumberFormatException ignored) { + return parseAsRegex(input); + } + } + + private PerLabelOptions parseAsInteger(String input) + throws NumberFormatException, OptionsParsingException { + int numericValue = Integer.parseInt(input); + if (numericValue <= 0) { + throw new OptionsParsingException("'" + input + "' should be >= 1"); + } else { + RegexFilter catchAll = + new RegexFilter(Collections.singletonList(".*"), Collections.<String>emptyList()); + return new PerLabelOptions(catchAll, Collections.singletonList(input)); + } + } + + private PerLabelOptions parseAsRegex(String input) throws OptionsParsingException { + PerLabelOptions testRegexps = super.convert(input); + if (testRegexps.getOptions().size() != 1) { + throw new OptionsParsingException("'" + input + "' has multiple runs for a single pattern"); + } + String runsPerTest = Iterables.getOnlyElement(testRegexps.getOptions()); + try { + int numericRunsPerTest = Integer.parseInt(runsPerTest); + if (numericRunsPerTest <= 0) { + throw new OptionsParsingException("'" + input + "' has a value < 1"); + } + } catch (NumberFormatException e) { + throw new OptionsParsingException("'" + input + "' has a non-numeric value", e); + } + return testRegexps; + } + + @Override + public String getTypeDescription() { + return "a positive integer or test_regex@runs. This flag may be passed more than once"; + } + } } |