Skip to content

Commit ae8ea8e

Browse files
authored
include fast, verbose, keyPattern, showDatafile and onlyFailures options in command (#7)
1 parent 9923c49 commit ae8ea8e

File tree

4 files changed

+50
-52
lines changed

4 files changed

+50
-52
lines changed

.github/workflows/checks.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ jobs:
2121
path: ~/.gradle/caches
2222
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
2323
restore-keys: |
24-
${{ runner.os }}-gradle-
24+
${{ runner.os }}-gradle-
2525
2626
- name: Build with Gradle
27+
env:
28+
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2730
run: ./gradlew build
2831

2932
- name: Test with Gradle

build.gradle.kts

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ plugins {
77

88
repositories {
99
mavenCentral()
10-
maven { url = uri("https://jitpack.io") }
10+
maven {
11+
url = uri("https://maven.pkg.github.com/featurevisor/featurevisor-kotlin")
12+
credentials {
13+
username = System.getenv("GITHUB_ACTOR")
14+
password = System.getenv("GITHUB_TOKEN")
15+
}
16+
}
1117
}
1218

1319
publishing {
@@ -34,13 +40,14 @@ gradlePlugin {
3440

3541
dependencies {
3642
testImplementation("org.jetbrains.kotlin:kotlin-test")
37-
implementation("com.github.featurevisor:featurevisor-kotlin:0.0.7")
43+
implementation("com.featurevisor:featurevisor-kotlin:0.0.8")
3844
implementation(gradleApi())
3945
}
4046

4147
tasks.test {
4248
useJUnitPlatform()
4349
}
50+
4451
kotlin {
4552
jvmToolchain(17)
4653
}

src/main/kotlin/com/featurevisor/plugin/TestRunnerPlugin.kt

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ import org.gradle.api.Project
66

77
class TestRunnerPlugin : Plugin<Project> {
88
override fun apply(project: Project) {
9-
10-
project.tasks.register(RunAllTestsTask.NAME,RunAllTestsTask::class.java){ task ->
11-
task.rootProjectPath = project.findProperty("rootProjectPath") as? String
12-
task.testDirPath = project.findProperty("testDirPath") as? String
13-
task.featureName = project.findProperty("featureName") as? String
14-
task.segmentName = project.findProperty("segmentName") as? String
15-
}
16-
9+
project.tasks.register(RunAllTestsTask.NAME,RunAllTestsTask::class.java)
1710
}
1811
}

src/main/kotlin/com/featurevisor/tasks/RunAllTestsTask.kt

+36-41
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,62 @@ package com.featurevisor.tasks
22

33
import org.gradle.api.DefaultTask
44
import org.gradle.api.tasks.Input
5-
import org.gradle.api.tasks.Optional
65
import org.gradle.api.tasks.TaskAction
76
import com.featurevisor.testRunner.*
7+
import org.gradle.api.tasks.options.Option
88

99
open class RunAllTestsTask : DefaultTask() {
1010

1111
companion object {
12-
const val NAME = "run-test"
12+
const val NAME = "test"
1313
}
1414

1515
@Input
16-
@Optional
17-
var rootProjectPath: String? = null
16+
@Option(option = "rootProjectPath", description = "Whether to run test for specific project")
17+
var rootProjectPath: String = project.projectDir.absolutePath
1818

1919
@Input
20-
@Optional
21-
var testDirPath: String? = null
20+
@Option(option = "testDirPath", description = "Whether to run test for specific test directory")
21+
var testDirPath: String = "tests"
2222

2323
@Input
24-
@Optional
25-
var featureName: String? = null
24+
@Option(option = "keyPattern", description = "Run test for specific key pattern")
25+
var keyPattern: String = ""
2626

2727
@Input
28-
@Optional
29-
var segmentName: String? = null
28+
@Option(option = "assertionPattern", description = "Run test for specific assertion pattern")
29+
var assertionPattern: String = ""
3030

31-
@TaskAction
32-
fun executeTask() {
33-
34-
when {
35-
(rootProjectPath.isNullOrEmpty().not() && testDirPath.isNullOrEmpty().not()) -> {
36-
startTest(rootProjectPath.orEmpty(), testDirPath.orEmpty())
37-
}
38-
39-
(rootProjectPath.isNullOrEmpty().not() && featureName.isNullOrEmpty().not()) -> {
40-
testSingleFeature(featureKey = featureName.orEmpty(), projectRootPath = rootProjectPath.orEmpty())
41-
}
42-
43-
(rootProjectPath.isNullOrEmpty().not() && segmentName.isNullOrEmpty().not()) -> {
44-
testSingleSegment(segmentKey = segmentName.orEmpty(), projectRootPath = rootProjectPath.orEmpty())
45-
}
31+
@Input
32+
@Option(option = "verbose", description = "Whether to run tests in verbose mode")
33+
var verbose: Boolean = false
4634

47-
rootProjectPath.isNullOrEmpty().not() -> {
48-
startTest(projectRootPath = rootProjectPath.orEmpty())
49-
}
35+
@Input
36+
@Option(option = "showDatafile", description = "Whether to run tests by showing datafile")
37+
var showDatafile: Boolean = false
5038

51-
testDirPath.isNullOrEmpty().not() -> {
52-
startTest(testDirPath = testDirPath.orEmpty(), projectRootPath = project.projectDir.absolutePath)
53-
}
39+
@Input
40+
@Option(option = "onlyFailures", description = "Whether to run tests by showing only failed tests")
41+
var onlyFailures: Boolean = false
5442

55-
featureName.isNullOrEmpty().not() -> {
56-
testSingleFeature(featureKey = featureName.orEmpty(), projectRootPath = project.projectDir.absolutePath)
57-
}
43+
@Input
44+
@Option(option = "fast", description = "Whether to run tests in fast mode")
45+
var fast: Boolean = false
5846

59-
segmentName.isNullOrEmpty().not() -> {
60-
testSingleSegment(segmentKey = segmentName.orEmpty(), projectRootPath = project.projectDir.absolutePath)
61-
}
47+
@TaskAction
48+
fun executeTask() {
6249

63-
else -> {
64-
startTest(projectRootPath = project.projectDir.absolutePath)
65-
}
66-
}
50+
val testProjectOption = TestProjectOption(
51+
keyPattern = keyPattern,
52+
assertionPattern = assertionPattern,
53+
verbose = verbose,
54+
showDatafile = showDatafile,
55+
onlyFailures = onlyFailures,
56+
fast = fast,
57+
projectRootPath = rootProjectPath,
58+
testDirPath = testDirPath
59+
)
60+
61+
startTest(testProjectOption)
6762
}
6863
}

0 commit comments

Comments
 (0)