Skip to content

Commit ee5ba7c

Browse files
authored
add more tests (#35)
1 parent ebb68dd commit ee5ba7c

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

src/test/java/org/w3id/cwl/cwl1_2/utils/ExamplesTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7642,4 +7642,59 @@ public void testvalid_listing_deep2ByMap() throws Exception {
76427642
doc = (java.util.Map<String, Object>) YamlUtils.mapFromString(yaml);
76437643
RootLoader.loadDocument(doc);
76447644
}
7645+
7646+
@org.junit.Test(expected = ValidationException.class)
7647+
public void testvalid_rename_inputsByString() throws Exception {
7648+
String path = java.nio.file.Paths.get(".").toAbsolutePath().normalize().toString();
7649+
String baseUri = Uris.fileUri(path) + "/";
7650+
java.net.URL url = getClass().getResource("valid_rename-inputs.cwl");
7651+
java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
7652+
String yaml = new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");
7653+
RootLoader.loadDocument(yaml, baseUri);
7654+
}
7655+
7656+
@org.junit.Test(expected = ValidationException.class)
7657+
public void testvalid_rename_inputsByPath() throws Exception {
7658+
java.net.URL url = getClass().getResource("valid_rename-inputs.cwl");
7659+
java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
7660+
RootLoader.loadDocument(resPath);
7661+
}
7662+
7663+
@org.junit.Test(expected = ValidationException.class)
7664+
public void testvalid_rename_inputsByMap() throws Exception {
7665+
java.net.URL url = getClass().getResource("valid_rename-inputs.cwl");
7666+
java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
7667+
String yaml = new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");
7668+
java.util.Map<String, Object> doc;
7669+
doc = (java.util.Map<String, Object>) YamlUtils.mapFromString(yaml);
7670+
RootLoader.loadDocument(doc);
7671+
}
7672+
7673+
@org.junit.Test
7674+
public void testvalid_rename_outputsByString() throws Exception {
7675+
String path = java.nio.file.Paths.get(".").toAbsolutePath().normalize().toString();
7676+
String baseUri = Uris.fileUri(path) + "/";
7677+
java.net.URL url = getClass().getResource("valid_rename-outputs.cwl");
7678+
java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
7679+
String yaml = new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");
7680+
RootLoader.loadDocument(yaml, baseUri);
7681+
}
7682+
7683+
@org.junit.Test
7684+
public void testvalid_rename_outputsByPath() throws Exception {
7685+
java.net.URL url = getClass().getResource("valid_rename-outputs.cwl");
7686+
java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
7687+
RootLoader.loadDocument(resPath);
7688+
}
7689+
7690+
@org.junit.Test
7691+
public void testvalid_rename_outputsByMap() throws Exception {
7692+
java.net.URL url = getClass().getResource("valid_rename-outputs.cwl");
7693+
java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
7694+
String yaml = new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");
7695+
java.util.Map<String, Object> doc;
7696+
doc = (java.util.Map<String, Object>) YamlUtils.mapFromString(yaml);
7697+
RootLoader.loadDocument(doc);
7698+
}
7699+
76457700
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
inputWithSecondary:
2+
class: File
3+
location: secondary_file_test.txt
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env cwl-runner
2+
id: InputSecondaryFileConformanceTest
3+
baseCommand:
4+
- ls
5+
class: CommandLineTool
6+
cwlVersion: v1.2
7+
doc: |
8+
Simple test to confirm the implementation of expressions returning a File within a CommandInputParameter.secondaryFile field.
9+
10+
Use GREP to filter the result from ls to ensure we only get the secondary files in there.
11+
12+
Related links:
13+
- Issue: https://github.com/common-workflow-language/cwltool/issues/1232
14+
- PR: https://github.com/common-workflow-language/cwltool/pull/1233
15+
- Discourse: https://cwl.discourse.group/t/ask-cwl-to-rename-a-secondary-file/72
16+
17+
inputs:
18+
- id: inputWithSecondary
19+
type: File
20+
doc: |
21+
This input will with a secondary file `.accessory`. You could create these files (and its accessory) with:
22+
```bash
23+
touch secondary_file_test.txt
24+
touch secondary_file_test.txt.accessory
25+
```
26+
secondaryFiles:
27+
- .accessory
28+
- |
29+
${
30+
function resolveSecondary(base, secPattern) {
31+
if (secPattern[0] == '^') {
32+
var spl = base.split('.');
33+
var endIndex = spl.length > 1 ? spl.length - 1 : 1;
34+
return resolveSecondary(spl.slice(undefined, endIndex).join("."), secPattern.slice(1));
35+
}
36+
return base + secPattern;
37+
}
38+
return [{
39+
"class": "File",
40+
"location": self.secondaryFiles[0].location,
41+
"basename": resolveSecondary(self.basename, '^.accessory')
42+
}];
43+
}
44+
45+
arguments:
46+
- valueFrom: "|"
47+
shellQuote: false
48+
position: 0
49+
- valueFrom: "grep"
50+
position: 1
51+
- valueFrom: "secondary"
52+
position: 2
53+
54+
outputs:
55+
- id: output_file
56+
type: stdout
57+
stdout: result
58+
requirements:
59+
InlineJavascriptRequirement: {}
60+
ShellCommandRequirement: {}
61+
InitialWorkDirRequirement:
62+
listing:
63+
- $(inputs.inputWithSecondary)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env cwl-runner
2+
id: OutputSecondaryFileConformanceTest
3+
baseCommand:
4+
- ls
5+
class: CommandLineTool
6+
cwlVersion: v1.2
7+
doc: |
8+
Simple test to confirm the implementation of expressions returning a File within a CommandOutputParameter.secondaryFile field.
9+
10+
Related links:
11+
- Issue: https://github.com/common-workflow-language/cwltool/issues/1232
12+
- PR: https://github.com/common-workflow-language/cwltool/pull/1233
13+
- Discourse: https://cwl.discourse.group/t/ask-cwl-to-rename-a-secondary-file/72
14+
15+
inputs: []
16+
outputs:
17+
- id: output_file
18+
label: out
19+
outputBinding:
20+
glob: "*.txt"
21+
secondaryFiles: |
22+
${
23+
function resolveSecondary(base, secPattern) {
24+
if (secPattern[0] == "^") {
25+
var spl = base.split(".");
26+
var endIndex = spl.length > 1 ? spl.length - 1 : 1;
27+
return resolveSecondary(spl.slice(undefined, endIndex).join("."), secPattern.slice(1));
28+
}
29+
return base + secPattern;
30+
}
31+
return [
32+
{
33+
"class": "File",
34+
"path": resolveSecondary(self.path, "^.accessory"),
35+
"basename": resolveSecondary(self.basename, ".accessory")
36+
}
37+
];
38+
}
39+
type: File
40+
requirements:
41+
InlineJavascriptRequirement: {}
42+
InitialWorkDirRequirement:
43+
listing:
44+
- entry: ""
45+
entryname: secondary_file_test.txt
46+
writable: true
47+
- entry: ""
48+
entryname: secondary_file_test.accessory
49+
writable: true

0 commit comments

Comments
 (0)