diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-21 01:03:57 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-21 01:03:57 +0000 |
commit | aff1a6c7cfd7e15337f70624907759803f036294 (patch) | |
tree | 74e54202b20114ddf260e2fe8c3515667eb96c1f | |
parent | 67ef30436e2e83bfd2b5ecdbc8524c83e24c0313 (diff) | |
parent | 7e97deb1b6e94e0c2a634cc812f6303f23737af2 (diff) | |
download | junit-params-android13-s2-release.tar.gz |
Snap for 8479413 from 7e97deb1b6e94e0c2a634cc812f6303f23737af2 to tm-releaseandroid-vts-13.0_r8android-vts-13.0_r7android-vts-13.0_r6android-vts-13.0_r5android-vts-13.0_r4android-vts-13.0_r3android-vts-13.0_r2android-vts-13.0_r1android-security-13.0.0_r9android-security-13.0.0_r8android-security-13.0.0_r7android-security-13.0.0_r6android-security-13.0.0_r5android-security-13.0.0_r4android-security-13.0.0_r3android-security-13.0.0_r2android-security-13.0.0_r17android-security-13.0.0_r16android-security-13.0.0_r15android-security-13.0.0_r14android-security-13.0.0_r13android-security-13.0.0_r12android-security-13.0.0_r11android-security-13.0.0_r10android-security-13.0.0_r1android-platform-13.0.0_r2android-platform-13.0.0_r1android-cts-13.0_r8android-cts-13.0_r7android-cts-13.0_r6android-cts-13.0_r5android-cts-13.0_r4android-cts-13.0_r3android-cts-13.0_r2android-cts-13.0_r1android-13.0.0_r8android-13.0.0_r7android-13.0.0_r6android-13.0.0_r5android-13.0.0_r4android-13.0.0_r31android-13.0.0_r3android-13.0.0_r2android-13.0.0_r12android-13.0.0_r1android13-tests-releaseandroid13-security-releaseandroid13-s3-releaseandroid13-s2-releaseandroid13-s1-releaseandroid13-release
Change-Id: I8d00fb79aceacec8722fb593d91fc524c3119e2c
-rw-r--r-- | README.google | 3 | ||||
-rw-r--r-- | src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java | 20 |
2 files changed, 17 insertions, 6 deletions
diff --git a/README.google b/README.google index 47541ba..a1ef97e 100644 --- a/README.google +++ b/README.google @@ -18,3 +18,6 @@ Local Modifications: and prevent use of @TestCaseName. Ignore tests broken by the above change. 38419944 - Fix sharding on CTS. + 36541809 - Partially revert 36541809 to allow @TestCaseName to be + used as long as it generates a name that is compatible + with CTS and AJUR. 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; |