RequireApiProfileAttribute.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. using NUnit.Framework.Interfaces;
  5. using NUnit.Framework.Internal;
  6. namespace UnityEditor.TestTools
  7. {
  8. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
  9. internal class RequireApiProfileAttribute : NUnitAttribute, IApplyToTest
  10. {
  11. public ApiCompatibilityLevel[] apiProfiles { get; private set; }
  12. public RequireApiProfileAttribute(params ApiCompatibilityLevel[] apiProfiles)
  13. {
  14. this.apiProfiles = apiProfiles;
  15. }
  16. void IApplyToTest.ApplyToTest(Test test)
  17. {
  18. test.Properties.Add(PropertyNames.Category, string.Format("ApiProfile({0})", string.Join(", ", apiProfiles.Select(p => p.ToString()).OrderBy(p => p).ToArray())));
  19. ApiCompatibilityLevel testProfile = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup);
  20. if (!apiProfiles.Contains(testProfile))
  21. {
  22. string skipReason = "Skipping test as it requires a compatible api profile set: " + string.Join(", ", apiProfiles.Select(p => p.ToString()).ToArray());
  23. test.RunState = RunState.Skipped;
  24. test.Properties.Add(PropertyNames.SkipReason, skipReason);
  25. }
  26. }
  27. }
  28. }