Skip to content

Commit

Permalink
Merge pull request #102 from dirkrombauts/master
Browse files Browse the repository at this point in the history
Make commandline parser robust against ill-placed semicolons
  • Loading branch information
dirkrombauts committed Apr 11, 2014
2 parents 0655190 + b73fb95 commit 968e550
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/Pickles/Pickles.Test/WhenParsingCommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ public void ThenCanParseResultsFileAsSemicolonSeparatedListAndTestResultsFileCon
Assert.AreEqual(@"c:\results1.xml", configuration.TestResultsFiles[0].FullName);
}

[Test]
public void ThenCanParseResultsFileAsSemicolonSeparatedListThatStartsWithASemicolon()
{
var args = new[] { @"-link-results-file=;c:\results1.xml" };

var configuration = new Configuration();
var commandLineArgumentParser = new CommandLineArgumentParser(FileSystem);
bool shouldContinue = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null);

shouldContinue.ShouldBeTrue();
configuration.HasTestResults.ShouldBeTrue();
Assert.AreEqual(1, configuration.TestResultsFiles.Length);
Assert.AreEqual(@"c:\results1.xml", configuration.TestResultsFiles[0].FullName);
}

[Test]
public void ThenCanParseResultsFileAsSemicolonSeparatedListThatEndsWithASemicolon()
{
var args = new[] { @"-link-results-file=c:\results1.xml;" };

var configuration = new Configuration();
var commandLineArgumentParser = new CommandLineArgumentParser(FileSystem);
bool shouldContinue = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null);

shouldContinue.ShouldBeTrue();
configuration.HasTestResults.ShouldBeTrue();
Assert.AreEqual(1, configuration.TestResultsFiles.Length);
Assert.AreEqual(@"c:\results1.xml", configuration.TestResultsFiles[0].FullName);
}

[Test]
public void ThenCanParseResultsFileWithShortFormSuccessfully()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Pickles/Pickles/CommandLineArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ limitations under the License.
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;

using java.io;

using NDesk.Options;

using TextWriter = System.IO.TextWriter;
Expand Down Expand Up @@ -112,7 +115,7 @@ public bool Parse(string[] args, Configuration configuration, TextWriter stdout)

if (!string.IsNullOrEmpty(this.testResultsFile))
{
var files = this.testResultsFile.Split(';');
var files = this.testResultsFile.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

configuration.TestResultsFiles = files.Select(f => this.fileSystem.FileInfo.FromFileName(f)).ToArray();
}
Expand Down

0 comments on commit 968e550

Please sign in to comment.