Skip to content

Commit

Permalink
Make tests pass on both Linux and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 6, 2024
1 parent 9ca2342 commit d313011
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/ChiselTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ public override bool Execute()
var graphPath = Path.Combine(IntermediateOutputPath, Graph);
try
{
using var output = new FileStream(graphPath, FileMode.Create);
if (!Enum.TryParse<GraphDirection>(GraphDirection, ignoreCase: true, out var graphDirection))
{
Log.LogWarning($"The ChiselGraphDirection property ({GraphDirection}) must be either {nameof(Chisel.GraphDirection.LeftToRight)} or {nameof(Chisel.GraphDirection.TopToBottom)}");
}
graph.Write(output, graphDirection);
using var graphStream = new FileStream(graphPath, FileMode.Create);
using var writer = new StreamWriter(graphStream);
graph.Write(writer, graphDirection);
GraphPath = [ new TaskItem(graphPath) ];
}
catch (Exception exception)
Expand Down
5 changes: 1 addition & 4 deletions src/DependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NuGet.ProjectModel;

namespace Chisel;
Expand Down Expand Up @@ -151,12 +150,10 @@ private void Restore(Package package, HashSet<Package> excludePackages)
}
}

public void Write(Stream stream, GraphDirection graphDirection = GraphDirection.LeftToRight, bool writeIgnoredPackages = false)
public void Write(TextWriter writer, GraphDirection graphDirection = GraphDirection.LeftToRight, bool writeIgnoredPackages = false)
{
bool FilterIgnored(Package package) => writeIgnoredPackages || package.State != PackageState.Ignore;

using var writer = new StreamWriter(stream, encoding: Encoding.UTF8, bufferSize: -1, leaveOpen: true);

writer.WriteLine("# Generated by https://github.com/0xced/Chisel");
writer.WriteLine("digraph");
writer.WriteLine("{");
Expand Down
6 changes: 3 additions & 3 deletions tests/DependencyGraphTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public async Task Graph01(bool writeIgnoredPackages)
var assetsFile = GetAssetsPath("Graph01.json");
var graph = new DependencyGraph(assetsFile, tfm: "net8.0", rid: "", [ "Testcontainers.MongoDb" ]);
var (removed, notFound, removedRoots) = graph.Remove([ "MongoDB.Driver", "AWSSDK.SecurityToken" ]);
using var stream = new MemoryStream();
graph.Write(stream, GraphDirection.LeftToRight, writeIgnoredPackages);
await using var writer = new StringWriter();
graph.Write(writer, GraphDirection.LeftToRight, writeIgnoredPackages);

removed.Should().BeEquivalentTo("AWSSDK.SecurityToken", "AWSSDK.Core");
notFound.Should().BeEmpty();
removedRoots.Should().BeEquivalentTo("MongoDB.Driver");

await Verify(stream, "gv").UseParameters(writeIgnoredPackages);
await Verify(writer.ToString(), "gv").UseParameters(writeIgnoredPackages);
}

private static string GetAssetsPath(string file, [CallerFilePath] string path = "")
Expand Down
10 changes: 10 additions & 0 deletions tests/Initialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.CompilerServices;
using EmptyFiles;

namespace Chisel.Tests;

public static class Initialization
{
[ModuleInitializer]
public static void Initialize() => FileExtensions.AddTextExtension("gv");
}

0 comments on commit d313011

Please sign in to comment.