diff options
author | Paul Duffin <paulduffin@google.com> | 2022-04-20 17:31:39 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-20 17:31:39 +0000 |
commit | 82a6353f1e29d5242a20d8a31712ca73901a13a4 (patch) | |
tree | 74e54202b20114ddf260e2fe8c3515667eb96c1f /src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java | |
parent | 97f64d942cc633f41faa687306ec5d4a78191985 (diff) | |
parent | 8c53111a47e58b5ab92782cde7a156a50447779e (diff) | |
download | junit-params-82a6353f1e29d5242a20d8a31712ca73901a13a4.tar.gz |
Allow @TestCaseName to be for names that are compatible with CTS/AJUR am: deb706635e am: a4ec4e26a9 am: 97bb2c51d7 am: 7e97deb1b6 am: 8c53111a47
Original change: https://android-review.googlesource.com/c/platform/external/junit-params/+/2059654
Change-Id: Ie2295eab62e2c43724550f4686c54d468b3684db
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java')
-rw-r--r-- | src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java b/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java index 1bdcafb..3386e51 100644 --- a/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java +++ b/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java @@ -23,6 +23,9 @@ public class MacroSubstitutionNamingStrategy implements TestCaseNamingStrategy { this.method = testMethod; } + // Android-added: allowable test names + private static final Pattern ALLOWABLE_TEST_NAMES = Pattern.compile("\\w+(\\[\\d+])?"); + @Override public String getTestCaseName(int parametersIndex, Object parameters) { TestCaseName testCaseName = method.getAnnotation(TestCaseName.class); @@ -30,6 +33,16 @@ public class MacroSubstitutionNamingStrategy implements TestCaseNamingStrategy { String template = getTemplate(testCaseName); String builtName = buildNameByTemplate(template, parametersIndex, parameters); + // Android-changed: CTS and AndroidJUnitRunner rely on specific format to test names, + // changing them will prevent CTS and AndroidJUnitRunner from working properly; + // see b/36541809 + if (!ALLOWABLE_TEST_NAMES.matcher(builtName).matches()) { + throw new IllegalStateException(String.format( + "@TestCaseName(\"%s\") not currently supported as it generated a test name of" + + " \"%s\" which will not work properly in CTS, must match \"%s\"", + template, builtName, ALLOWABLE_TEST_NAMES)); + } + if (builtName.trim().isEmpty()) { return buildNameByTemplate(DEFAULT_TEMPLATE, parametersIndex, parameters); } else { @@ -39,12 +52,7 @@ public class MacroSubstitutionNamingStrategy implements TestCaseNamingStrategy { private String getTemplate(TestCaseName testCaseName) { if (testCaseName != null) { - // Android-changed: CTS and AndroidJUnitRunner rely on specific format to test names, - // changing them will prevent CTS and AndroidJUnitRunner from working properly; - // see b/36541809 - throw new IllegalStateException( - "@TestCaseName not currently supported as it breaks running tests in CTS"); - // return testCaseName.value(); + return testCaseName.value(); } return DEFAULT_TEMPLATE; |