Skip to content

Commit

Permalink
chore: more file tests for task evaluation.
Browse files Browse the repository at this point in the history
These test cases come directly from the 1.2 WDL specification.
  • Loading branch information
peterhuene committed Dec 10, 2024
1 parent 100d3ab commit 465838d
Show file tree
Hide file tree
Showing 76 changed files with 367 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/change-extension-task/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"change_extension.prefix": "foo"
}
5 changes: 5 additions & 0 deletions wdl-engine/tests/tasks/change-extension-task/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"change_extension.data_file": "work/foo.data",
"change_extension.data": "data",
"change_extension.index": "index"
}
22 changes: 22 additions & 0 deletions wdl-engine/tests/tasks/change-extension-task/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version 1.2

task change_extension {
input {
String prefix
}

command <<<
printf "data" > '~{prefix}.data'
printf "index" > '~{prefix}.index'
>>>

output {
File data_file = "~{prefix}.data"
String data = read_string(data_file)
String index = read_string(sub(data_file, "\\.data$", ".index"))
}

requirements {
container: "ubuntu:latest"
}
}
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions wdl-engine/tests/tasks/file-sizes-task/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: type mismatch: argument to function `size` expects type `None`, `File?`, `String?`, `Directory?`, or `X` where `X`: any compound type that recursively contains a `File` or `Directory`, but found type `Map[String, Pair[Int, String?]]`
┌─ tests/tasks/file-sizes-task/source.wdl:14:31
14 │ Float nested_bytes = size({
│ ╭───────────────────────────────^
15 │ │ "a": (10, "created_file"),
16 │ │ "b": (50, missing_file)
17 │ │ })
│ ╰─────^ this is type `Map[String, Pair[Int, String?]]`

1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/file-sizes-task/files/created_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this file is 22 bytes
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/file-sizes-task/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions wdl-engine/tests/tasks/file-sizes-task/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_sizes.created_file": "work/created_file",
"file_sizes.missing_file_bytes": 0.0,
"file_sizes.created_file_bytes": 22.0,
"file_sizes.multi_file_kb": 0.022,
"file_sizes.nested_bytes": 22.0
}
24 changes: 24 additions & 0 deletions wdl-engine/tests/tasks/file-sizes-task/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version 1.2

task file_sizes {
command <<<
printf "this file is 22 bytes\n" > created_file
>>>

File? missing_file = None

output {
File created_file = "created_file"
Float missing_file_bytes = size(missing_file)
Float created_file_bytes = size(created_file, "B")
Float multi_file_kb = size([created_file, missing_file], "K")
Float nested_bytes = size({
"a": (10, created_file),
"b": (50, missing_file)
})
}

requirements {
container: "ubuntu:latest"
}
}
Empty file.
Empty file.
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/test-basename/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions wdl-engine/tests/tasks/test-basename/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_basename.is_true1": true,
"test_basename.is_true2": true,
"test_basename.is_true3": true
}
11 changes: 11 additions & 0 deletions wdl-engine/tests/tasks/test-basename/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version 1.2

task test_basename {
command <<<>>>

output {
Boolean is_true1 = basename("/path/to/file.txt") == "file.txt"
Boolean is_true2 = basename("/path/to/file.txt", ".txt") == "file"
Boolean is_true3 = basename("/path/to/dir") == "dir"
}
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/test-ceil/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test_ceil.i1": 2
}
6 changes: 6 additions & 0 deletions wdl-engine/tests/tasks/test-ceil/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"test_ceil.all_true": [
true,
true
]
}
17 changes: 17 additions & 0 deletions wdl-engine/tests/tasks/test-ceil/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version 1.2

task test_ceil {
input {
Int i1
}

Int i2 = i1 + 1
Float f1 = i1
Float f2 = i1 + 0.1

command <<<>>>

output {
Array[Boolean] all_true = [ceil(f1) == i1, ceil(f2) == i2]
}
}
Empty file.
Empty file.
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/test-find/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions wdl-engine/tests/tasks/test-find/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"find_string.match1": "ello",
"find_string.match2": null
}
16 changes: 16 additions & 0 deletions wdl-engine/tests/tasks/test-find/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version 1.2

task find_string {
input {
String in = "hello world"
String pattern1 = "e..o"
String pattern2 = "goodbye"
}

command <<<>>>

output {
String? match1 = find(in, pattern1) # "ello"
String? match2 = find(in, pattern2) # None
}
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/test-floor/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test_floor.i1": 2
}
6 changes: 6 additions & 0 deletions wdl-engine/tests/tasks/test-floor/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"test_floor.all_true": [
true,
true
]
}
17 changes: 17 additions & 0 deletions wdl-engine/tests/tasks/test-floor/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version 1.2

task test_floor {
input {
Int i1
}

Int i2 = i1 - 1
Float f1 = i1
Float f2 = i1 - 0.1

command <<<>>>

output {
Array[Boolean] all_true = [floor(f1) == i1, floor(f2) == i2]
}
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/test-join-paths/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions wdl-engine/tests/tasks/test-join-paths/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"resolve_paths_task.bins_equal": true,
"resolve_paths_task.result": "hello",
"resolve_paths_task.missing_file": null
}
38 changes: 38 additions & 0 deletions wdl-engine/tests/tasks/test-join-paths/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version 1.2

task resolve_paths_task {
input {
File abs_file = "/usr"
String abs_str = "/usr"
String rel_dir_str = "bin"
File rel_file = "echo"
File rel_dir_file = "mydir"
String rel_str = "mydata.txt"
}

# these are all equivalent to '/usr/bin/echo'
File bin1 = join_paths(abs_file, [rel_dir_str, rel_file])
File bin2 = join_paths(abs_str, [rel_dir_str, rel_file])
File bin3 = join_paths([abs_str, rel_dir_str, rel_file])

# the default behavior is that this resolves to
# '<working dir>/mydir/mydata.txt'
File data = join_paths(rel_dir_file, rel_str)

# this resolves to '<working dir>/bin/echo', which is non-existent
File doesnt_exist = join_paths([rel_dir_str, rel_file])
command <<<
mkdir ~{rel_dir_file}
echo -n "hello" > ~{data}
>>>

output {
Boolean bins_equal = (bin1 == bin2) && (bin1 == bin3)
String result = read_string(data)
File? missing_file = doesnt_exist
}

runtime {
container: "ubuntu:latest"
}
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/test-matches/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contains_string.fastq": "sample1234_R1.fastq"
}
4 changes: 4 additions & 0 deletions wdl-engine/tests/tasks/test-matches/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"contains_string.is_compressed": false,
"contains_string.is_read1": true
}
14 changes: 14 additions & 0 deletions wdl-engine/tests/tasks/test-matches/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version 1.2

task contains_string {
input {
File fastq
}

command <<<>>>

output {
Boolean is_compressed = matches(basename(fastq), "\\.(gz|zip|zstd)")
Boolean is_read1 = matches(basename(fastq), "_R1")
}
}
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions wdl-engine/tests/tasks/test-max/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test_max.value1": 1,
"test_max.value2": 2.0
}
4 changes: 4 additions & 0 deletions wdl-engine/tests/tasks/test-max/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test_max.max1": 2.0,
"test_max.max2": 2.0
}
16 changes: 16 additions & 0 deletions wdl-engine/tests/tasks/test-max/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version 1.2

task test_max {
input {
Int value1
Float value2
}

command <<<>>>

output {
# these two expressions are equivalent
Float max1 = if value1 > value2 then value1 else value2
Float max2 = max(value1, value2)
}
}
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions wdl-engine/tests/tasks/test-min/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test_min.value1": 1,
"test_min.value2": 2.0
}
4 changes: 4 additions & 0 deletions wdl-engine/tests/tasks/test-min/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test_min.min1": 1.0,
"test_min.min2": 1.0
}
16 changes: 16 additions & 0 deletions wdl-engine/tests/tasks/test-min/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version 1.2

task test_min {
input {
Int value1
Float value2
}

command <<<>>>

output {
# these two expressions are equivalent
Float min1 = if value1 < value2 then value1 else value2
Float min2 = min(value1, value2)
}
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/test-round/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test_round.i1": 2
}
6 changes: 6 additions & 0 deletions wdl-engine/tests/tasks/test-round/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"test_round.all_true": [
true,
true
]
}
17 changes: 17 additions & 0 deletions wdl-engine/tests/tasks/test-round/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version 1.2

task test_round {
input {
Int i1
}

Int i2 = i1 + 1
Float f1 = i1 + 0.49
Float f2 = i1 + 0.50

command <<<>>>

output {
Array[Boolean] all_true = [round(f1) == i1, round(f2) == i2]
}
}
Empty file.
Empty file.
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/test-stderr/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/test-stderr/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"echo_stderr.message": "hello world"
}
9 changes: 9 additions & 0 deletions wdl-engine/tests/tasks/test-stderr/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version 1.2

task echo_stderr {
command <<< >&2 printf "hello world" >>>

output {
String message = read_string(stderr())
}
}
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/test-stderr/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
Empty file.
1 change: 1 addition & 0 deletions wdl-engine/tests/tasks/test-stdout/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions wdl-engine/tests/tasks/test-stdout/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"echo_stdout.message": "hello world"
}
Loading

0 comments on commit 465838d

Please sign in to comment.