diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f839ccac..6dcde7956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# viash 0.5.3 + +## NEW FEATURES + +* Similar to `par`, each script now also has a `meta` list. `meta` contains meta information about the component + or the execution thereof. It currently has the following fields: + - `meta["resources_dir"]`: Path to the directory containing the resources + - `meta["functionality_name"]`: Name of the component + +* `NextFlowPlatform`: Export `VIASH_TEMP` environment variable. + +## BUG FIXES + +* `NextFlowPlatform`: Fix output formatting when `separate_multiple_outputs` is `false`. + # viash 0.5.2 ## MINOR CHANGES diff --git a/build.sbt b/build.sbt index 3aab0a270..4996f956a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ name := "viash" -version := "0.5.2" +version := "0.5.3" scalaVersion := "2.12.10" diff --git a/src/main/scala/com/dataintuitive/viash/functionality/resources/BashScript.scala b/src/main/scala/com/dataintuitive/viash/functionality/resources/BashScript.scala index efb63690f..929625779 100644 --- a/src/main/scala/com/dataintuitive/viash/functionality/resources/BashScript.scala +++ b/src/main/scala/com/dataintuitive/viash/functionality/resources/BashScript.scala @@ -19,6 +19,7 @@ package com.dataintuitive.viash.functionality.resources import com.dataintuitive.viash.functionality._ import com.dataintuitive.viash.functionality.dataobjects._ +import com.dataintuitive.viash.wrapper.BashWrapper import java.net.URI @@ -38,11 +39,14 @@ case class BashScript( def generatePlaceholder(functionality: Functionality): String = { val params = functionality.arguments.filter(d => d.direction == Input || d.isInstanceOf[FileObject]) - val par_set = params.map { par => + val parSet = params.map { par => s"""${par.par}='$$${par.VIASH_PAR}'""" } - s"""${par_set.mkString("\n")} - | + val metaSet = BashWrapper.metaFields.map{ case (env_name, script_name) => + s"""meta_$script_name='$$$env_name'""".stripMargin + } + s"""${parSet.mkString("\n")} + |${metaSet.mkString("\n")} |resources_dir="$$VIASH_RESOURCES_DIR" |""".stripMargin } diff --git a/src/main/scala/com/dataintuitive/viash/functionality/resources/CSharpScript.scala b/src/main/scala/com/dataintuitive/viash/functionality/resources/CSharpScript.scala index 800619983..68cc36794 100644 --- a/src/main/scala/com/dataintuitive/viash/functionality/resources/CSharpScript.scala +++ b/src/main/scala/com/dataintuitive/viash/functionality/resources/CSharpScript.scala @@ -19,6 +19,7 @@ package com.dataintuitive.viash.functionality.resources import com.dataintuitive.viash.functionality._ import com.dataintuitive.viash.functionality.dataobjects._ +import com.dataintuitive.viash.wrapper.BashWrapper import java.net.URI @@ -83,10 +84,15 @@ case class CSharpScript( s"${par.plainName} = $setter" } + val metaSet = BashWrapper.metaFields.map{ case (env_name, script_name) => + s"""$script_name = "$$$env_name"""" + } s"""var par = new { | ${parSet.mkString(",\n ")} |}; - | + |var meta = new { + | ${metaSet.mkString(",\n ")} + |}; |var resources_dir = "$$VIASH_RESOURCES_DIR"; |""".stripMargin } diff --git a/src/main/scala/com/dataintuitive/viash/functionality/resources/JavaScriptScript.scala b/src/main/scala/com/dataintuitive/viash/functionality/resources/JavaScriptScript.scala index 7216c68b1..3fe38ec75 100644 --- a/src/main/scala/com/dataintuitive/viash/functionality/resources/JavaScriptScript.scala +++ b/src/main/scala/com/dataintuitive/viash/functionality/resources/JavaScriptScript.scala @@ -19,6 +19,7 @@ package com.dataintuitive.viash.functionality.resources import com.dataintuitive.viash.functionality._ import com.dataintuitive.viash.functionality.dataobjects._ +import com.dataintuitive.viash.wrapper.BashWrapper import java.net.URI @@ -38,7 +39,7 @@ case class JavaScriptScript( def generatePlaceholder(functionality: Functionality): String = { val params = functionality.arguments.filter(d => d.direction == Input || d.isInstanceOf[FileObject]) - val par_set = params.map { par => + val parSet = params.map { par => val env_name = par.VIASH_PAR val parse = par match { @@ -61,10 +62,15 @@ case class JavaScriptScript( s"""'${par.plainName}': $$VIASH_DOLLAR$$( if [ ! -z $${$env_name+x} ]; then echo "$parse"; else echo undefined; fi )""" } + val metaSet = BashWrapper.metaFields.map{ case (env_name, script_name) => + s"""'$script_name': '$$$env_name'""" + } s"""let par = { - | ${par_set.mkString(",\n ")} + | ${parSet.mkString(",\n ")} + |}; + |let meta = { + | ${metaSet.mkString(",\n ")} |}; - | |let resources_dir = '$$VIASH_RESOURCES_DIR' |""".stripMargin } diff --git a/src/main/scala/com/dataintuitive/viash/functionality/resources/PythonScript.scala b/src/main/scala/com/dataintuitive/viash/functionality/resources/PythonScript.scala index 2f98bed3a..f4aafcb25 100644 --- a/src/main/scala/com/dataintuitive/viash/functionality/resources/PythonScript.scala +++ b/src/main/scala/com/dataintuitive/viash/functionality/resources/PythonScript.scala @@ -19,6 +19,7 @@ package com.dataintuitive.viash.functionality.resources import com.dataintuitive.viash.functionality._ import com.dataintuitive.viash.functionality.dataobjects._ +import com.dataintuitive.viash.wrapper.BashWrapper import java.net.URI @@ -38,7 +39,7 @@ case class PythonScript( def generatePlaceholder(functionality: Functionality): String = { val params = functionality.arguments.filter(d => d.direction == Input || d.isInstanceOf[FileObject]) - val par_set = params.map { par => + val parSet = params.map { par => val env_name = par.VIASH_PAR val parse = par match { @@ -61,8 +62,15 @@ case class PythonScript( s"""'${par.plainName}': $$VIASH_DOLLAR$$( if [ ! -z $${$env_name+x} ]; then echo "$parse"; else echo None; fi )""" } + val metaSet = BashWrapper.metaFields.map{ case (env_name, script_name) => + s"""'$script_name': '$$$env_name'""" + } + s"""par = { - | ${par_set.mkString(",\n ")} + | ${parSet.mkString(",\n ")} + |} + |meta = { + | ${metaSet.mkString(",\n ")} |} | |resources_dir = '$$VIASH_RESOURCES_DIR' diff --git a/src/main/scala/com/dataintuitive/viash/functionality/resources/RScript.scala b/src/main/scala/com/dataintuitive/viash/functionality/resources/RScript.scala index 17251db8d..88ff3d6c4 100644 --- a/src/main/scala/com/dataintuitive/viash/functionality/resources/RScript.scala +++ b/src/main/scala/com/dataintuitive/viash/functionality/resources/RScript.scala @@ -19,6 +19,7 @@ package com.dataintuitive.viash.functionality.resources import com.dataintuitive.viash.functionality._ import com.dataintuitive.viash.functionality.dataobjects._ +import com.dataintuitive.viash.wrapper.BashWrapper import java.net.URI @@ -38,7 +39,7 @@ case class RScript( def generatePlaceholder(functionality: Functionality): String = { val params = functionality.arguments.filter(d => d.direction == Input || d.isInstanceOf[FileObject]) - val par_set = params.map { par => + val parSet = params.map { par => val env_name = par.VIASH_PAR val parse = par match { @@ -61,10 +62,21 @@ case class RScript( s""""${par.plainName}" = $$VIASH_DOLLAR$$( if [ ! -z $${$env_name+x} ]; then echo "$parse"; else echo NULL; fi )""" } - s"""par <- list( - | ${par_set.mkString(",\n ")} + val metaSet = BashWrapper.metaFields.map{ case (env_name, script_name) => + s"""$script_name = "$$$env_name"""" + } + + s"""# get parameters from cli + |par <- list( + | ${parSet.mkString(",\n ")} + |) + | + |# get meta parameters + |meta <- list( + | ${metaSet.mkString(",\n ")} |) | + |# get resources dir |resources_dir = "$$VIASH_RESOURCES_DIR" |""".stripMargin } diff --git a/src/main/scala/com/dataintuitive/viash/functionality/resources/ScalaScript.scala b/src/main/scala/com/dataintuitive/viash/functionality/resources/ScalaScript.scala index 30782e577..afaa089aa 100644 --- a/src/main/scala/com/dataintuitive/viash/functionality/resources/ScalaScript.scala +++ b/src/main/scala/com/dataintuitive/viash/functionality/resources/ScalaScript.scala @@ -19,6 +19,7 @@ package com.dataintuitive.viash.functionality.resources import com.dataintuitive.viash.functionality._ import com.dataintuitive.viash.functionality.dataobjects._ +import com.dataintuitive.viash.wrapper.BashWrapper import java.net.URI @@ -38,7 +39,7 @@ case class ScalaScript( def generatePlaceholder(functionality: Functionality): String = { val params = functionality.arguments.filter(d => d.direction == Input || d.isInstanceOf[FileObject]) - val classTypes = params.map { par => + val parClassTypes = params.map { par => val classType = par match { case o: BooleanObject if o.multiple => "List[Boolean]" case o: IntegerObject if o.multiple => "List[Integer]" @@ -58,9 +59,7 @@ case class ScalaScript( case _: StringObject => "String" } par.plainName + ": " + classType - } - val parSet = params.map { par => val env_name = par.VIASH_PAR @@ -100,14 +99,27 @@ case class ScalaScript( case None => parse } } + + val metaClassTypes = BashWrapper.metaFields.map { case (_, script_name) => + script_name + ": String" + } + val metaSet = BashWrapper.metaFields.map { case (env_name, script_name) => + s""""$$$env_name"""" + } s"""case class ViashPar( - | ${classTypes.mkString(",\n ")} + | ${parClassTypes.mkString(",\n ")} |) - | |val par = ViashPar( | ${parSet.mkString(",\n ")} |) | + |case class ViashMeta( + | ${metaClassTypes.mkString(",\n ")} + |) + |val meta = ViashMeta( + | ${metaSet.mkString(",\n ")} + |) + | |val resources_dir = "$$VIASH_RESOURCES_DIR" |""".stripMargin } diff --git a/src/main/scala/com/dataintuitive/viash/platforms/NextFlowPlatform.scala b/src/main/scala/com/dataintuitive/viash/platforms/NextFlowPlatform.scala index 9b5275cb0..1e3c9e97a 100644 --- a/src/main/scala/com/dataintuitive/viash/platforms/NextFlowPlatform.scala +++ b/src/main/scala/com/dataintuitive/viash/platforms/NextFlowPlatform.scala @@ -167,7 +167,7 @@ case class NextFlowPlatform( */ val asNestedTuples: List[ConfigTuple] = List( "docker.enabled" → true, - "docker.runOptions" → "-i -v ${baseDir}:${baseDir}", + "def viash_temp = System.getenv(\"VIASH_TEMP\") ?: \"/tmp/\"\n docker.runOptions" → "-i -v ${baseDir}:${baseDir} -v $viash_temp:$viash_temp", "process.container" → "dataintuitive/viash", "params" → NestedValue( namespacedParameters ::: @@ -461,11 +461,14 @@ case class NextFlowPlatform( | STUB=1 $$cli | \"\"\" | script: + | def viash_temp = System.getenv("VIASH_TEMP") ?: "/tmp/" | if (params.test) | \"\"\" | # Some useful stuff | export NUMBA_CACHE_DIR=/tmp/numba-cache | # Running the pre-hook when necessary + | # Pass viash temp dir + | export VIASH_TEMP="$${viash_temp}" | # Adding NXF's `$$moduleDir` to the path in order to resolve our own wrappers | export PATH="./:$${moduleDir}:\\$$PATH" | ./$${params.$fname.tests.testScript} | tee $$output @@ -475,6 +478,8 @@ case class NextFlowPlatform( | # Some useful stuff | export NUMBA_CACHE_DIR=/tmp/numba-cache | # Running the pre-hook when necessary + | # Pass viash temp dir + | export VIASH_TEMP="$${viash_temp}" | # Adding NXF's `$$moduleDir` to the path in order to resolve our own wrappers | export PATH="$${moduleDir}:\\$$PATH" | $$cli @@ -499,7 +504,7 @@ case class NextFlowPlatform( s""" emit: | result_.flatMap{ it -> | (it[1].keySet().size() > 1) - | ? it + | ? [ it ] | : it[1].collect{ k, el -> [ it[0], el, it[2] ] } | }""".stripMargin } diff --git a/src/main/scala/com/dataintuitive/viash/wrapper/BashWrapper.scala b/src/main/scala/com/dataintuitive/viash/wrapper/BashWrapper.scala index 60c1dac28..d1b80fed0 100644 --- a/src/main/scala/com/dataintuitive/viash/wrapper/BashWrapper.scala +++ b/src/main/scala/com/dataintuitive/viash/wrapper/BashWrapper.scala @@ -24,6 +24,12 @@ import com.dataintuitive.viash.functionality.dataobjects._ import com.dataintuitive.viash.helpers.{Bash, Format} object BashWrapper { + val metaFields: List[(String, String)] = { + List( + ("VIASH_META_FUNCTIONALITY_NAME", "functionality_name"), + ("VIASH_RESOURCES_DIR", "resources_dir") + ) + } def nameAndVersion(functionality: Functionality): String = { functionality.name + functionality.version.map(" " + _).getOrElse(" ") @@ -179,6 +185,9 @@ object BashWrapper { |# find source folder of this component |$var_resources_dir=`ViashSourceDir $${BASH_SOURCE[0]}` | + |# define meta fields + |VIASH_META_FUNCTIONALITY_NAME="${functionality.name}" + | |${spaceCode(allMods.preParse)} |# initialise array |VIASH_POSITIONAL_ARGS='' diff --git a/src/test/resources/testbash/code.sh b/src/test/resources/testbash/code.sh index 50e6b75c9..c1fc3f4da 100755 --- a/src/test/resources/testbash/code.sh +++ b/src/test/resources/testbash/code.sh @@ -12,6 +12,7 @@ par_output="output.txt" par_log="log.txt" par_optional="help" par_optional_with_default="me" +meta_functionality_name="testbash" resources_dir="." # VIASH END @@ -58,3 +59,6 @@ RESOURCE=`head -1 "$resources_dir/resource1.txt"` output "head of resource1: |$RESOURCE|" output "multiple: |$par_multiple|" output "multiple_pos: |$par_multiple_pos|" + +output "meta_functionality_name: |$meta_functionality_name|" +output "meta_resources_dir: |$meta_resources_dir|" diff --git a/src/test/resources/testbash/tests/check_outputs.sh b/src/test/resources/testbash/tests/check_outputs.sh index e1c80ce7b..53c3954e5 100755 --- a/src/test/resources/testbash/tests/check_outputs.sh +++ b/src/test/resources/testbash/tests/check_outputs.sh @@ -24,6 +24,8 @@ grep -q 'optional: |foo|' output.txt grep -q 'optional_with_default: |bar|' output.txt grep -q 'multiple: |one:two|' output.txt grep -q 'multiple_pos: |a:b:c:d:e:f|' output.txt +grep -q 'meta_functionality_name: |testbash|' output.txt +grep -q 'meta_resources_dir: |..*|' output.txt grep -q 'resources_dir: |..*|' output.txt grep -q 'head of input: |Scala|' output.txt @@ -51,6 +53,9 @@ grep -q 'optional_with_default: |The default value.|' output2.txt grep -q 'multiple: ||' output2.txt grep -q 'multiple_pos: ||' output2.txt +grep -q 'meta_functionality_name: |testbash|' output2.txt +grep -q 'meta_resources_dir: |..*|' output2.txt + grep -q 'resources_dir: |..*|' output2.txt grep -q 'head of input: |this file is only for testing|' output2.txt grep -q 'head of resource1: |if you can read this,|' output2.txt diff --git a/src/test/resources/testcsharp/config.vsh.yaml b/src/test/resources/testcsharp/config.vsh.yaml index ab7662f4a..84a6bd526 100644 --- a/src/test/resources/testcsharp/config.vsh.yaml +++ b/src/test/resources/testcsharp/config.vsh.yaml @@ -53,5 +53,8 @@ functionality: platforms: - type: native - type: docker - image: "andmos/dotnet-script" + image: "hjerpbakk/dotnet-script:1.0.1" + setup: + - type: apk + packages: [ bash ] - type: nextflow diff --git a/src/test/resources/testcsharp/script.csx b/src/test/resources/testcsharp/script.csx index 7493007b0..995e08154 100644 --- a/src/test/resources/testcsharp/script.csx +++ b/src/test/resources/testcsharp/script.csx @@ -1,4 +1,5 @@ using System.Reflection; +using System.IO; // TODO: make sure certain stdout and stderrs are generated // TODO: write stdout and stderr to file if --output and --log are specified @@ -35,53 +36,70 @@ void Log(string log) Log("Parsed input arguments."); -if (par.output != null) -{ +StreamWriter file; +if (par.output != null) { Log("Writing output to file"); - Type t = par.GetType(); - PropertyInfo [] pi = t.GetProperties(); + file = new(par.output); +} +else +{ + Log("Printing output to console'"); +} - using (StreamWriter sw = File.AppendText(par.output)) +void Output(string str) +{ + if (par.output != null) { - foreach (PropertyInfo p in pi) - { - if (p.PropertyType.IsArray) - { - object[] array = (object[])p.GetValue(par); - - sw.Write(p.Name + ": |"); - sw.Write("{0}", string.Join(", ", array)); - sw.WriteLine("|"); - } - else - { - sw.WriteLine(p.Name + ": |" + p.GetValue(par) + "|"); - } - } - - sw.WriteLine("resources_dir: |" + resources_dir + "|"); + file.WriteLine(str); + } + else + { + System.Console.WriteLine(str); } } -else + +try { - Log("Printing output to console'"); Type t = par.GetType(); PropertyInfo [] pi = t.GetProperties(); + foreach (PropertyInfo p in pi) { if (p.PropertyType.IsArray) { object[] array = (object[])p.GetValue(par); - System.Console.Write(p.Name + ": |"); - Console.Write("{0}", string.Join(", ", array)); - System.Console.WriteLine("|"); + Output(p.Name + ": |" + string.Join(", ", array) + "|"); } else { - System.Console.WriteLine(p.Name + ": |" + p.GetValue(par) + "|"); + Output(p.Name + ": |" + p.GetValue(par) + "|"); } } - System.Console.WriteLine("resources_dir: |" + resources_dir + "|"); + Output("resources_dir: |" + resources_dir + "|"); + + t = meta.GetType(); + pi = t.GetProperties(); + + foreach (PropertyInfo p in pi) + { + if (p.PropertyType.IsArray) + { + object[] array = (object[])p.GetValue(meta); + + Output("meta_" + p.Name + ": |" + string.Join(", ", array) + "|"); + } + else + { + Output("meta_" + p.Name + ": |" + p.GetValue(meta) + "|"); + } + } +} +finally +{ + if (par.output != null) + { + file.Close(); + } } \ No newline at end of file diff --git a/src/test/resources/testcsharp/tests/check_outputs.sh b/src/test/resources/testcsharp/tests/check_outputs.sh index da6f3f28f..11d1c6936 100755 --- a/src/test/resources/testcsharp/tests/check_outputs.sh +++ b/src/test/resources/testcsharp/tests/check_outputs.sh @@ -22,6 +22,8 @@ grep -q 'optional_with_default: |bar|' output.txt grep -q 'multiple: |one, two|' output.txt grep -q 'multiple_pos: |a, b, c, d, e, f|' output.txt grep -q 'resources_dir: |..*|' output.txt +grep -q 'meta_resources_dir: |..*|' output.txt +grep -q 'meta_functionality_name: |testcsharp|' output.txt [[ ! -f log.txt ]] && echo "Log file could not be found!" && exit 1 grep -q 'Parsed input arguments.' log.txt @@ -43,5 +45,7 @@ grep -q 'optional_with_default: |The default value.|' output2.txt grep -q 'multiple: ||' output2.txt grep -q 'multiple_pos: ||' output2.txt grep -q 'resources_dir: |..*|' output2.txt +grep -q 'meta_resources_dir: |..*|' output.txt +grep -q 'meta_functionality_name: |testcsharp|' output.txt echo ">>> Test finished successfully" diff --git a/src/test/resources/testjs/code.js b/src/test/resources/testjs/code.js index 0a0e073a4..3c26f2db0 100644 --- a/src/test/resources/testjs/code.js +++ b/src/test/resources/testjs/code.js @@ -54,3 +54,6 @@ if (typeof par['output'] === 'undefined') { for (const key in par) { outFun(`${key}: |${par[key]}|`) } +for (const key in meta) { + outFun(`meta_${key}: |${meta[key]}|`) +} \ No newline at end of file diff --git a/src/test/resources/testjs/tests/check_outputs.sh b/src/test/resources/testjs/tests/check_outputs.sh index 270afec9e..3ef73257f 100755 --- a/src/test/resources/testjs/tests/check_outputs.sh +++ b/src/test/resources/testjs/tests/check_outputs.sh @@ -22,6 +22,8 @@ grep -q 'optional_with_default: |bar|' output.txt grep -q 'multiple: |one,two|' output.txt grep -q 'multiple_pos: |a,b,c,d,e,f|' output.txt grep -q 'resources_dir: |..*|' output.txt +grep -q 'meta_resources_dir: |..*|' output.txt +grep -q 'meta_functionality_name: |testjs|' output.txt [[ ! -f log.txt ]] && echo "Log file could not be found!" && exit 1 grep -q 'Parsed input arguments.' log.txt @@ -43,5 +45,7 @@ grep -q 'optional_with_default: |The default value.|' output2.txt grep -q 'multiple: |undefined|' output2.txt grep -q 'multiple_pos: |undefined|' output2.txt grep -q 'resources_dir: |..*|' output2.txt +grep -q 'meta_resources_dir: |..*|' output2.txt +grep -q 'meta_functionality_name: |testjs|' output2.txt echo ">>> Test finished successfully" diff --git a/src/test/resources/testpython/code.py b/src/test/resources/testpython/code.py index 154ec246d..a2051ef51 100644 --- a/src/test/resources/testpython/code.py +++ b/src/test/resources/testpython/code.py @@ -25,12 +25,24 @@ logging.info('Parsed input arguments.') -if par['output'] is not None: - logging.info('Writing output to file') - with open(par['output'], 'w') as f: - for key in par.keys(): - f.write(key + ": |" + str(par[key]) + "|\n") +if par['output'] is not None: + logging.info('Writing output to file') + output_file = open(par['output'], 'w') else: - logging.info('Printing output to console') - for key in par.keys(): - print(key + ": |" + str(par[key]) + "|") + logging.info('Printing output to console') + +def echo(s): + if par['output'] is not None: + output_file.write(s + "\n") + else: + print(s) + +try: + for key, value in par.items(): + echo(f"{key}: |{value}|") + + for key, value in meta.items(): + echo(f"meta_{key}: |{value}|") +finally: + if par['output'] is not None: + output_file.close() \ No newline at end of file diff --git a/src/test/resources/testpython/tests/check_outputs.py b/src/test/resources/testpython/tests/check_outputs.py index d48ae01a4..9a731c2f7 100644 --- a/src/test/resources/testpython/tests/check_outputs.py +++ b/src/test/resources/testpython/tests/check_outputs.py @@ -32,6 +32,8 @@ def test_check_output(self): self.assertRegex(output, 'optional_with_default: \\|bar\\|') self.assertRegex(output, 'multiple: \\|\\[\'one\', \'two\'\\]\\|') self.assertRegex(output, 'multiple_pos: \\|\\[\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'\\]\\|') + self.assertRegex(output, 'meta_resources_dir: \\|..*\\|') + self.assertRegex(output, 'meta_functionality_name: \\|testpython\\|') self.assertTrue(path.exists("log.txt")) diff --git a/src/test/resources/testr/script.vsh.R b/src/test/resources/testr/script.vsh.R index 3576f58ee..e72eaa862 100644 --- a/src/test/resources/testr/script.vsh.R +++ b/src/test/resources/testr/script.vsh.R @@ -77,11 +77,14 @@ write_fun <- function(file, ...) { write_fun(par$log, "INFO:Parsed input arguments.\n") -str <- paste0(names(par), ": |", par, "|\n", collapse = "") - if (length(par$output) > 0) { write_fun(par$log, 'INFO:Writing output to file\n') } else { write_fun(par$log, 'INFO:Printing output to console\n') } + +str <- paste0(names(par), ": |", par, "|\n", collapse = "") +write_fun(par$output, str) + +str <- paste0("meta_", names(meta), ": |", meta, "|\n", collapse = "") write_fun(par$output, str) diff --git a/src/test/resources/testr/tests/check_outputs.R b/src/test/resources/testr/tests/check_outputs.R index 22f3c2c5f..8a9e87b1a 100644 --- a/src/test/resources/testr/tests/check_outputs.R +++ b/src/test/resources/testr/tests/check_outputs.R @@ -28,6 +28,8 @@ test_that("Checking whether output is correct", { expect_match(output, 'optional_with_default: \\|bar\\|') expect_match(output, 'multiple: \\|c\\("one", "two"\\)\\|') expect_match(output, 'multiple_pos: \\|c\\("a", "b", "c", "d", "e", "f"\\)\\|') + expect_match(output, 'meta_resources_dir: \\|..*\\|') + expect_match(output, 'meta_functionality_name: \\|testr\\|') expect_true(file.exists("log.txt")) log <- read_file("log.txt") @@ -50,6 +52,8 @@ test_that("Checking whether output is correct with minimal parameters", { expect_match(output, 'Parsed input arguments') expect_match(output, 'multiple: \\|NULL\\|') expect_match(output, 'multiple_pos: \\|NULL\\|') + expect_match(output, 'meta_resources_dir: \\|..*\\|') + expect_match(output, 'meta_functionality_name: \\|testr\\|') }) test_that("Checking whether executable fails when wrong parameters are given", { diff --git a/src/test/resources/testscala/script.scala b/src/test/resources/testscala/script.scala index 9b80f4fd2..00e7a6be7 100644 --- a/src/test/resources/testscala/script.scala +++ b/src/test/resources/testscala/script.scala @@ -28,11 +28,13 @@ def toStringWithFields(c: AnyRef): Map[String, Any] = { try { logFun("Parsed input arguments.") - val map = toStringWithFields(par) - - for ((name, value) ← map) { + for ((name, value) ← toStringWithFields(par)) { outputFun(s"$name: |$value|") } + + for ((name, value) ← toStringWithFields(meta)) { + outputFun(s"meta_$name: |$value|") + } outputFun(s"resources_dir: |$resources_dir|") } finally { diff --git a/src/test/resources/testscala/tests/check_outputs.sh b/src/test/resources/testscala/tests/check_outputs.sh index cebf4961c..ffb251177 100755 --- a/src/test/resources/testscala/tests/check_outputs.sh +++ b/src/test/resources/testscala/tests/check_outputs.sh @@ -22,6 +22,8 @@ grep -q 'optional_with_default: |Some(bar)|' output.txt grep -q 'multiple: |List(one, two)|' output.txt grep -q 'multiple_pos: |List(a, b, c, d, e, f)|' output.txt grep -q 'resources_dir: |..*|' output.txt +grep -q 'meta_resources_dir: |..*|' output.txt +grep -q 'meta_functionality_name: |testscala|' output.txt [[ ! -f log.txt ]] && echo "Log file could not be found!" && exit 1 grep -q 'Parsed input arguments.' log.txt @@ -43,5 +45,7 @@ grep -q 'optional_with_default: |Some(The default value.)|' output2.txt grep -q 'multiple: |List()|' output2.txt grep -q 'multiple_pos: |List()|' output2.txt grep -q 'resources_dir: |..*|' output2.txt +grep -q 'meta_resources_dir: |..*|' output2.txt +grep -q 'meta_functionality_name: |testscala|' output2.txt echo ">>> Test finished successfully"