Skip to content

Commit

Permalink
Fix NEEDS checking for inner nodes/values
Browse files Browse the repository at this point in the history
Didn't work if you had both top level NEEDS and NEEDS on a subnode/value
since it was checking NEEDS on the wrong node in that case
  • Loading branch information
blowfishpro committed Dec 6, 2017
1 parent 1347768 commit 60171d9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ModuleManager/NeedsChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public static void CheckNeeds(UrlDir gameDatabaseRoot, IEnumerable<string> mods,
}

// Recursively check the contents
PatchContext context = new PatchContext(mod, gameDatabaseRoot, logger, progress);
CheckNeeds(new NodeStack(mod.config), context, mods);
PatchContext context = new PatchContext(currentMod, gameDatabaseRoot, logger, progress);
CheckNeeds(new NodeStack(currentMod.config), context, mods);
}
catch (Exception ex)
{
try
{
progress.Exception(currentMod, "Exception while checking needs on root node :\n" + currentMod.PrettyPrint(), ex);
progress.Exception(mod, "Exception while checking needs on root node :\n" + mod.PrettyPrint(), ex);
}
catch (Exception ex2)
{
Expand Down
52 changes: 52 additions & 0 deletions ModuleManagerTests/NeedsCheckerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using ModuleManager;
using ModuleManager.Logging;
using ModuleManager.Progress;
using ModuleManager.Extensions;
using NodeStack = ModuleManager.Collections.ImmutableStack<ConfigNode>;

namespace ModuleManagerTests
{
Expand Down Expand Up @@ -346,6 +348,56 @@ public void TestCheckNeeds__Nested()

}

[Fact]
public void TestCheckNeeds__RootAndNested()
{
string[] modList = { "mod1", "mod2" };

UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig(new TestConfigNode("SOME_NODE:NEEDS[mod1]")
{
{ "aa:NEEDS[mod2]", "00" },
{ "bb:NEEDS[mod3]", "01" },
new TestConfigNode("INNER_NODE_1:NEEDS[mod2]")
{
{ "cc", "02" },
},
new TestConfigNode("INNER_NODE_2:NEEDS[mod3]")
{
{ "dd", "03" },
},
}, file);
UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig(new ConfigNode("SOME_OTHER_NODE:NEEDS[mod3]"), file);

NeedsChecker.CheckNeeds(root, modList, progress, logger);

progress.DidNotReceiveWithAnyArgs().Exception(null, null);
progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
progress.DidNotReceiveWithAnyArgs().Error(null, null);

UrlDir.UrlConfig[] configs = root.AllConfigs.ToArray();
Assert.Equal(1, configs.Length);

UrlDir.UrlConfig url = configs[0];
Assert.Equal("SOME_NODE", url.type);
ConfigNode newNode = url.config;
Assert.Equal("SOME_NODE", newNode.name);

Assert.Equal(1, newNode.values.Count);
Assert.Equal(1, newNode.nodes.Count);

Assert.Equal("aa", newNode.values[0].name);
Assert.Equal("00", newNode.values[0].value);

Assert.Equal("INNER_NODE_1", newNode.nodes[0].name);

Assert.Equal("cc", newNode.nodes[0].values[0].name);
Assert.Equal("02", newNode.nodes[0].values[0].value);

progress.Received().NeedsUnsatisfiedRoot(config2);
progress.Received().NeedsUnsatisfiedValue(url, Arg.Is<NodeStack>(stack => stack.GetPath() == "SOME_NODE"), "bb:NEEDS[mod3]");
progress.Received().NeedsUnsatisfiedNode(url, Arg.Is<NodeStack>(stack => stack.GetPath() == "SOME_NODE/INNER_NODE_2:NEEDS[mod3]"));
}

[Fact]
public void TestCheckNeeds__Exception()
{
Expand Down

0 comments on commit 60171d9

Please sign in to comment.