Skip to content

Commit

Permalink
Implemented test to validate all text files end in CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
lordmilko committed May 4, 2018
1 parent e04390a commit 13a1cd7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
32 changes: 29 additions & 3 deletions PrtgAPI.Tests.UnitTests/InfrastructureTests/AssemblyTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand Down Expand Up @@ -68,7 +70,8 @@ public void InjectedProperties_On_ILazy_AreMarkedInternal()
}

[TestMethod]
public void AllTextFiles_UseSpaces()
[TestCategory("SkipCI")]
public void AllTextFiles_UseSpaces_AndCRLF()
{
var path = GetProjectRoot();

Expand All @@ -78,18 +81,41 @@ public void AllTextFiles_UseSpaces()
".cs",
".ps1",
".txt",
".md"
".md",
".ps1xml"
};

var files = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Where(f =>
types.Any(f.EndsWith)
);

var badNewLines = new List<string>();

foreach (var file in files)
{
if (File.ReadAllText(file).Contains("\t"))
var text = File.ReadAllText(file);

if (text.Contains("\t"))
throw new Exception($"{file} contains tabs");

var matches = Regex.Matches(text, "\n");

foreach (Match match in matches)
{
var index = match.Index;

var prev = text[index - 1];

if (prev != '\r')
{
badNewLines.Add(new FileInfo(file).Name);
break;
}
}
}

if (badNewLines.Count > 0)
throw new Exception($"{string.Join(", ", badNewLines) } are missing CRLF");
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions PrtgAPI.Tests.UnitTests/InfrastructureTests/PrtgUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ public void PrtgUrl_SearchFilter_With_DateTime()
{
var url = CreateUrl(new Parameters.Parameters
{
[Parameter.FilterXyz] = new[] { new SearchFilter(Property.LastUp, new DateTime(2000, 10, 2, 12, 10, 5)) }
[Parameter.FilterXyz] = new[] { new SearchFilter(Property.LastUp, new DateTime(2000, 10, 2, 12, 10, 5, DateTimeKind.Utc)) }
});

Assert.AreEqual("filter_lastup=36801.0903356482", url);
Assert.AreEqual("filter_lastup=36801.5070023148", url);
}

[TestMethod]
Expand Down

0 comments on commit 13a1cd7

Please sign in to comment.