You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/BasicChecks.cs
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,5 @@
1
-
usingSystem;
2
-
usingSystem.Collections.Generic;
1
+
usingSystem.Collections.Generic;
3
2
usingSystem.IO;
4
-
usingSystem.Linq;
5
3
6
4
namespaceCheckTestOutput
7
5
{
@@ -25,6 +23,24 @@ public static void CheckString(
25
23
);
26
24
}
27
25
26
+
/// <summary> Verifies that the provided <paramref name="output" /> equals to the `outputDirectory/TestClass.TestMethod.bin` file. </summary>
27
+
/// <param name="checkName"> If not null, checkName will be appended to the calling <paramref name="memberName" />. Intended to be used when having multiple checks in one method. </param>
/// <summary> Verifies that the provided <paramref name="output" /> equals to the `outputDirectory/TestClass.TestMethod.txt` file. File is compared line-by-line. </summary>
29
45
/// <param name="checkName"> If not null, checkName will be appended to the calling <paramref name="memberName" />. Intended to be used when having multiple checks in one method. </param>
<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>
$"{Path.GetFileName(filename)} has changed, the actual output differs from the previous accepted output:\n\n"+
244
301
string.Join("\n",diff)+"\n\n"+
245
-
"If this change OK? To let the test pass, stage the file in git. Confused? See https://github.com/exyi/CheckTestOutput/blob/master/trouble.md#changed-file\n"
302
+
"Is this change OK? To let the test pass, stage the file in git. Confused? See https://github.com/exyi/CheckTestOutput/blob/master/trouble.md#changed-file\n"
303
+
304
+
);
305
+
}
306
+
}
307
+
else
308
+
{
309
+
thrownewException($"{Path.GetFileName(filename)} has changed, the previous accepted output differs from the actual output:\n\n{outputString}\n\nNote that CheckTestOutput could not use git on your system, so the \"UX\" is limited.");
// fine! Just check that the file is not changed - if it is changed or deleted, we rewrite
322
+
if(IsModified(filename))
323
+
{
324
+
using(vart=File.Create(filename))
325
+
{
326
+
t.Write(outputBytes);
327
+
}
328
+
}
329
+
return;
330
+
}
331
+
332
+
if(DoesGitWork.Value)
333
+
{
334
+
using(vart=File.Create(filename))
335
+
{
336
+
t.Write(outputBytes);
337
+
}
338
+
339
+
if(IsModified(filename))
340
+
{
341
+
if(IsNewFile(filename))
342
+
{
343
+
thrownewException($"{Path.GetFileName(filename)} is not explicitly accepted - the file is untracked in git. To let this test pass, view the file and stage it. Confused? See https://github.com/exyi/CheckTestOutput/blob/master/trouble.md#untracked-file\n");
344
+
}
345
+
346
+
347
+
vardiff=RunGitCommand("diff",filename);
348
+
if(diff.All(string.IsNullOrEmpty))
349
+
{
350
+
// I guess fine from our perspective, but it's weird...
351
+
Console.WriteLine($"CheckTestOutput warning: {Path.GetFileName(filename)} is modified, but the diff is empty.");
352
+
return;
353
+
}
354
+
thrownewException(
355
+
$"{Path.GetFileName(filename)} has changed, the actual output differs from the previous accepted output!"
356
+
+"Is the change OK? To let the test pass, stage the file in git. Confused? See https://github.com/exyi/CheckTestOutput/blob/master/trouble.md#changed-file\n"
247
357
);
248
358
}
249
359
}
250
360
else
251
361
{
252
-
thrownewException($"{Path.GetFileName(filename)}has changed, the previous accepted output differs from the actual output:\n\n{outputString}\n\nNote that CheckTestOutput could not use git on your system, so the \"UX\" is limited.");
362
+
thrownewException($"{Path.GetFileName(filename)}has changed, the previous accepted output differs from the actual output.");
0 commit comments