Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

EmbeddedPackageOnlyTestAttribute.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using NUnit.Framework;
  3. using NUnit.Framework.Interfaces;
  4. using NUnit.Framework.Internal;
  5. namespace Unity.Collections.Tests
  6. {
  7. #if UNITY_DOTSRUNTIME
  8. // Always ignore these tests
  9. internal class EmbeddedPackageOnlyTestAttribute : IgnoreAttribute {
  10. public EmbeddedPackageOnlyTestAttribute() : base("Only runs in the editor when this package is embedded or referenced locally.")
  11. {
  12. }
  13. }
  14. #else
  15. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
  16. internal class EmbeddedPackageOnlyTestAttribute : NUnitAttribute, IApplyToTest
  17. {
  18. public void ApplyToTest(Test test)
  19. {
  20. #if UNITY_EDITOR
  21. var assembly = test.Method?.TypeInfo?.Assembly ?? test.TypeInfo?.Assembly;
  22. if (assembly == null)
  23. {
  24. UnityEngine.Debug.LogError($"The {nameof(EmbeddedPackageOnlyTestAttribute)} attribute can only be applied to tests in an assembly.");
  25. return;
  26. }
  27. var package = UnityEditor.PackageManager.PackageInfo.FindForAssembly(assembly);
  28. if (package == null)
  29. {
  30. UnityEngine.Debug.LogError(
  31. $"The {nameof(EmbeddedPackageOnlyTestAttribute)} attribute can only be applied to tests in a package.");
  32. return;
  33. }
  34. if (package.source == UnityEditor.PackageManager.PackageSource.Embedded ||
  35. package.source == UnityEditor.PackageManager.PackageSource.Local)
  36. return;
  37. #endif
  38. test.RunState = RunState.Ignored;
  39. test.Properties.Add(PropertyNames.SkipReason, "Only runs in the editor when this package is embedded or referenced locally.");
  40. }
  41. }
  42. #endif
  43. }