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