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

Conversation

YutingZhang-A
Copy link
Contributor

@YutingZhang-A YutingZhang-A commented Jan 2, 2025

Fixes #3196 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

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 before you spend time working on it.

Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.

Summary by CodeRabbit

  • New Features

    • Added support to exclude certain tests from command line options (GITHUB-3196)
    • Enhanced test name matching with regex support
  • Bug Fixes

    • Corrected calculation of 'invocation-numbers' in testng-failed.xml
    • Fixed issues with data providers and success percentage
    • Resolved execution stalls with global thread pool
    • Corrected deep comparison for Sets
    • Fixed display of ignored tests in XML results
  • Documentation

    • Added reference for GPG key trust in README
  • Improvements

    • Updated JCommander library to version 1.83
    • Enhanced assertEquals for arrays with index information

Copy link

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces enhancements to TestNG's test name matching functionality, focusing on providing more flexible regex-based test name selection. The changes primarily involve modifying the nameMatchesAny method in XmlTest to support regular expression matching, updating related test matching logic, and adding new test methods to validate the regex functionality. This update aims to improve the granularity of test selection through command-line options.

Changes

File Change Summary
CHANGES.txt Updated with version 7.11.0 changes, including bug fixes and new feature support for excluding tests via command line
README.md Added reference link for "How to Trust Imported GPG Keys"
testng-core-api/src/main/java/org/testng/xml/XmlTest.java Replaced test name matching with regex-based pattern matching
testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java Updated test name matching logic to use regex patterns
testng-core/src/test/java/org/testng/xml/XmlTestTest.java Added new test method testNameMatchesAnyWithRegex to validate regex functionality
testng-core/src/test/java/test/methodselectors/CommandLineTest.java Added new test method testSpecificTestNamesWithRegexCommandLineExclusions for regex command line exclusions

Assessment against linked issues

Objective Addressed Explanation
Support regex-based test exclusion [#3196]
Allow complex test name filtering
Maintain existing testnames parameter functionality

Poem

🐰 In the realm of TestNG's might,
Regex dances with test's delight,
Patterns weave through command's embrace,
Filtering tests with elegant grace,
A rabbit's code, both smart and light! 🧪

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

@YutingZhang-A YutingZhang-A marked this pull request as ready for review January 6, 2025 07:29
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
testng-core/src/test/java/org/testng/xml/XmlTestTest.java (1)

23-29: Consider providing additional regex edge cases in tests
These tests only cover a basic pattern match and a negative pattern. It may be useful to add more boundary scenarios (like empty regex patterns, special character sets, or capturing groups) to ensure broader validation of the matching logic.

testng-core-api/src/main/java/org/testng/xml/XmlTest.java (1)

628-628: Document implications of regex-based matching
While regex-based matching offers flexibility, it can introduce subtle pitfalls if the user expects literal matching. A brief javadoc note clarifying that wildcard or partial matches are possible might help avoid confusion.

CHANGES.txt (1)

9-9: Correct typographical errors in release note
There's a misspelling ("execlude somes 'test'"). Consider correcting it to something like "exclude some tests" for clarity and consistency with the rest of the release notes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 078c1e3 and 568bfb6.

📒 Files selected for processing (5)
  • CHANGES.txt (1 hunks)
  • README.md (1 hunks)
  • testng-core-api/src/main/java/org/testng/xml/XmlTest.java (2 hunks)
  • testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java (2 hunks)
  • testng-core/src/test/java/org/testng/xml/XmlTestTest.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
🔇 Additional comments (2)
testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java (1)

93-94: Validate performance of regex matching on large test name sets
Although regex provides flexibility, it can be slower on large collections. Verify that performance is acceptable, especially in scenarios with numerous test names or frequent calls to getMissedTestNames.

testng-core-api/src/main/java/org/testng/xml/XmlTest.java (1)

4-4: Ensure consistent usage of java.util.regex.Pattern
Importing Pattern suggests usage of regex logic within the class. Just confirm that the rest of the class interacts properly without overshadowing simpler checks.

Copy link
Member

@krmahadevan krmahadevan left a comment

Choose a reason for hiding this comment

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

Can you please help a test that checks this functionality when the test name is passed as a parameter via the Command line argument approach ?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
testng-core/src/test/java/test/methodselectors/CommandLineTest.java (1)

173-192: Enhance test coverage and fix issue reference.

The test description references GITHUB-2407 but this test appears to be verifying functionality for GITHUB-3196 (support to exclude tests in command line options).

Consider:

  1. Updating the description to reference the correct issue: GITHUB-3196
  2. Adding assertions to verify that tests not matching the regex pattern were excluded
  3. Adding more test cases with different regex patterns to improve coverage
-  @Test(description = "GITHUB-2407")
+  @Test(description = "GITHUB-3196")
   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 = {};
+    String[] skipped = {"testGroup2Test1", "testGroup2Test2"}; // Add verification for excluded tests
     verifyTests("Passed", passed, tla.getPassedTests());
     verifyTests("Failed", failed, tla.getFailedTests());
+    verifyTests("Skipped", skipped, tla.getSkippedTests());
   }
testng-core-api/src/main/java/org/testng/xml/XmlTest.java (1)

628-637: Optimize regex pattern compilation and add error handling.

The current implementation compiles the regex pattern on every match. For better performance and error handling:

Consider:

   public boolean nameMatchesAny(List<String> names) {
     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());
+                    try {
+                      Pattern pattern = Pattern.compile(trimmedRegex);
+                      return pattern.matcher(getName()).matches();
+                    } catch (java.util.regex.PatternSyntaxException e) {
+                      throw new TestNGException("Invalid regex pattern: " + regex, e);
+                    }
                   }
                   return false;
                 });
   }
CHANGES.txt (1)

9-9: Enhance change log entry with more details.

The current entry "Fixed: GITHUB-3196: support to execlude somes tests in option of command line" has typos and lacks details about the feature.

Consider updating to:

-Fixed: GITHUB-3196: support to execlude somes tests in option of command line
+Fixed: GITHUB-3196: Support excluding tests using regex patterns in command line options. Tests can now be excluded using patterns like "/^pattern.*/" in the -testnames option.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 568bfb6 and c5b8bb1.

📒 Files selected for processing (5)
  • CHANGES.txt (1 hunks)
  • testng-core-api/src/main/java/org/testng/xml/XmlTest.java (2 hunks)
  • testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java (2 hunks)
  • testng-core/src/test/java/org/testng/xml/XmlTestTest.java (1 hunks)
  • testng-core/src/test/java/test/methodselectors/CommandLineTest.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • testng-core/src/main/java/org/testng/xml/internal/TestNamesMatcher.java
  • testng-core/src/test/java/org/testng/xml/XmlTestTest.java
🔇 Additional comments (1)
testng-core-api/src/main/java/org/testng/xml/XmlTest.java (1)

4-4: LGTM!

The import for Pattern is appropriate for the new regex functionality.

@YutingZhang-A
Copy link
Contributor Author

Can you please help a test that checks this functionality when the test name is passed as a parameter via the Command line argument approach ?

Hi,
I am not sure I understand correctly, I added a test in testng-core/src/test/java/test/methodselectors/CommandLineTest.java. is it enough?
Because this is my first time contributing testng code, I'm not sure what needs to be done. If there's anything else I need to do, please let me know.
BR//Yuting

@juherr juherr merged commit e162179 into testng-team:master Jan 9, 2025
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support to execlude somes 'test' in option of command line
3 participants