Skip to content

Commit 132e934

Browse files
committed
Fix some tests for Unix platforms support
1 parent 4c47b31 commit 132e934

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

TeamTools.Linter.CommandLineTests/UnitTests/CommandLintOptionsTests.cs renamed to TeamTools.Linter.CommandLineTests/UnitTests/CommandLineOptionsTests.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
using CommandLine;
22
using NUnit.Framework;
33
using System.Collections.Generic;
4+
using System.IO;
45
using TeamTools.TSQL.Linter.CommandLine.Config;
56

67
namespace TeamTools.TSQL.Linter.CommandLineTests
78
{
89
[Category("Linter.ConsoleExe")]
9-
public class CommandLintOptionsTests
10+
public class CommandLineOptionsTests
1011
{
1112
private Dictionary<string, List<string>> argVariants;
13+
#if Windows
14+
private const string BasePath = @"c:\";
15+
#else
16+
private const string BasePath = @"/home/";
17+
#endif
1218

1319
[SetUp]
1420
public void Setup()
1521
{
1622
argVariants = new Dictionary<string, List<string>>
1723
{
18-
{ "scan dir", new List<string> { "--config", "c:\\conf.json", "--dir", "c:\\src" } },
19-
{ "scan file", new List<string> { "--config", "c:\\conf.json", "--file", "c:\\src\\file.sql" } },
20-
{ "scan diff", new List<string> { "--config", "c:\\conf.json", "--dir", "c:\\src\\proj", "--diff", "--format", "json", "--basepath", "c:\\src", "--output", "c:\\report.json", "--verbose" } },
24+
{ "scan dir", new List<string> { "--config", BasePath + "conf.json", "--dir", BasePath + "src" } },
25+
{ "scan file", new List<string> { "--config", BasePath + "conf.json", "--file", Path.Combine(BasePath, "src", "file.sql") } },
26+
{ "scan diff", new List<string> { "--config", BasePath + "conf.json", "--dir", Path.Combine(BasePath, "src", "proj"), "--diff", "--format", "json", "--basepath", BasePath + "src", "--output", BasePath + "report.json", "--verbose" } },
2127
};
2228
}
2329

@@ -42,10 +48,10 @@ public void TestAllArgumentsExtractedCorrectly()
4248
.WithNotParsed(err => Assert.Fail(string.Join(";", err)));
4349

4450
Assert.That(parsedOpts, Is.Not.Null);
45-
Assert.That(parsedOpts.ConfigFile, Is.EqualTo("c:\\conf.json"));
46-
Assert.That(parsedOpts.DirectoryName, Is.EqualTo("c:\\src\\proj"));
47-
Assert.That(parsedOpts.BasePath, Is.EqualTo("c:\\src"));
48-
Assert.That(parsedOpts.OutputFile, Is.EqualTo("c:\\report.json"));
51+
Assert.That(parsedOpts.ConfigFile, Is.EqualTo(BasePath + "conf.json"));
52+
Assert.That(parsedOpts.DirectoryName, Is.EqualTo(Path.Combine(BasePath, "src", "proj")));
53+
Assert.That(parsedOpts.BasePath, Is.EqualTo(BasePath + "src"));
54+
Assert.That(parsedOpts.OutputFile, Is.EqualTo(BasePath + "report.json"));
4955
Assert.That(parsedOpts.Format, Is.EqualTo(OutputFileFormat.JSON));
5056
Assert.That(string.IsNullOrEmpty(parsedOpts.FileListSource), Is.True);
5157
Assert.That(string.IsNullOrEmpty(parsedOpts.FileName), Is.True);

TeamTools.Linter.CommandLineTests/UnitTests/ConfigHandlerTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using System.IO;
23
using TeamTools.Common.Linting;
34
using TeamTools.Common.Linting.Infrastructure;
45
using TeamTools.TSQL.Linter.CommandLine.Config;
@@ -15,7 +16,8 @@ public void TestConfigHandlerParsesConfigCorrectly()
1516
var asm = new AssemblyWrapper();
1617
var cfg = new ConfigHandler(asm, new AppConfigLoader(fs, asm), fs);
1718

18-
cfg.LoadFromFile(@".\DefaultConfig.json");
19+
// Relative path to config should be successfully revealed
20+
cfg.LoadFromFile(Path.Combine(".", "DefaultConfig.json"));
1921

2022
Assert.Multiple(() =>
2123
{

TeamTools.Linter.CommandLineTests/UnitTests/FileEnumeratorTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NUnit.Framework;
22
using System.Collections.Generic;
3+
using System.IO;
34
using TeamTools.Common.Linting;
45
using TeamTools.TSQL.Linter.CommandLine.Infrastructure;
56
using TeamTools.TSQL.Linter.CommandLineTests.TestingInfrastructure;
@@ -34,7 +35,11 @@ public void TestListEnumerator()
3435
var files = new ListedFileEnumerator(fs, "subfolder", "srcfile");
3536
var fileList = string.Join(";", files.EnumFiles());
3637

37-
Assert.That(fileList, Is.EqualTo("subfolder\\line1;subfolder\\line2"));
38+
// Replace is to respect different platforms
39+
var expectedValue = "subfolder\\line1;subfolder\\line2";
40+
expectedValue = expectedValue.Replace('\\', Path.DirectorySeparatorChar);
41+
42+
Assert.That(fileList, Is.EqualTo(expectedValue));
3843
}
3944

4045
[Test]

TeamTools.Linter.CommandLineTests/UnitTests/FileReporterTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using TeamTools.Common.Linting;
@@ -29,22 +30,27 @@ public void TestReportResultsSendsToStream()
2930
reporter.ReportResults();
3031

3132
// ToList, ToArray returns elements in reversed order
32-
Assert.That(writer.ToString(), Is.EqualTo("error: issue2\r\nerror: issue1\r\n"));
33+
Assert.That(writer.ToString(), Is.EqualTo(string.Join(Environment.NewLine, "error: issue2", "error: issue1", "")));
3334
}
3435

3536
[Test]
3637
public void TestJsonReportFormatterOutput()
3738
{
39+
#if Windows
40+
const string basePath = @"c:\";
41+
#else
42+
const string basePath = @"/home/";
43+
#endif
3844
string expectedOutput = @"{'LINT':{'language':'TSQL','files':[{'name':'filename.txt','issues':[{'line':2,'col':3,'reason':'Failure','evidence':'','category':'CODE_SMELL','severity':'MAJOR','rule':'RULEID'}]}]}}"
3945
.Replace('\'', '"');
40-
var formatter = new JsonReportFormatter(@"c:\test");
46+
var formatter = new JsonReportFormatter(Path.Combine(basePath, "test"));
4147
var output = new StringWriter();
4248
var issues = new List<RuleViolation>();
4349
issues.Add(new RuleViolation
4450
{
4551
Line = 2,
4652
Column = 3,
47-
FileName = @"c:\test\filename.txt",
53+
FileName = Path.Combine(basePath, "test", "filename.txt"),
4854
RuleId = "RULEID",
4955
Text = "Failure",
5056
});

0 commit comments

Comments
 (0)