Skip to content

Commit 4be4bde

Browse files
committed
Merge pull request #43 from am11/rewrite-new-api
Check expected errors in spec tests
2 parents b296880 + 8f5bef0 commit 4be4bde

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

LibSass.NET.Tests/Spec/SpecTests.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using LibSass.Compiler.Options;
66
using Xunit;
77
using static LibSass.Tests.TestCommonsAndExtensions;
8+
using static System.IO.Path;
9+
using static System.IO.File;
810

911
namespace LibSass.Tests.Spec
1012
{
@@ -20,7 +22,21 @@ public static void Sass_Specs_Run(string source, string expected, bool error, st
2022
}
2123
.Compile();
2224

23-
Assert.Equal(expected.SpecNormalize(), result.Output.SpecNormalize());
25+
if (!string.IsNullOrEmpty(result.ErrorMessage))
26+
{
27+
Assert.True(error);
28+
}
29+
else
30+
{
31+
Assert.False(error);
32+
}
33+
34+
if (!string.IsNullOrEmpty(expected))
35+
{
36+
Assert.Equal(
37+
expected.SpecNormalize(),
38+
result.Output.SpecNormalize());
39+
}
2440
}
2541

2642
const string SpecInputFile = "input.scss";
@@ -50,27 +66,28 @@ private static IEnumerable<object> GetSassSpecDataSuites()
5066
foreach (var testDirectory in testDirectories)
5167
{
5268
var testPath = testDirectory.FullName;
53-
var hasErrorFile = File.Exists(Path.Combine(testPath, SpecErrorFile));
69+
var hasErrorFile = Exists(Combine(testPath, SpecErrorFile));
5470
var hasError = false;
71+
5572
if (hasErrorFile)
5673
{
57-
var errorFileContents = File.ReadAllText(Path.Combine(testPath, SpecErrorFile));
74+
var errorFileContents = ReadAllText(Combine(testPath, SpecErrorFile));
5875
hasError = !(errorFileContents.StartsWith("DEPRECATION WARNING") ||
5976
errorFileContents.StartsWith("WARNING:") ||
6077
Regex.IsMatch(errorFileContents, @"^.*?\/input.scss:\d+ DEBUG:"));
6178
}
6279

63-
var inputFile = Path.Combine(testDirectory.FullName, SpecInputFile);
80+
var inputFile = Combine(testDirectory.FullName, SpecInputFile);
6481

65-
if (!File.Exists(inputFile))
82+
if (!Exists(inputFile))
6683
continue;
6784

6885
yield return new object[]
6986
{
7087
inputFile,
71-
File.ReadAllText(Path.Combine(testDirectory.FullName, SpecExpectedFile)),
88+
ReadAllText(Combine(testDirectory.FullName, SpecExpectedFile)),
7289
hasErrorFile && hasError,
73-
new[] {testPath, Path.Combine(testPath, SpecSubDirectory) }
90+
new[] { testPath, Combine(testPath, SpecSubDirectory) }
7491
};
7592
}
7693
}
@@ -80,7 +97,8 @@ private static string SpecNormalize(this string input)
8097
{
8198
return Regex.Replace(input, @"\s+", string.Empty)
8299
.Replace("{\r", "{")
83-
.Replace("{", "{\n").Replace(";", ";\n");
100+
.Replace("{", "{\n")
101+
.Replace(";", ";\n");
84102
}
85103
}
86104
}

0 commit comments

Comments
 (0)