From fc8acd503e2e0cb56cd2472e26855d5e3b0eef01 Mon Sep 17 00:00:00 2001 From: kshakir Date: Sat, 26 Mar 2011 00:41:47 +0000 Subject: [PATCH] Enabled the parameterize option for debugging PipelineTest MD5s. Fixed escaping expressions that have more than one space between arguments. Updated example to match the wiki. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5516 348d0f76-0448-11de-a6fe-93d51630548a --- .../org/broadinstitute/sting/utils/Utils.java | 6 +++--- .../sting/utils/UtilsUnitTest.java | 18 ++++++++++++++++++ .../sting/queue/pipeline/PipelineTest.scala | 8 ++++---- .../queue/pipeline/PipelineTestSpec.scala | 3 +++ .../ExampleCountLociPipelineTest.scala | 10 ++++++---- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index 4404dc64a..4c13d8b18 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -319,7 +319,7 @@ public class Utils { else if (args.indexOf('\"') != -1) return escapeExpressions(args, "\""); else - return args.split(" "); + return args.trim().split(" +"); } /** @@ -335,13 +335,13 @@ public class Utils { for (int i = 0; i < split.length - 1; i += 2) { arg = split[i].trim(); if (arg.length() > 0) // if the unescaped arg has a size - command = Utils.concatArrays(command, arg.split(" ")); + command = Utils.concatArrays(command, arg.split(" +")); command = Utils.concatArrays(command, new String[]{split[i + 1]}); } arg = split[split.length - 1].trim(); if (split.length % 2 == 1) // if the command ends with a delimiter if (arg.length() > 0) // if the last unescaped arg has a size - command = Utils.concatArrays(command, arg.split(" ")); + command = Utils.concatArrays(command, arg.split(" +")); return command; } diff --git a/java/test/org/broadinstitute/sting/utils/UtilsUnitTest.java b/java/test/org/broadinstitute/sting/utils/UtilsUnitTest.java index 7a800e965..a9808edb4 100644 --- a/java/test/org/broadinstitute/sting/utils/UtilsUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/UtilsUnitTest.java @@ -86,6 +86,18 @@ public class UtilsUnitTest extends BaseTest { public void testEscapeExpressions() { String[] expected, actual; + expected = new String[] {"one", "two", "three"}; + actual = Utils.escapeExpressions("one two three"); + Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions(" one two three"); + Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions("one two three "); + Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions(" one two three "); + Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions(" one two three "); + Assert.assertEquals(actual, expected); + expected = new String[] {"one", "two", "three four", "five", "six"}; actual = Utils.escapeExpressions("one two 'three four' five six"); Assert.assertEquals(actual, expected); @@ -95,6 +107,8 @@ public class UtilsUnitTest extends BaseTest { Assert.assertEquals(actual, expected); actual = Utils.escapeExpressions(" one two 'three four' five six "); Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions(" one two 'three four' five six "); + Assert.assertEquals(actual, expected); expected = new String[] {"one two", "three", "four"}; actual = Utils.escapeExpressions("'one two' three four"); @@ -105,6 +119,8 @@ public class UtilsUnitTest extends BaseTest { Assert.assertEquals(actual, expected); actual = Utils.escapeExpressions(" 'one two' three four "); Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions(" 'one two' three four "); + Assert.assertEquals(actual, expected); expected = new String[] {"one", "two", "three four"}; actual = Utils.escapeExpressions("one two 'three four'"); @@ -115,5 +131,7 @@ public class UtilsUnitTest extends BaseTest { Assert.assertEquals(actual, expected); actual = Utils.escapeExpressions(" one two 'three four' "); Assert.assertEquals(actual, expected); + actual = Utils.escapeExpressions(" one two 'three four' "); + Assert.assertEquals(actual, expected); } } diff --git a/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala b/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala index 7e6ca18c2..2c04cb424 100644 --- a/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala +++ b/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala @@ -150,7 +150,7 @@ object PipelineTest extends BaseTest with Logging { println(Utils.dupString('-', 80)); executeTest(name, pipelineTest.args, pipelineTest.jobQueue, pipelineTest.expectedException) if (run) { - assertMatchingMD5s(name, pipelineTest.fileMD5s.map{case (file, md5) => new File(runDir(name), file) -> md5}) + assertMatchingMD5s(name, pipelineTest.fileMD5s.map{case (file, md5) => new File(runDir(name), file) -> md5}, pipelineTest.parameterize) if (pipelineTest.evalSpec != null) validateEval(name, pipelineTest.evalSpec) println(" => %s PASSED".format(name)) @@ -159,11 +159,11 @@ object PipelineTest extends BaseTest with Logging { println(" => %s PASSED DRY RUN".format(name)) } - private def assertMatchingMD5s(name: String, fileMD5s: Traversable[(File, String)]) { + private def assertMatchingMD5s(name: String, fileMD5s: Traversable[(File, String)], parameterize: Boolean) { var failed = 0 for ((file, expectedMD5) <- fileMD5s) { - val calculatedMD5 = BaseTest.testFileMD5(name, file, expectedMD5, false) - if (expectedMD5 != "" && expectedMD5 != calculatedMD5) + val calculatedMD5 = BaseTest.testFileMD5(name, file, expectedMD5, parameterize) + if (!parameterize && expectedMD5 != "" && expectedMD5 != calculatedMD5) failed += 1 } if (failed > 0) diff --git a/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala b/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala index 22fe7c1f4..f26689383 100644 --- a/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala +++ b/scala/test/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala @@ -19,6 +19,9 @@ class PipelineTestSpec(var name: String = null) { /** Expected exception from the test. */ var expectedException: Class[_ <: Exception] = null + /** If true will check the MD5s without failing. */ + var parameterize = false + def this(args: String, fileMD5s: Traversable[(String, String)]) = { this() this.args = args diff --git a/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleCountLociPipelineTest.scala b/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleCountLociPipelineTest.scala index 024c14232..2b3b51783 100644 --- a/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleCountLociPipelineTest.scala +++ b/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleCountLociPipelineTest.scala @@ -31,12 +31,14 @@ import org.broadinstitute.sting.BaseTest class ExampleCountLociPipelineTest { @Test def testCountLoci { - var testOut = "count.out" + val testOut = "count.out" val spec = new PipelineTestSpec spec.name = "countloci" - spec.args = "-S scala/qscript/examples/ExampleCountLoci.scala -R %s -I %s -o %s".format( - BaseTest.hg18Reference, BaseTest.validationDataLocation + "small_bam_for_countloci.bam", testOut - ) + spec.args = Array( + " -S scala/qscript/examples/ExampleCountLoci.scala", + " -R " + BaseTest.hg18Reference, + " -I " + BaseTest.validationDataLocation + "small_bam_for_countloci.bam", + " -o " + testOut).mkString spec.fileMD5s += testOut -> "67823e4722495eb10a5e4c42c267b3a6" PipelineTest.executeTest(spec) }