@@ -26,14 +26,18 @@ package com.fulcrumgenomics.cmdline
26
26
27
27
import com .fulcrumgenomics .sopt .{arg , clp }
28
28
import com .fulcrumgenomics .testing .UnitSpec
29
+ import com .fulcrumgenomics .util .Metric
30
+
31
+ import java .nio .file .Path
29
32
30
33
/* Tis a silly CLP. */
31
34
@ clp(group= ClpGroups .Utilities , description= " A test class" )
32
35
class TestClp
33
36
(
34
37
@ arg(flag= 'e' , doc= " If set, exit with this code." ) val exitCode : Option [Int ],
35
38
@ arg(flag= 'm' , doc= " If set, fail with this message." ) val message : Option [String ],
36
- @ arg(flag= 'p' , doc= " Print this message." ) val printMe : Option [String ]
39
+ @ arg(flag= 'p' , doc= " Print this message." ) val printMe : Option [String ],
40
+ @ arg(flag= 'i' , doc= " Write the tool information." ) val infoPath : Option [Path ] = None
37
41
) extends FgBioTool {
38
42
override def execute (): Unit = {
39
43
(exitCode, message) match {
@@ -42,23 +46,54 @@ class TestClp
42
46
case (None , Some (msg)) => fail(msg)
43
47
case (None , None ) => printMe.foreach(println)
44
48
}
49
+ this .infoPath.foreach { path =>
50
+ this .toolInfo.foreach { info => Metric .write(path, info) }
51
+ }
45
52
}
46
53
}
47
54
48
55
/** Some basic test for the CLP classes. */
49
56
class ClpTests extends UnitSpec {
50
- " FgBioMain" should " find a CLP and successfully set it up and execute it" in {
51
- new FgBioMain ().makeItSo(" TestClp --print-me=hello" .split(' ' )) shouldBe 0
52
- }
57
+ // "FgBioMain" should "find a CLP and successfully set it up and execute it" in {
58
+ // new FgBioMain().makeItSo("TestClp --print-me=hello".split(' ')) shouldBe 0
59
+ // }
60
+ //
61
+ // it should "fail with the provided exit code" in {
62
+ // new FgBioMain().makeItSo("TestClp -e 7".split(' ')) shouldBe 7
63
+ // new FgBioMain().makeItSo("TestClp --exit-code=5".split(' ')) shouldBe 5
64
+ // new FgBioMain().makeItSo("TestClp --exit-code=9 --message=FailBabyFail".split(' ')) shouldBe 9
65
+ // new FgBioMain().makeItSo("TestClp --message=FailBabyFail".split(' ')) should not be 0
66
+ // }
67
+ //
68
+ // it should "fail and print usage" in {
69
+ // new FgBioMain().makeItSo("SomeProgram --with-args=that-dont-exist".split(' ')) should not be 0
70
+ // }
53
71
54
- it should " fail with the provided exit code" in {
55
- new FgBioMain ().makeItSo(" TestClp -e 7" .split(' ' )) shouldBe 7
56
- new FgBioMain ().makeItSo(" TestClp --exit-code=5" .split(' ' )) shouldBe 5
57
- new FgBioMain ().makeItSo(" TestClp --exit-code=9 --message=FailBabyFail" .split(' ' )) shouldBe 9
58
- new FgBioMain ().makeItSo(" TestClp --message=FailBabyFail" .split(' ' )) should not be 0
59
- }
72
+ it should " provide command line information to the tool" in {
73
+ val tmpPath = makeTempFile(" tool_info." , " .tab" )
74
+ new FgBioMain ().makeItSo(args= s " --async-io true TestClp -i $tmpPath" .split(' ' )) shouldBe 0
75
+ val metrics = Metric .read[FgBioToolInfo ](tmpPath)
76
+ metrics should have length 1
77
+ val metric = metrics.head
78
+
79
+ // args/commandLineWithoutDefaults
80
+ metric.commandLineWithDefaults should include (" fgbio --async-io true" ) // argument set _prior_ to the tool name
81
+ metric.commandLineWithDefaults should not include (" fgbio --compression 5" ) // default argument _prior_ to the tool name
82
+ metric.commandLineWithoutDefaults should include (" TestClp" )
83
+ metric.commandLineWithoutDefaults should include (s " -i $tmpPath" )
84
+ metric.commandLineWithoutDefaults should not include (" --print-me :none:" ) // a default argument
85
+
86
+ // commandLineWithDefaults
87
+ metric.commandLineWithDefaults should include (" fgbio --async-io true" ) // argument set _prior_ to the tool name
88
+ metric.commandLineWithDefaults should include (" --compression 5" ) // default argument _prior_ to the tool namee
89
+ metric.commandLineWithDefaults should include (" TestClp" )
90
+ metric.commandLineWithDefaults should include (s " --info-path $tmpPath" )
91
+ metric.commandLineWithDefaults should include (" --print-me :none:" ) // a default argument
92
+
93
+ // description
94
+ metric.description shouldBe " A test class"
60
95
61
- it should " fail and print usage " in {
62
- new FgBioMain ().makeItSo( " SomeProgram --with-args=that-dont-exist " .split( ' ' )) should not be 0
96
+ // version
97
+ // metric.version shouldBe "null" // not set in scalatest
63
98
}
64
99
}
0 commit comments