Skip to content

Commit

Permalink
Allows the file to be in PWD (#29)
Browse files Browse the repository at this point in the history
* Reproduced the bug in the CI

* Added unit tests for the issue

* Fixed "Path cannot be the empty string or all whitespace."
  • Loading branch information
gfoidl committed Dec 16, 2018
1 parent 782059b commit c483bcc
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ jobs:
echo ""
./verify-xml.sh "TestResults/nunit.xml"
./verify-xml.sh "TestResults/mstest.xml"
- run:
name: run-single-arg
command: |
mkdir ./single-arg
cp tests/trx2junit.Tests/data/nunit.trx ./single-arg
echo "-----------------------------------------------"
echo "file in different location than pwd"
trx2junit ./single-arg/nunit.trx
echo ""
./verify-xml.sh "single-arg/nunit.xml"
echo ""
echo "-----------------------------------------------"
echo "file in same location than pwd"
cd single-arg
trx2junit nunit.trx
echo ""
cd -
./verify-xml.sh "single-arg/nunit.xml"
- run:
name: run-multiple-args
command: |
Expand Down
4 changes: 3 additions & 1 deletion source/trx2junit/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ internal static string GetJunitFile(string trxFile, string outputPath = null)
private static void EnsureOutputDirectoryExists(string jUnitFile)
{
string directory = Path.GetDirectoryName(jUnitFile);
Directory.CreateDirectory(directory);

if (!string.IsNullOrWhiteSpace(directory))
Directory.CreateDirectory(directory);
}
}
}
74 changes: 74 additions & 0 deletions tests/trx2junit.Tests/WorkerTests/RunAsync/LocationIsPwd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;

namespace trx2junit.Tests.WorkerTests.RunAsync
{
[TestFixture]
public class LocationIsPwd
{
private string _curDir;
//---------------------------------------------------------------------
[SetUp]
public void SetUp()
{
_curDir = Environment.CurrentDirectory;
Environment.CurrentDirectory = "./data";
}
//---------------------------------------------------------------------
[TearDown]
public void TearDown()
{
Environment.CurrentDirectory = _curDir;
}
//---------------------------------------------------------------------
[Test]
public async Task Single_file_given___converted()
{
string[] expectedFiles = { "nunit.xml" };
DeleteExpectedFiles(expectedFiles);

var sut = new Worker();

string[] args = { "nunit.trx" };
var options = new WorkerOptions(args);
await sut.RunAsync(options);

CheckExpectedFilesExist(expectedFiles);
}
//---------------------------------------------------------------------
[Test]
public async Task Multiple_files_given___converted()
{
string[] expectedFiles = { "nunit.xml", "mstest.xml", "mstest-warning.xml" };
DeleteExpectedFiles(expectedFiles);

var sut = new Worker();

string[] args = { "nunit.trx", "mstest.trx", "mstest-warning.trx" };
var options = new WorkerOptions(args);
await sut.RunAsync(options);

CheckExpectedFilesExist(expectedFiles);
}
//---------------------------------------------------------------------
private static void DeleteExpectedFiles(string[] files)
{
foreach (string file in files)
File.Delete(file);
}
//---------------------------------------------------------------------
private static void CheckExpectedFilesExist(string[] files)
{
Assert.Multiple(() =>
{
foreach (string file in files)
{
bool actual = File.Exists(file);
Assert.IsTrue(actual, $"File '{file}' does not exist");
}
});
}
}
}

0 comments on commit c483bcc

Please sign in to comment.