Skip to content

Commit

Permalink
WX-1145 Fix minor regression introduced in WDL 1.1 foundation (#7153)
Browse files Browse the repository at this point in the history
  • Loading branch information
aednichols authored Jun 6, 2023
1 parent bbf45bf commit 012d16b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object LanguageFactoryUtil {
}

val firstCodeLine = fileWithoutInitialWhitespace.headOption.map(_.dropWhile(_.isWhitespace))
firstCodeLine.exists { line => startsWithOptions.contains(line) }
firstCodeLine.exists { line => startsWithOptions.contains(line.trim) }
}

def chooseFactory(workflowSource: WorkflowSource, wsfc: WorkflowSourceFilesCollection): ErrorOr[LanguageFactory] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cromwell.languages.util

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class LooksParseableSpec extends AnyFlatSpec with Matchers {
behavior of "simpleLooksParseable"

it should "work with `version 1.0` followed by whitespace" in {

val source =
"""
|version 1.0
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "work with `version 1.0` preceded by whitespace" in {

val source =
"""
| version 1.0
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "work with `version 1.0` surrounded by whitespace" in {

val source =
"""
| version 1.0
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "work with `version 1.0` surrounded by whitespace on all sides" in {

val source =
"""
|
| version 1.0
|
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

// This test technically contradicts the spec [0] but there is better hope of receiving a useful
// error if we try & fail to parse as 1.0, than if we fall back to the server default, `draft-2`
// > From draft-3 forward, the first line of all WDL files must be a version statement
// [0] https://github.com/openwdl/wdl/blob/main/versions/1.0/SPEC.md#versioning
it should "work with `version 1.0` surrounded by comments" in {

val source =
"""
|# My WDL does a cool thing
|version 1.0
|# Here we go...
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "reject Chris's idea of a version declaration" in {

val source =
"""
|# Thank goodness this WDL is not version 1.1!
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe false
}

}

0 comments on commit 012d16b

Please sign in to comment.