Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to execlude somes test in option of command line #3200

1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Fixed: GITHUB-3122: Update JCommander to 1.83 (Antoine Dessaigne)
Fixed: GITHUB-3135: assertEquals on arrays - Failure message is missing information about the array index when an array element is unexpectedly null or non-null (Albert Choi)
Fixed: GITHUB-3140: assertEqualsDeep on Sets - Deep comparison was using the wrong expected value
Fixed: GITHUB-3189: Incorrect number of ignored tests displayed in the XML results
Fixed: GITHUB-3196: support to execlude somes tests in option of command line

7.10.2
Fixed: GITHUB-3117: ListenerComparator doesn't work (Krishnan Mahadevan)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I try to revert the update of README.md, it still shows there is one line have update.

Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ gpg: Good signature from "Krishnan Mahadevan (krmahadevan-key) <krishnan.mahadev
For more details regarding keys please refer:
* [Verifying Signature](https://infra.apache.org/release-signing.html#verifying-signature)
* [How to Trust Imported GPG Keys](https://classroom.anir0y.in/post/blog-how-to-trust-imported-gpg-keys/)
* [How to Trust Imported GPG Keys](https://classroom.anir0y.in/post/blog-how-to-trust-imported-gpg-keys/)
12 changes: 11 additions & 1 deletion testng-core-api/src/main/java/org/testng/xml/XmlTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testng.xml;

import java.util.*;
import java.util.regex.Pattern;
import org.testng.TestNGException;
import org.testng.collections.Lists;
import org.testng.collections.Maps;
Expand Down Expand Up @@ -624,6 +625,15 @@ public XmlGroups getXmlGroups() {
* @return <code>true</code> if the current test's name matches with any of the given names.
*/
public boolean nameMatchesAny(List<String> names) {
return names.contains(getName());
return names.contains(getName())
|| names.stream()
.anyMatch(
regex -> {
if (regex.startsWith("/") && regex.endsWith("/")) {
String trimmedRegex = regex.substring(1, regex.length() - 1);
return Pattern.matches(trimmedRegex, getName());
}
return false;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testng.xml.internal;

import java.util.List;
import java.util.regex.Pattern;
import org.testng.TestNGException;
import org.testng.collections.Lists;
import org.testng.log4testng.Logger;
Expand Down Expand Up @@ -89,7 +90,18 @@ public boolean validateMissMatchedTestNames() {
public List<String> getMissedTestNames() {
List<String> missedTestNames = Lists.newArrayList();
missedTestNames.addAll(testNames);
missedTestNames.removeIf(matchedTestNames::contains);
missedTestNames.removeIf(
regex ->
matchedTestNames.contains(regex)
|| matchedTestNames.stream()
.anyMatch(
name -> {
if (regex.startsWith("/") && regex.endsWith("/")) {
String trimmedRegex = regex.substring(1, regex.length() - 1);
return Pattern.matches(trimmedRegex, name);
}
return false;
}));
return missedTestNames;
}

Expand Down
8 changes: 8 additions & 0 deletions testng-core/src/test/java/org/testng/xml/XmlTestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public void testNameMatchesAny() {
assertThat(xmlTest.nameMatchesAny(Collections.singletonList("test2"))).isFalse();
}

@Test(description = "GITHUB-3196")
public void testNameMatchesAnyWithRegex() {
XmlSuite xmlSuite = createDummySuiteWithTestNamesAs("test1");
XmlTest xmlTest = xmlSuite.getTests().get(0);
assertThat(xmlTest.nameMatchesAny(Collections.singletonList("/^(test1$).*/"))).isTrue();
assertThat(xmlTest.nameMatchesAny(Collections.singletonList("/^(?!test1$).*/"))).isFalse();
}

@Test(dataProvider = "dp", description = "GITHUB-1716")
public void testNullOrEmptyParameter(Map<String, String> data) {
XmlTest test = createXmlTest("suite", "test", Issue1716TestSample.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,27 @@ public void testOverrideExcludedMethodsSuiteExclusions() {
verifyTests("Failed", failed, tla.getFailedTests());
}

@Test(description = "GITHUB-2407")
public void testSpecificTestNamesWithRegexCommandLineExclusions() {
String[] args =
new String[] {
"src/test/resources/testnames/main-suite.xml",
"-log",
"0",
"-d",
OutputDirectoryPatch.getOutputDirectory(),
"-testnames",
"/^testGroup1.*/"
};

TestNG.privateMain(args, tla);

String[] passed = {"sampleOutputTest1"};
String[] failed = {};
verifyTests("Passed", passed, tla.getPassedTests());
verifyTests("Failed", failed, tla.getFailedTests());
}

private void verifyTests(String title, String[] expected, List<ITestResult> found) {

Assertions.assertThat(found.stream().map(ITestResult::getName).toArray(String[]::new))
Expand Down
Loading