Skip to content

Commit 5b6d500

Browse files
committed
Add js-output tests
1 parent 5e2e188 commit 5b6d500

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

tests/test_examples.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
from __future__ import absolute_import
22
import unittest
3+
import pytest
4+
import subprocess
5+
6+
try:
7+
from cStringIO import StringIO
8+
except ModuleNotFoundError:
9+
from io import StringIO
310

411
import cwltool.expression as expr
512
import cwltool.factory
@@ -516,5 +523,34 @@ def test_print_dot(self):
516523
self.assertEquals(main(["--print-dot", get_data('tests/wf/revsort.cwl')]), 0)
517524

518525

526+
class TestJsConsole(unittest.TestCase):
527+
def reload_sandboxjs(self):
528+
# Reload sandboxjs to remove set globals
529+
import cwltool.sandboxjs
530+
reload(cwltool.sandboxjs)
531+
532+
def test_js_console_cmd_line_tool(self):
533+
for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
534+
self.reload_sandboxjs()
535+
pipe = StringIO()
536+
self.assertEquals(main(["--js-console", get_data("tests/wf/" + test_file)], stderr=pipe), 0)
537+
538+
output = pipe.getvalue()
539+
pipe.close()
540+
541+
self.assertIn("[log] Log message", output)
542+
self.assertIn("[err] Error message", output)
543+
544+
def test_no_js_console(self):
545+
for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
546+
self.reload_sandboxjs()
547+
pipe = StringIO()
548+
self.assertEquals(main([get_data("tests/wf/" + test_file)], stderr=pipe), 1)
549+
550+
output = pipe.getvalue()
551+
pipe.close()
552+
553+
self.assertIn("ReferenceError: console is not defined", output)
554+
519555
if __name__ == '__main__':
520556
unittest.main()

tests/wf/js_output.cwl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.0
3+
requirements:
4+
- class: InlineJavascriptRequirement
5+
inputs: []
6+
outputs: []
7+
arguments:
8+
- valueFrom: ${console.log("Log message");console.error("Error message");return "true";}

tests/wf/js_output_workflow.cwl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class: Workflow
2+
cwlVersion: v1.0
3+
requirements:
4+
- class: InlineJavascriptRequirement
5+
inputs: []
6+
outputs: []
7+
steps:
8+
- id: js_log
9+
in: []
10+
out: []
11+
run:
12+
class: ExpressionTool
13+
inputs: []
14+
outputs: []
15+
expression: ${console.log("Log message");console.error("Error message");return "true";}

0 commit comments

Comments
 (0)