diff --git a/cwltool/load_tool.py b/cwltool/load_tool.py index 986255364..38573a2ed 100644 --- a/cwltool/load_tool.py +++ b/cwltool/load_tool.py @@ -22,6 +22,7 @@ from . import process, update from .errors import WorkflowException from .process import Process, shortname +from .update import ALLUPDATES _logger = logging.getLogger("cwltool") @@ -161,12 +162,17 @@ def validate_document(document_loader, # type: Loader if "cwlVersion" in workflowobj: if not isinstance(workflowobj["cwlVersion"], (str, Text)): raise Exception("'cwlVersion' must be a string, got %s" % type(workflowobj["cwlVersion"])) + if workflowobj["cwlVersion"] not in list(ALLUPDATES): + # print out all the Supported Versions of cwlVersion + versions = list(ALLUPDATES) # ALLUPDATES is a dict + versions.sort() + raise ValidationException("'cwlVersion' not valid. Supported CWL versions are: \n{}".format("\n".join(versions))) workflowobj["cwlVersion"] = re.sub( r"^(?:cwl:|https://w3id.org/cwl/cwl#)", "", workflowobj["cwlVersion"]) else: - _logger.warning("No cwlVersion found, treating this file as draft-2.") - workflowobj["cwlVersion"] = "draft-2" + raise ValidationException("No cwlVersion found." + "Use the following syntax in your CWL workflow to declare version: cwlVersion: ") if workflowobj["cwlVersion"] == "draft-2": workflowobj = cast(CommentedMap, cmap(update._draft2toDraft3dev1( diff --git a/tests/test_cwl_version.py b/tests/test_cwl_version.py new file mode 100644 index 000000000..c78a01375 --- /dev/null +++ b/tests/test_cwl_version.py @@ -0,0 +1,14 @@ +from __future__ import absolute_import +import unittest + +from cwltool.main import main + +from .util import get_data + +class CWL_Version_Checks(unittest.TestCase): + # no cwlVersion in the workflow + def test_missing_cwl_version(self): + self.assertEqual(main([get_data('tests/wf/missing_cwlVersion.cwl')]), 1) + # using cwlVersion: v0.1 in the workflow + def test_incorrect_cwl_version(self): + self.assertEqual(main([get_data('tests/wf/wrong_cwlVersion.cwl')]), 1) diff --git a/tests/wf/missing_cwlVersion.cwl b/tests/wf/missing_cwlVersion.cwl new file mode 100644 index 000000000..951842d36 --- /dev/null +++ b/tests/wf/missing_cwlVersion.cwl @@ -0,0 +1,31 @@ +#!/usr/bin/env cwl-runner +class: Workflow + +label: "Hello World" +doc: "Outputs a message using echo" + +inputs: [] + +outputs: + response: + outputSource: step0/response + type: File + +steps: + step0: + run: + class: CommandLineTool + inputs: + message: + type: string + doc: "The message to print" + default: "Hello World" + inputBinding: + position: 1 + baseCommand: echo + stdout: response.txt + outputs: + response: + type: stdout + in: [] + out: [response] diff --git a/tests/wf/wrong_cwlVersion.cwl b/tests/wf/wrong_cwlVersion.cwl new file mode 100644 index 000000000..3bac9583b --- /dev/null +++ b/tests/wf/wrong_cwlVersion.cwl @@ -0,0 +1,32 @@ +#!/usr/bin/env cwl-runner +cwlVersion: v0.1 +class: Workflow + +label: "Hello World" +doc: "Outputs a message using echo" + +inputs: [] + +outputs: + response: + outputSource: step0/response + type: File + +steps: + step0: + run: + class: CommandLineTool + inputs: + message: + type: string + doc: "The message to print" + default: "Hello World" + inputBinding: + position: 1 + baseCommand: echo + stdout: response.txt + outputs: + response: + type: stdout + in: [] + out: [response]