public static void ExecuteParsingTest(string arguments, bool shouldPass, Action <PsaraOptions> assertions = null) { var ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments.Split(' ')); var Options = (ApplicationOptionParser).PsaraOptions; if (shouldPass) { assertions(Options); } else //TODO - it would be nice to specify the actual error codes from the parsing result { int ErrorCode = ApplicationOptionParser.ParsingResult.ExitCode; Assert.NotEqual(0, ApplicationOptionParser.ParsingResult.ExitCode); Assert.NotNull(ApplicationOptionParser.ParsingResult.Exception); } }
public static void CreateMissingOutFolder() { var vcfPath = Path.Combine(TestPaths.LocalTestDataDirectory, "PsaraTestInput.vcf"); var roiPath = Path.Combine(TestPaths.LocalTestDataDirectory, "roi.txt"); var testVcfDir = Path.Combine(TestPaths.LocalScratchDirectory, "VcfDir"); var testNonexistantDir = Path.Combine(TestPaths.LocalScratchDirectory, "mockNonexistantDir"); if (Directory.Exists(testNonexistantDir)) { Directory.Delete(testNonexistantDir); } //test 1: if no output directory is supplied, test the vcf directory will do. if (!Directory.Exists(testVcfDir)) { Directory.CreateDirectory(testVcfDir); } var testVcfPath = Path.Combine(testVcfDir, "PsaraTestInput.vcf"); if (!File.Exists(testVcfPath)) { File.Copy(vcfPath, testVcfPath); } var arguments = new string[] { "-vcf", testVcfPath, "-roi", roiPath }; var ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments); var Options = (ApplicationOptionParser).PsaraOptions; Assert.Equal(testVcfDir, Options.OutputDirectory); Assert.True(ApplicationOptionParser.HadSuccess); Assert.Equal(0, ApplicationOptionParser.ParsingResult.ExitCode); //test 2: if a non-existant output directory is supplied, check it can be created arguments = new string[] { "-vcf", testVcfPath, "-roi", roiPath, "-outfolder", testNonexistantDir }; Assert.False(Directory.Exists(testNonexistantDir)); ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments); Options = (ApplicationOptionParser).PsaraOptions; Assert.Equal(testNonexistantDir, Options.OutputDirectory); Assert.True(ApplicationOptionParser.HadSuccess); Assert.Equal(0, ApplicationOptionParser.ParsingResult.ExitCode); Assert.True(Directory.Exists(testNonexistantDir)); //test 3: if an uncreatable directory is supplied, check a parsing error is thrown arguments = new string[] { "-vcf", testVcfPath, "-roi", roiPath, "-outfolder", "This..:&^$*%WontWOrk:!!" }; Assert.False(Directory.Exists("This..:&^$*%WontWOrk:!!")); ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments); Options = (ApplicationOptionParser).PsaraOptions; Assert.Equal("This..:&^$*%WontWOrk:!!", Options.OutputDirectory); Assert.True(ApplicationOptionParser.ParsingFailed); Assert.Equal(160, ApplicationOptionParser.ParsingResult.ExitCode); Assert.False(Directory.Exists("This..:&^$*%WontWOrk:!!")); }
public static void CreateMissingOutFolder() { var vcfPath = Path.Combine(TestPaths.LocalTestDataDirectory, "PsaraTestInput.vcf"); var roiPath = Path.Combine(TestPaths.LocalTestDataDirectory, "roi.txt"); var testVcfDir = Path.Combine(TestPaths.LocalScratchDirectory, "VcfDir"); var testNonexistantDir = Path.Combine(TestPaths.LocalScratchDirectory, "mockNonexistantDir"); if (Directory.Exists(testNonexistantDir)) { Directory.Delete(testNonexistantDir); } //test 1: if no output directory is supplied, test the vcf directory will do. if (!Directory.Exists(testVcfDir)) { Directory.CreateDirectory(testVcfDir); } var testVcfPath = Path.Combine(testVcfDir, "PsaraTestInput.vcf"); if (!File.Exists(testVcfPath)) { File.Copy(vcfPath, testVcfPath); } var arguments = new string[] { "-vcf", testVcfPath, "-roi", roiPath }; var ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments); var Options = (ApplicationOptionParser).PsaraOptions; Assert.Equal(testVcfDir, Options.OutputDirectory); Assert.True(ApplicationOptionParser.HadSuccess); Assert.Equal(0, ApplicationOptionParser.ParsingResult.ExitCode); //test 2: if a non-existant output directory is supplied, check it can be created arguments = new string[] { "-vcf", testVcfPath, "-roi", roiPath, "-outfolder", testNonexistantDir }; Assert.False(Directory.Exists(testNonexistantDir)); ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments); Options = (ApplicationOptionParser).PsaraOptions; Assert.Equal(testNonexistantDir, Options.OutputDirectory); Assert.True(ApplicationOptionParser.HadSuccess); Assert.Equal(0, ApplicationOptionParser.ParsingResult.ExitCode); Assert.True(Directory.Exists(testNonexistantDir)); //test 3: if an uncreatable directory is supplied, check a parsing error is thrown string crazyDir = "This//..:\\&^$*%WontWOrk:!!"; //tjd, ha ha, no it can be created by UNIX... //allow linux/unix to skip this.. otherwise they would fail for being smart.. var platform = Environment.OSVersion.Platform.ToString().ToLower(); if ((platform.Contains("unix")) || (platform.Contains("linux"))) { Assert.True(true); } else { arguments = new string[] { "-vcf", testVcfPath, "-roi", roiPath, "-outfolder", crazyDir }; bool doesItExist = Directory.Exists(crazyDir); Assert.False(doesItExist); ApplicationOptionParser = new PsaraOptionsParser(); ApplicationOptionParser.ParseArgs(arguments); Options = (ApplicationOptionParser).PsaraOptions; Assert.Equal(crazyDir, Options.OutputDirectory); Assert.True(ApplicationOptionParser.ParsingFailed); Assert.Equal(160, ApplicationOptionParser.ParsingResult.ExitCode); Assert.False(Directory.Exists(crazyDir)); } }