From 7eb50bc1d446fdd287a486370608f4861f92294c Mon Sep 17 00:00:00 2001 From: enztngh Date: Thu, 26 Dec 2024 10:58:57 +0800 Subject: [PATCH 1/7] test --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6bad5f205..6049587db 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Sonarqube Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=org.testng%3Atestng&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.testng%3Atestng) Documentation available at [TestNG's main web site](https://testng.org). Visit [TestNG Documentation's GitHub Repo](https://github.com/testng-team/testng-team.github.io) to contribute to it. - +### ### Release Notes * [7.10.0](https://groups.google.com/g/testng-users/c/6DmFaKUjIxY) * [7.9.0](https://groups.google.com/g/testng-users/c/nN7LkuZWO48) @@ -142,4 +142,4 @@ gpg: Good signature from "Krishnan Mahadevan (krmahadevan-key) Date: Thu, 2 Jan 2025 15:05:02 +0800 Subject: [PATCH 2/7] GITHUB-3196:support regex for testnames option of command line --- testng-core-api/src/main/java/org/testng/xml/XmlTest.java | 3 ++- .../java/org/testng/xml/internal/TestNamesMatcher.java | 8 +++++--- testng-core/src/test/java/org/testng/xml/XmlTestTest.java | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java index 9df4e7e8d..372c65e73 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java @@ -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; @@ -624,6 +625,6 @@ public XmlGroups getXmlGroups() { * @return true if the current test's name matches with any of the given names. */ public boolean nameMatchesAny(List names) { - return names.contains(getName()); + return names.stream().allMatch(regex -> Pattern.matches(regex, getName())); } } diff --git a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java index 507f35869..a0f1a5845 100644 --- a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java +++ b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java @@ -21,6 +21,8 @@ public final class TestNamesMatcher { private final List cloneSuites = Lists.newArrayList(); private final List matchedTestNames = Lists.newArrayList(); private final List matchedTests = Lists.newArrayList(); + private final List missedTestNames = Lists.newArrayList(); + private final List missedTests = Lists.newArrayList(); private final List testNames; private final boolean ignoreMissedTestNames; @@ -87,9 +89,6 @@ public boolean validateMissMatchedTestNames() { } public List getMissedTestNames() { - List missedTestNames = Lists.newArrayList(); - missedTestNames.addAll(testNames); - missedTestNames.removeIf(matchedTestNames::contains); return missedTestNames; } @@ -110,6 +109,9 @@ private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny(XmlSuite suite) { tests.add(xt); matchedTestNames.add(xt.getName()); matchedTests.add(xt); + }else{ + missedTestNames.add(xt.getName()); + missedTests.add(xt); } } if (tests.isEmpty()) { diff --git a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java index 3fd1a9cc3..b2c06498c 100644 --- a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java +++ b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java @@ -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 data) { XmlTest test = createXmlTest("suite", "test", Issue1716TestSample.class); From f898bee819fb16bb4e8f5738aab113423e6948d9 Mon Sep 17 00:00:00 2001 From: enztngh Date: Thu, 2 Jan 2025 15:12:38 +0800 Subject: [PATCH 3/7] GITHUB-3196: support to execlude somes 'test' in option of command line --- CHANGES.txt | 1 + README.md | 1 - .../src/main/java/org/testng/xml/internal/TestNamesMatcher.java | 2 +- testng-core/src/test/java/org/testng/xml/XmlTestTest.java | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7c9edb612..381eb188f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 'test' in option of command line 7.10.2 Fixed: GITHUB-3117: ListenerComparator doesn't work (Krishnan Mahadevan) diff --git a/README.md b/README.md index 6049587db..956ecf134 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![Sonarqube Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=org.testng%3Atestng&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.testng%3Atestng) Documentation available at [TestNG's main web site](https://testng.org). Visit [TestNG Documentation's GitHub Repo](https://github.com/testng-team/testng-team.github.io) to contribute to it. -### ### Release Notes * [7.10.0](https://groups.google.com/g/testng-users/c/6DmFaKUjIxY) * [7.9.0](https://groups.google.com/g/testng-users/c/nN7LkuZWO48) diff --git a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java index a0f1a5845..5c781279f 100644 --- a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java +++ b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java @@ -109,7 +109,7 @@ private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny(XmlSuite suite) { tests.add(xt); matchedTestNames.add(xt.getName()); matchedTests.add(xt); - }else{ + } else { missedTestNames.add(xt.getName()); missedTests.add(xt); } diff --git a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java index b2c06498c..7129cd0ef 100644 --- a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java +++ b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java @@ -21,7 +21,7 @@ public void testNameMatchesAny() { } @Test(description = "GITHUB-3196") - public void testNameMatchesAnyWithRegex(){ + public void testNameMatchesAnyWithRegex() { XmlSuite xmlSuite = createDummySuiteWithTestNamesAs("test1"); XmlTest xmlTest = xmlSuite.getTests().get(0); assertThat(xmlTest.nameMatchesAny(Collections.singletonList("^(test1$).*"))).isTrue(); From adb5ca2a130fb387bcd7243ef3520131778f66cc Mon Sep 17 00:00:00 2001 From: enztngh Date: Mon, 6 Jan 2025 10:43:41 +0800 Subject: [PATCH 4/7] GITHUB-3196: support to execlude somes 'test' in option of command line --- README.md | 13 +++++++------ .../src/main/java/org/testng/xml/XmlTest.java | 2 +- .../org/testng/xml/internal/TestNamesMatcher.java | 12 +++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 956ecf134..7b0a81524 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Sonarqube Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=org.testng%3Atestng&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.testng%3Atestng) Documentation available at [TestNG's main web site](https://testng.org). Visit [TestNG Documentation's GitHub Repo](https://github.com/testng-team/testng-team.github.io) to contribute to it. + ### Release Notes * [7.10.0](https://groups.google.com/g/testng-users/c/6DmFaKUjIxY) * [7.9.0](https://groups.google.com/g/testng-users/c/nN7LkuZWO48) @@ -39,7 +40,7 @@ Always make sure your issue is happening on the latest TestNG version. Bug repor ### Have you considered sending a pull request instead of filing an issue? The best way to report a bug is to provide the TestNG team with a full test case reproducing the issue. -Maybe you can write a runnable test case (check the `src/test/` folder for examples) and propose it in a pull request +Maybe you can write a runnable test case (check the `src/test/` folder for examples) and propose it in a pull request Don't worry if the CI fails because it is the expected behavior. This pull request will be a perfect start to find the fix :) @@ -48,12 +49,12 @@ Refer our [Contributing](.github/CONTRIBUTING.md) section for detailed set of st ### We encourage pull requests that: - * Add new features to TestNG (or) - * Fix bugs in TestNG +* Add new features to TestNG (or) +* Fix bugs in TestNG + +If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the +[TestNG-dev](https://groups.google.com/forum/#!forum/testng-dev) before you spend time working on it. - If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the - [TestNG-dev](https://groups.google.com/forum/#!forum/testng-dev) before you spend time working on it. - ### GPG Keys #### Getting the keys diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java index 372c65e73..649239696 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java @@ -625,6 +625,6 @@ public XmlGroups getXmlGroups() { * @return true if the current test's name matches with any of the given names. */ public boolean nameMatchesAny(List names) { - return names.stream().allMatch(regex -> Pattern.matches(regex, getName())); + return names.stream().anyMatch(regex -> Pattern.matches(regex, getName())); } } diff --git a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java index 5c781279f..a0af9147b 100644 --- a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java +++ b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java @@ -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; @@ -21,8 +22,6 @@ public final class TestNamesMatcher { private final List cloneSuites = Lists.newArrayList(); private final List matchedTestNames = Lists.newArrayList(); private final List matchedTests = Lists.newArrayList(); - private final List missedTestNames = Lists.newArrayList(); - private final List missedTests = Lists.newArrayList(); private final List testNames; private final boolean ignoreMissedTestNames; @@ -89,6 +88,12 @@ public boolean validateMissMatchedTestNames() { } public List getMissedTestNames() { + List missedTestNames = Lists.newArrayList(); + missedTestNames.addAll(testNames); + missedTestNames.removeIf(regex -> + matchedTestNames.stream() + .anyMatch(testName -> Pattern.matches(regex, testName)) + ); return missedTestNames; } @@ -109,9 +114,6 @@ private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny(XmlSuite suite) { tests.add(xt); matchedTestNames.add(xt.getName()); matchedTests.add(xt); - } else { - missedTestNames.add(xt.getName()); - missedTests.add(xt); } } if (tests.isEmpty()) { From bab0de4543e9ab2f78c02438ce3f14a43053f9cc Mon Sep 17 00:00:00 2001 From: enztngh Date: Mon, 6 Jan 2025 10:54:02 +0800 Subject: [PATCH 5/7] GITHUB-3196: support to execlude somes 'test' in option of command line --- .../main/java/org/testng/xml/internal/TestNamesMatcher.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java index a0af9147b..4333d4334 100644 --- a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java +++ b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java @@ -90,10 +90,8 @@ public boolean validateMissMatchedTestNames() { public List getMissedTestNames() { List missedTestNames = Lists.newArrayList(); missedTestNames.addAll(testNames); - missedTestNames.removeIf(regex -> - matchedTestNames.stream() - .anyMatch(testName -> Pattern.matches(regex, testName)) - ); + missedTestNames.removeIf( + regex -> matchedTestNames.stream().anyMatch(testName -> Pattern.matches(regex, testName))); return missedTestNames; } From 568bfb66ce15ab311fc05636260ae24cb8da81ed Mon Sep 17 00:00:00 2001 From: YutingZhang-A Date: Mon, 6 Jan 2025 10:58:59 +0800 Subject: [PATCH 6/7] revert update of README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7b0a81524..e1caa10d5 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Always make sure your issue is happening on the latest TestNG version. Bug repor ### Have you considered sending a pull request instead of filing an issue? The best way to report a bug is to provide the TestNG team with a full test case reproducing the issue. -Maybe you can write a runnable test case (check the `src/test/` folder for examples) and propose it in a pull request +Maybe you can write a runnable test case (check the `src/test/` folder for examples) and propose it in a pull request Don't worry if the CI fails because it is the expected behavior. This pull request will be a perfect start to find the fix :) @@ -49,12 +49,12 @@ Refer our [Contributing](.github/CONTRIBUTING.md) section for detailed set of st ### We encourage pull requests that: -* Add new features to TestNG (or) -* Fix bugs in TestNG - -If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the -[TestNG-dev](https://groups.google.com/forum/#!forum/testng-dev) before you spend time working on it. + * Add new features to TestNG (or) + * Fix bugs in TestNG + If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the + [TestNG-dev](https://groups.google.com/forum/#!forum/testng-dev) before you spend time working on it. + ### GPG Keys #### Getting the keys From c5b8bb19452c257f4940b7af986dea190219925b Mon Sep 17 00:00:00 2001 From: enztngh Date: Thu, 9 Jan 2025 15:10:14 +0800 Subject: [PATCH 7/7] GITHUB-3196: support to execlude somes 'test' in option of command line --- CHANGES.txt | 2 +- .../src/main/java/org/testng/xml/XmlTest.java | 11 +++++++++- .../testng/xml/internal/TestNamesMatcher.java | 12 ++++++++++- .../test/java/org/testng/xml/XmlTestTest.java | 4 ++-- .../test/methodselectors/CommandLineTest.java | 21 +++++++++++++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 381eb188f..909824763 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,7 +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 'test' in option of command line +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) diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java index 649239696..3343bda19 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java @@ -625,6 +625,15 @@ public XmlGroups getXmlGroups() { * @return true if the current test's name matches with any of the given names. */ public boolean nameMatchesAny(List names) { - return names.stream().anyMatch(regex -> Pattern.matches(regex, 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; + }); } } diff --git a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java index 4333d4334..253ef47d3 100644 --- a/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java +++ b/testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java @@ -91,7 +91,17 @@ public List getMissedTestNames() { List missedTestNames = Lists.newArrayList(); missedTestNames.addAll(testNames); missedTestNames.removeIf( - regex -> matchedTestNames.stream().anyMatch(testName -> Pattern.matches(regex, testName))); + 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; } diff --git a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java index 7129cd0ef..d5f06c5ab 100644 --- a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java +++ b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java @@ -24,8 +24,8 @@ public void testNameMatchesAny() { 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(); + assertThat(xmlTest.nameMatchesAny(Collections.singletonList("/^(test1$).*/"))).isTrue(); + assertThat(xmlTest.nameMatchesAny(Collections.singletonList("/^(?!test1$).*/"))).isFalse(); } @Test(dataProvider = "dp", description = "GITHUB-1716") diff --git a/testng-core/src/test/java/test/methodselectors/CommandLineTest.java b/testng-core/src/test/java/test/methodselectors/CommandLineTest.java index fcffea3ab..e6dee8263 100644 --- a/testng-core/src/test/java/test/methodselectors/CommandLineTest.java +++ b/testng-core/src/test/java/test/methodselectors/CommandLineTest.java @@ -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 found) { Assertions.assertThat(found.stream().map(ITestResult::getName).toArray(String[]::new))