Skip to content

Commit 10567e7

Browse files
committed
Add back old .NET framework support
for DotVVM unit tests ;(
1 parent d423d1f commit 10567e7

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

exampleTest/CheckTestOutput.Example.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net6.0;net472</TargetFrameworks>
5+
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
6+
57

68
<IsPackable>false</IsPackable>
79
<RollForward>major</RollForward>

src/CheckTestOutput.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
55
<LangVersion>9</LangVersion>
66

77
<Description>Simple helper which checks that output of a test matches a file. If not matching, just git staging the new file will accept the new version.</Description>
@@ -16,7 +16,7 @@
1616

1717
<AssemblyOriginatorKeyFile>dotvvmwizard.snk</AssemblyOriginatorKeyFile>
1818
<SignAssembly>true</SignAssembly>
19-
<PublicSign>true</PublicSign>
19+
<!-- <PublicSign >true</PublicSign> -->
2020

2121
<PackageReadmeFile>README.md</PackageReadmeFile>
2222

@@ -30,6 +30,10 @@
3030
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
3131
<PackageReference Include="System.Text.Json" Version="5.0.2" />
3232
</ItemGroup>
33+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
34+
<PackageReference Include="System.Text.Json" Version="5.0.2" />
35+
<PackageReference Include="MedallionShell.StrongName" Version="1.6.2" />
36+
</ItemGroup>
3337

3438
<ItemGroup>
3539
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>

src/OutputChecker.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private Process StartGitProcess(params string[] args)
8888
#if DEBUG
8989
Console.WriteLine("Running git command: " + string.Join(" ", args));
9090
#endif
91+
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
9192
// run `git ...args` in CheckDirectory working directory with 3 second timeout
9293
var procInfo = new ProcessStartInfo("git")
9394
{
@@ -102,9 +103,12 @@ private Process StartGitProcess(params string[] args)
102103
};
103104
foreach (var a in args)
104105
procInfo.ArgumentList.Add(a);
105-
106-
107106
return Process.Start(procInfo);
107+
#else
108+
// Old frameworks don't support ArgumentList, so I rather pull in a dependency than write my own escaping
109+
var command = Medallion.Shell.Shell.Default.Run("git", args, options => options.WorkingDirectory(CheckDirectory).Timeout(TimeSpan.FromSeconds(15)));
110+
return command.Process;
111+
#endif
108112
}
109113

110114
private void HandleProcessExit(Process proc, Task outputReaderTask, params string[] args)
@@ -145,21 +149,13 @@ private string[] RunGitCommand(params string[] args)
145149

146150
private byte[] RunGitBinaryCommand(params string[] args)
147151
{
148-
const int BUFFER_SIZE = 1024;
149-
150152
var proc = StartGitProcess(args);
151153

152-
List<byte> ret = new();
154+
MemoryStream ret = new();
153155

154156
var outputReaderTask = Task.Run(() =>
155157
{
156-
byte[] buffer = new byte[BUFFER_SIZE];
157-
158-
int charsRead = 0;
159-
while ((charsRead = proc.StandardOutput.BaseStream.Read(buffer, 0, BUFFER_SIZE)) != 0)
160-
{
161-
ret.AddRange(buffer.AsSpan(0, charsRead).ToArray());
162-
}
158+
proc.StandardOutput.BaseStream.CopyTo(ret);
163159
});
164160

165161
HandleProcessExit(proc, outputReaderTask, args);
@@ -323,7 +319,7 @@ internal void CheckOutputBinaryCore(byte[] outputBytes, string checkName, string
323319
{
324320
using (var t = File.Create(filename))
325321
{
326-
t.Write(outputBytes);
322+
t.Write(outputBytes, 0, outputBytes.Length);
327323
}
328324
}
329325
return;
@@ -333,7 +329,7 @@ internal void CheckOutputBinaryCore(byte[] outputBytes, string checkName, string
333329
{
334330
using (var t = File.Create(filename))
335331
{
336-
t.Write(outputBytes);
332+
t.Write(outputBytes, 0, outputBytes.Length);
337333
}
338334

339335
if (IsModified(filename))

0 commit comments

Comments
 (0)