Skip to content

Analyzer-Idea: Un/SupportedOSPlatformAttribute should be consistent with OSConditionAttribute #11018

Description

Summary

CA1416 Helps with identifying platform-API problems. If you decorate a TestMethod/Class with another Un/SupportedOSPlatformAttribute, CA1416 is happy, but the test still runs via MsTest

Background and Motivation

the Attributes are the "correct way"

Proposed Feature

Analyzer+CodeFix who finds dependencies like this:

[SupportedOSPlatform("linux")] -> [OSCondition(OperatingSystems.Linux)]
[UnupportedOSPlatform("linux")] -> [OSCondition(ConditionMode.Exclude, OperatingSystems.Linux)]

in my short thought process, this 1-to-1 mapping should work. But OSCondition is AllowMultiple=False. so there needs to be some clever thinking, or just some restrictions, ie only-exclude or only-include

[SupportedOSPlatform("linux"), SupportedOSPlatform("OSX")] -> [OSCondition(OperatingSystems.Linux | OperatingSystems.OSX)]
[SupportedOSPlatform("linux"), UnsupportedOSPlatform("OSX")] -> can't compute codefix, unless you read containg symbols attributes (class/assembly)

  • also, consider the SupportedOSPlatformAttributes may contain a version a la "windows10.0".
  • Analyzer should also check existing pairs, so that something like this can't happen:
    • [SupportedOSPlatform("windows"), OSCondition(OperatingSystems.Linux)]

Alternative Designs

respect SupportedOSPlatformAttribute in MsTest

  • bad, because then OSConditionAttributes are invalid on the same method/class

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/analyzersMSTest.Analyzers Roslyn analyzers and code fixes.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions