Skip to content

Commit

Permalink
Config file parsing (and tests) now takes OS (forward-slash vs back-s…
Browse files Browse the repository at this point in the history
…lash) into account
  • Loading branch information
oliwennell committed Feb 9, 2018
1 parent 655a549 commit b7efed3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
24 changes: 20 additions & 4 deletions src/Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@ public Config WithPathsRelativeTo(string baseDirectory)
{
return new Config
{
SolutionFilePath = Path.Combine(baseDirectory, SolutionFilePath),
TestAssemblyFilePaths = TestAssemblyFilePaths.Select(x => Path.Combine(baseDirectory, x)).ToArray(),
NunitTestRunnerFilePath = Path.Combine(baseDirectory, NunitTestRunnerFilePath),
SolutionFilePath = NormalisePathSeparators(
Path.Combine(baseDirectory, SolutionFilePath)),

TestAssemblyFilePaths = TestAssemblyFilePaths.Select(x =>
NormalisePathSeparators(
Path.Combine(baseDirectory, x)))
.ToArray(),

NunitTestRunnerFilePath = NormalisePathSeparators(
Path.Combine(baseDirectory, NunitTestRunnerFilePath)),

ProjectFilters = ProjectFilters?.ToArray(),
SourceFileFilters = SourceFileFilters?.ToArray(),
CoverageReportFilePath = CoverageReportFilePath != null ? Path.Combine(baseDirectory, CoverageReportFilePath) : null

CoverageReportFilePath = CoverageReportFilePath != null
? NormalisePathSeparators(Path.Combine(baseDirectory, CoverageReportFilePath))
: null
};
}

private string NormalisePathSeparators(string path)
{
return path.Replace('/', Path.DirectorySeparatorChar)
.Replace('\\', Path.DirectorySeparatorChar);
}
}
}
49 changes: 26 additions & 23 deletions src/Tests/Console/ImplementationDetails/Config_file_parsing.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Fettle.Console;
using System.IO;
using Fettle.Console;
using NUnit.Framework;

namespace Fettle.Tests.Console.ImplementationDetails
Expand All @@ -10,62 +11,64 @@ public void All_properties_are_parsed()
{
const string fileContents = @"
solution: src\blah.sln
solution: src/blah.sln
testAssemblies:
- src\Blah.Tests\bin\Debug\Blah.Tests.dll
- src\Blurg.Tests\bin\Debug\Blurg.Tests.dll
- src/Blah.Tests/bin/Debug/Blah.Tests.dll
- src/Blurg.Tests/bin/Debug/Blurg.Tests.dll
nunitTestRunner: nunit\nunit3-console.exe
nunitTestRunner: nunit/nunit3-console.exe
projectFilters:
- BlahImpl
sourceFileFilters: [ Blah\Things\*.cs, Wibble\w*mble.cs ]
sourceFileFilters: [ Blah/Things/*.cs, Wibble/w*mble.cs ]
coverageReport: report.xml
";
var baseDir = Path.Combine(Path.GetPathRoot(Path.GetTempPath()), "random");

var config = ConfigFile.Parse(fileContents).WithPathsRelativeTo(@"C:\base\dir");
var config = ConfigFile.Parse(fileContents).WithPathsRelativeTo(baseDir);

Assert.That(config.NunitTestRunnerFilePath, Is.EqualTo(@"C:\base\dir\nunit\nunit3-console.exe"));
Assert.That(config.SolutionFilePath, Is.EqualTo(@"C:\base\dir\src\blah.sln"));
Assert.That(config.NunitTestRunnerFilePath, Is.EqualTo(Path.Combine(baseDir, "nunit", "nunit3-console.exe")));
Assert.That(config.SolutionFilePath, Is.EqualTo(Path.Combine(baseDir, "src" ,"blah.sln")));
Assert.That(config.TestAssemblyFilePaths, Is.EquivalentTo(new[]
{
@"C:\base\dir\src\Blah.Tests\bin\Debug\Blah.Tests.dll",
@"C:\base\dir\src\Blurg.Tests\bin\Debug\Blurg.Tests.dll"
Path.Combine(baseDir, "src", "Blah.Tests", "bin", "Debug", "Blah.Tests.dll"),
Path.Combine(baseDir, "src", "Blurg.Tests", "bin", "Debug", "Blurg.Tests.dll")
}));
Assert.That(config.ProjectFilters, Is.EquivalentTo(new[] { @"BlahImpl" }));
Assert.That(config.SourceFileFilters, Is.EquivalentTo(new[] { @"Blah\Things\*.cs", @"Wibble\w*mble.cs" }));
Assert.That(config.CoverageReportFilePath, Is.EqualTo(@"C:\base\dir\report.xml"));
Assert.That(config.SourceFileFilters, Is.EquivalentTo(new[] { @"Blah/Things/*.cs", @"Wibble/w*mble.cs" }));
Assert.That(config.CoverageReportFilePath, Is.EqualTo(Path.Combine(baseDir, "report.xml")));
}

[Test]
public void Optional_properties_can_be_omitted()
{
const string fileContents = @"
solution: src\blah.sln
solution: src/blah.sln
testAssemblies:
- src\Blah.Tests\bin\Debug\Blah.Tests.dll
- src\Blurg.Tests\bin\Debug\Blurg.Tests.dll
- src/Blah.Tests/bin/Debug/Blah.Tests.dll
- src/Blurg.Tests/bin/Debug/Blurg.Tests.dll
nunitTestRunner: nunit\nunit3-console.exe
nunitTestRunner: nunit/nunit3-console.exe
#projectFilters: [ BlahImpl ]
#sourceFileFilters: [ Blah\Things\*.cs, Wibble\w*mble.cs ]
#sourceFileFilters: [ Blah/Things/*.cs, Wibble/w*mble.cs ]
#coverageReport: report.xml
";
var baseDir = Path.Combine(Path.GetPathRoot(Path.GetTempPath()), "random");

var config = ConfigFile.Parse(fileContents).WithPathsRelativeTo(@"C:\base\dir");
var config = ConfigFile.Parse(fileContents).WithPathsRelativeTo(baseDir);

Assert.That(config.NunitTestRunnerFilePath, Is.EqualTo(@"C:\base\dir\nunit\nunit3-console.exe"));
Assert.That(config.SolutionFilePath, Is.EqualTo(@"C:\base\dir\src\blah.sln"));
Assert.That(config.NunitTestRunnerFilePath, Is.EqualTo(Path.Combine(baseDir, "nunit", "nunit3-console.exe")));
Assert.That(config.SolutionFilePath, Is.EqualTo(Path.Combine(baseDir, "src", "blah.sln")));
Assert.That(config.TestAssemblyFilePaths, Is.EquivalentTo(new[]
{
@"C:\base\dir\src\Blah.Tests\bin\Debug\Blah.Tests.dll",
@"C:\base\dir\src\Blurg.Tests\bin\Debug\Blurg.Tests.dll"
Path.Combine(baseDir, "src", "Blah.Tests", "bin", "Debug", "Blah.Tests.dll"),
Path.Combine(baseDir, "src", "Blurg.Tests", "bin", "Debug", "Blurg.Tests.dll")
}));

Assert.That(config.ProjectFilters, Is.Null);
Expand Down

0 comments on commit b7efed3

Please sign in to comment.