Closed olgabot closed 5 years ago
We usually test modules directly within Reflow as you suggest. Reflow comes with a test package:
$ reflow doc $/test
Declarations
val Assert func(tests [bool]) unit
Assert fails if any passed (boolean) value is false.
val All func(tests [bool]) bool
All returns true if every passed (boolean) value is true.
This allows you to write tests (that return boolean values indicating success), and then piece them together, e.g.,:
...
// Verify that filter conditions are working.
val TestPhixCounts = {
val phixBam = file("./../testdata/sambamba/phix.bam")
val phixBai = file("./../testdata/sambamba/phix.bam.bai")
val phixCounts = sambamba.PhixCounts(phixBam, phixBai)
phixCounts == fileutils.Echo("1\n")
}
val Main = test.Assert([
TestIndex,
TestMerge,
TestMergeAndIndex,
TestSortedMergeAndIndex,
TestMarkdup,
TestFilterDuplicates,
TestSort,
TestNameSort,
TestMpileup,
TestPhixCounts,
TestReadExtraction,
TestExtractDiscordantReads,
TestRemoveDiscordantReads,
])
I am planning on adding a proper test runner, so that you can do reflow test foo.rf
, and it will check each exported identifier with the prefix Test
...
Thank you! That is very helpful. Can you let me know how to import the fileutils
module?
ah, fileutils is an internal module we have. here it is:
// Module with generic file utilities
val image = "ubuntu:16.04"
val cpu = 1
val mem = GiB
// Gzip gzips a file
//
// @param f File to be gzipped
// @return gzipped Gzipped version of the input file f
func Gzip(f file) =
exec(image, cpu, mem) (gzipped file) {"
gzip -c {{f}} > {{gzipped}}
"}
// Gunzip gzips a file
//
// @param gz File to be unzipped
// @return f Unzipped file
func Gunzip(gz file) =
exec(image, cpu, mem) (f file) {"
gunzip -c {{gz}} > {{f}}
"}
// Echo creates a file with a given string
//
// @param towrite String to write to file
// @return output Newly created file
func Echo(towrite string) =
exec(image, cpu, mem) (output file) {"
printf "{{towrite}}" > {{output}}
"}
// EmptyFile is a file of size 0.
val EmptyFile = file("/dev/null")
// Concat concatenates text files together using cat.
func Concat(files [file]) =
if (len(files) == 1) {
val [returnFile] = files
returnFile
} else {
exec(image, cpu, mem) (output file) {"
cat {{files}} > {{output}}
"}
}
// Header extracts the first line of the file into a new file
func Header(f file) =
exec(image := image, cpu, mem) (result file) {"
head -n1 {{f}} > {{result}}
"}
// HeaderLess extracts all but the first line of the file into a new file
func HeaderLess(f file) =
exec(image := image, cpu, mem) (result file) {"
tail -n+2 {{f}} > {{result}}
"}
Got it, thank you!
Coming soon: reflow test
Hello, I have a file called
star_htseq.rf
that has aMain
function that I can run from the command line. What is the proper way to test this workflow? Previously I had been writing a bunch of makefiles but it seems like there should be a way to do this within Reflow itself. Thank you! Warmest, OlgaThe
star_htseq.rf
file in question: