Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Commit 9019ce4

Browse files
dsvoroninyunikkk
authored andcommitted
add --fail-if-no-tests optional arg (#139)
Add --fail-if-no-tests optional arg.
1 parent 1d76355 commit 9019ce4

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ Composer shipped as jar, to run it you need JVM 1.8+: `java -jar composer-latest
114114
* Default: `120` seconds (2 minutes).
115115
* Applicable to both test APK and APK under test.
116116
* Example: `--install-timeout 20`
117-
117+
* `--fail-if-no-tests`
118+
* Either `true` or `false` to enable/disable error on empty test suite.
119+
* Default: `true`.
120+
* `False` may be applicable when you run tests conditionally(via annotation/package filters) and empty suite is a valid outcome.
121+
* Example: `--fail-if-no-tests false`
122+
118123
##### Example
119124

120125
Simplest :

composer/src/main/kotlin/com/gojuno/composer/Args.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ data class Args(
9797
description = "APK installation timeout in seconds. If not passed defaults to 120 seconds (2 minutes). Applicable to both test APK and APK under test.",
9898
order = 10
9999
)
100-
var installTimeoutSeconds: Int = TimeUnit.MINUTES.toSeconds(2).toInt()
100+
var installTimeoutSeconds: Int = TimeUnit.MINUTES.toSeconds(2).toInt(),
101+
102+
@Parameter(
103+
names = arrayOf("--fail-if-no-tests"),
104+
required = false,
105+
arity = 1,
106+
description = "Either `true` or `false` to enable/disable error on empty test suite. True by default.",
107+
order = 11
108+
)
109+
var failIfNoTests: Boolean = true
101110
)
102111

103112
// No way to share array both for runtime and annotation without reflection.

composer/src/main/kotlin/com/gojuno/composer/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fun main(rawArgs: Array<String>) {
7474

7575
when {
7676
totalPassed > 0 && totalFailed == 0 -> exit(Exit.Ok)
77-
totalPassed == 0 && totalFailed == 0 -> exit(Exit.NoTests)
77+
totalPassed == 0 && totalFailed == 0 -> if(args.failIfNoTests) exit(Exit.NoTests) else exit(Exit.Ok)
7878
else -> exit(Exit.ThereWereFailedTests)
7979
}
8080

composer/src/test/kotlin/com/gojuno/composer/ArgsSpec.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class ArgsSpec : Spek({
2929
keepOutputOnExit = false,
3030
devices = emptyList(),
3131
devicePattern = "",
32-
installTimeoutSeconds = 120
32+
installTimeoutSeconds = 120,
33+
failIfNoTests = true
3334
))
3435
}
3536
}
@@ -164,4 +165,32 @@ class ArgsSpec : Spek({
164165
assertThat(args.installTimeoutSeconds).isEqualTo(600)
165166
}
166167
}
168+
169+
context("parse args with passed --fail-if-no-tests") {
170+
171+
val args by memoized {
172+
parseArgs(rawArgsWithOnlyRequiredFields + arrayOf("--fail-if-no-tests", "false"))
173+
}
174+
175+
it("parses --fail-if-no-tests correctly") {
176+
assertThat(args.failIfNoTests).isEqualTo(false)
177+
}
178+
}
179+
180+
context("parse args with explicitly passed --fail-if-no-tests") {
181+
182+
listOf(true, false).forEach { failIfNoTests ->
183+
184+
context("--fail-if-no-tests $failIfNoTests") {
185+
186+
val args by memoized {
187+
parseArgs(rawArgsWithOnlyRequiredFields + arrayOf("--fail-if-no-tests", "$failIfNoTests"))
188+
}
189+
190+
it("parses --fail-if-no-tests correctly") {
191+
assertThat(args.failIfNoTests).isEqualTo(failIfNoTests)
192+
}
193+
}
194+
}
195+
}
167196
})

0 commit comments

Comments
 (0)