File tree Expand file tree Collapse file tree
testng-core-api/src/main/java/org/testng/xml
main/java/org/testng/xml/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ Fixed: GITHUB-3122: Update JCommander to 1.83 (Antoine Dessaigne)
66Fixed: 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)
77Fixed: GITHUB-3140: assertEqualsDeep on Sets - Deep comparison was using the wrong expected value
88Fixed: GITHUB-3189: Incorrect number of ignored tests displayed in the XML results
9+ Fixed: GITHUB-3196: support to execlude somes tests in option of command line
910
10117.10.2
1112Fixed: GITHUB-3117: ListenerComparator doesn't work (Krishnan Mahadevan)
Original file line number Diff line number Diff line change @@ -142,4 +142,4 @@ gpg: Good signature from "Krishnan Mahadevan (krmahadevan-key) <krishnan.mahadev
142142For more details regarding keys please refer:
143143
144144* [Verifying Signature](https://infra.apache.org/release-signing.html#verifying-signature)
145- * [How to Trust Imported GPG Keys](https://classroom.anir0y.in/post/blog-how-to-trust-imported-gpg-keys/)
145+ * [How to Trust Imported GPG Keys](https://classroom.anir0y.in/post/blog-how-to-trust-imported-gpg-keys/)
Original file line number Diff line number Diff line change 11package org .testng .xml ;
22
33import java .util .*;
4+ import java .util .regex .Pattern ;
45import org .testng .TestNGException ;
56import org .testng .collections .Lists ;
67import org .testng .collections .Maps ;
@@ -624,6 +625,15 @@ public XmlGroups getXmlGroups() {
624625 * @return <code>true</code> if the current test's name matches with any of the given names.
625626 */
626627 public boolean nameMatchesAny (List <String > names ) {
627- return names .contains (getName ());
628+ return names .contains (getName ())
629+ || names .stream ()
630+ .anyMatch (
631+ regex -> {
632+ if (regex .startsWith ("/" ) && regex .endsWith ("/" )) {
633+ String trimmedRegex = regex .substring (1 , regex .length () - 1 );
634+ return Pattern .matches (trimmedRegex , getName ());
635+ }
636+ return false ;
637+ });
628638 }
629639}
Original file line number Diff line number Diff line change 11package org .testng .xml .internal ;
22
33import java .util .List ;
4+ import java .util .regex .Pattern ;
45import org .testng .TestNGException ;
56import org .testng .collections .Lists ;
67import org .testng .log4testng .Logger ;
@@ -89,7 +90,18 @@ public boolean validateMissMatchedTestNames() {
8990 public List <String > getMissedTestNames () {
9091 List <String > missedTestNames = Lists .newArrayList ();
9192 missedTestNames .addAll (testNames );
92- missedTestNames .removeIf (matchedTestNames ::contains );
93+ missedTestNames .removeIf (
94+ regex ->
95+ matchedTestNames .contains (regex )
96+ || matchedTestNames .stream ()
97+ .anyMatch (
98+ name -> {
99+ if (regex .startsWith ("/" ) && regex .endsWith ("/" )) {
100+ String trimmedRegex = regex .substring (1 , regex .length () - 1 );
101+ return Pattern .matches (trimmedRegex , name );
102+ }
103+ return false ;
104+ }));
93105 return missedTestNames ;
94106 }
95107
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ public void testNameMatchesAny() {
2020 assertThat (xmlTest .nameMatchesAny (Collections .singletonList ("test2" ))).isFalse ();
2121 }
2222
23+ @ Test (description = "GITHUB-3196" )
24+ public void testNameMatchesAnyWithRegex () {
25+ XmlSuite xmlSuite = createDummySuiteWithTestNamesAs ("test1" );
26+ XmlTest xmlTest = xmlSuite .getTests ().get (0 );
27+ assertThat (xmlTest .nameMatchesAny (Collections .singletonList ("/^(test1$).*/" ))).isTrue ();
28+ assertThat (xmlTest .nameMatchesAny (Collections .singletonList ("/^(?!test1$).*/" ))).isFalse ();
29+ }
30+
2331 @ Test (dataProvider = "dp" , description = "GITHUB-1716" )
2432 public void testNullOrEmptyParameter (Map <String , String > data ) {
2533 XmlTest test = createXmlTest ("suite" , "test" , Issue1716TestSample .class );
Original file line number Diff line number Diff line change @@ -170,6 +170,27 @@ public void testOverrideExcludedMethodsSuiteExclusions() {
170170 verifyTests ("Failed" , failed , tla .getFailedTests ());
171171 }
172172
173+ @ Test (description = "GITHUB-2407" )
174+ public void testSpecificTestNamesWithRegexCommandLineExclusions () {
175+ String [] args =
176+ new String [] {
177+ "src/test/resources/testnames/main-suite.xml" ,
178+ "-log" ,
179+ "0" ,
180+ "-d" ,
181+ OutputDirectoryPatch .getOutputDirectory (),
182+ "-testnames" ,
183+ "/^testGroup1.*/"
184+ };
185+
186+ TestNG .privateMain (args , tla );
187+
188+ String [] passed = {"sampleOutputTest1" };
189+ String [] failed = {};
190+ verifyTests ("Passed" , passed , tla .getPassedTests ());
191+ verifyTests ("Failed" , failed , tla .getFailedTests ());
192+ }
193+
173194 private void verifyTests (String title , String [] expected , List <ITestResult > found ) {
174195
175196 Assertions .assertThat (found .stream ().map (ITestResult ::getName ).toArray (String []::new ))
You can’t perform that action at this time.
0 commit comments