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

[dotnet] Fix current version of IgnoreTargetAttribute in test suite #15051

Merged

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Jan 9, 2025

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix, Enhancement


Description

  • Refactored IgnoreTargetAttribute class for improved clarity and maintainability.

  • Added nullability annotations to enhance code safety and modernize the implementation.

  • Simplified logic for applying test ignore attributes and improved platform matching.

  • Updated platform detection logic to support net8 and added compile-time error for unsupported platforms.


Changes walkthrough 📝

Relevant files
Enhancement
IgnoreTargetAttribute.cs
Refactored and enhanced `IgnoreTargetAttribute` class       

dotnet/test/common/CustomTestAttributes/IgnoreTargetAttribute.cs

  • Refactored IgnoreTargetAttribute to use auto-properties.
  • Improved logic for applying test ignore attributes.
  • Added nullability annotations for better code safety.
  • Updated platform detection logic to support net8.
  • +34/-49 

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Jan 9, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Incorrect Skip Reason

    The skip reason property is set to platformToIgnoreAttr.Reason instead of the constructed ignoreReason string that includes both the browser and custom reason

    test.RunState = RunState.Ignored;
    test.Properties.Set(PropertyNames.SkipReason, ignoreReason);
    Platform Check

    The platform check logic assumes only NET8_0 target framework, but should handle other supported .NET versions or provide clear error handling for unsupported versions

    #if NET8_0
                return "net8";
    #else
    #error Update IgnoreTargetAttribute.CurrentPlatform to the current TFM
    #endif

    Copy link
    Contributor

    qodo-merge-pro bot commented Jan 9, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add parameter validation to prevent null reference exceptions

    Add null check for test parameter in ApplyToTest method to prevent potential
    NullReferenceException.

    dotnet/test/common/CustomTestAttributes/IgnoreTargetAttribute.cs [48-53]

     public void ApplyToTest(Test test)
     {
    +    if (test == null)
    +    {
    +        throw new ArgumentNullException(nameof(test));
    +    }
         if (test.RunState is RunState.NotRunnable)
         {
             return;
         }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding null parameter validation is crucial for preventing runtime errors and maintaining robust code. This is particularly important for public API methods like ApplyToTest.

    8
    Add constructor parameter validation to prevent null reference exceptions

    Add null check for target parameter in constructor to prevent potential issues with
    null values being passed.

    dotnet/test/common/CustomTestAttributes/IgnoreTargetAttribute.cs [33-36]

     public IgnoreTargetAttribute(string target)
     {
    +    if (target == null)
    +    {
    +        throw new ArgumentNullException(nameof(target));
    +    }
         this.Value = target.ToLower();
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding null parameter validation in the constructor is essential for preventing runtime errors, especially since the code immediately calls ToLower() on the parameter which would throw if null.

    8

    Copy link
    Member

    @nvborisenko nvborisenko left a comment

    Choose a reason for hiding this comment

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

    Thanks @RenderMichael !

    @nvborisenko nvborisenko merged commit 85b8164 into SeleniumHQ:trunk Jan 9, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the ignore-target-attribute branch January 9, 2025 16:38
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants