generated from vrchat-community/template-package
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5aeab25
commit 05c9a7e
Showing
8 changed files
with
225 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace nadena.dev.ndmf | ||
{ | ||
/// <summary> | ||
/// This attribute declares a pass or an extension context to depend on another context. | ||
/// When an extension context depends on another, it will implicitly activate the other context whenever the | ||
/// depending context is activated. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
public sealed class DependsOnContext : Attribute | ||
{ | ||
public Type ExtensionContext { get; } | ||
|
||
public DependsOnContext(Type extensionContext) | ||
{ | ||
ExtensionContext = extensionContext; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
UnitTests~/PluginResolverTests/ExtensionDependenciesTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Linq; | ||
using nadena.dev.ndmf; | ||
using NUnit.Framework; | ||
|
||
namespace UnitTests.PluginResolverTests | ||
{ | ||
[DependsOnContext(typeof(Ctx3))] | ||
[DependsOnContext(typeof(Ctx2))] | ||
public class Ctx1 : IExtensionContext | ||
{ | ||
public void OnActivate(BuildContext context) | ||
{ | ||
|
||
} | ||
|
||
public void OnDeactivate(BuildContext context) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class Ctx2 : IExtensionContext | ||
{ | ||
public void OnActivate(BuildContext context) | ||
{ | ||
|
||
} | ||
|
||
public void OnDeactivate(BuildContext context) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class Ctx3 : IExtensionContext | ||
{ | ||
public void OnActivate(BuildContext context) | ||
{ | ||
|
||
} | ||
|
||
public void OnDeactivate(BuildContext context) | ||
{ | ||
|
||
} | ||
} | ||
|
||
[DependsOnContext(typeof(Ctx1))] | ||
public class Pass1 : Pass<Pass1> | ||
{ | ||
protected override void Execute(BuildContext context) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class Plugin1 : Plugin<Plugin1> | ||
{ | ||
protected override void Configure() | ||
{ | ||
InPhase(BuildPhase.Generating) | ||
.Run(Pass1.Instance) | ||
.Then.WithCompatibleExtension(typeof(Ctx1), seq => | ||
{ | ||
seq.Run("test test", _ => { }); | ||
}); | ||
} | ||
} | ||
|
||
public class ExtensionDependenciesTest | ||
{ | ||
[Test] | ||
public void AssertCorrectPassDependencies() | ||
{ | ||
var resolver = new PluginResolver(new[] { typeof(Plugin1) }); | ||
|
||
var phase = resolver.Passes.First(p => p.Item1 == BuildPhase.Generating).Item2; | ||
var pass1 = phase.First(pass => pass.InstantiatedPass is Pass1); | ||
|
||
Assert.That(pass1.ActivatePlugins, Is.EquivalentTo(new[] { typeof(Ctx2), typeof(Ctx3), typeof(Ctx1) })); | ||
Assert.That(pass1.DeactivatePlugins, Is.Empty); | ||
|
||
var pass2 = phase.First(pass => pass.InstantiatedPass.DisplayName == "test test"); | ||
Assert.That(pass2.ActivatePlugins.IsEmpty); | ||
Assert.That(pass2.DeactivatePlugins.IsEmpty); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
UnitTests~/PluginResolverTests/ExtensionDependenciesTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.