Skip to content

Commit

Permalink
Include more tests in the root test suite (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bencodes committed Nov 3, 2023
1 parent fac4a15 commit ffff1cf
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 22 deletions.
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ ktlint_config(
test_suite(
name = "all_tests",
tests = [
"//docs:are_docs_up_to_date_test",
"//src/test/kotlin/io/bazel/kotlin:assertion_tests",
"//src/test/kotlin/io/bazel/kotlin/builder:builder_tests",
"//src/test/kotlin/io/bazel/kotlin/integration:integration_tests",
"//src/test/kotlin/io/bazel/worker:worker_tests",
"//src/test/starlark:convert_tests",
],
)
Expand All @@ -48,6 +51,8 @@ test_suite(
tests = [
":all_tests",
"//src/test/kotlin/io/bazel/kotlin:local_assertion_tests",
"//src/test/kotlin/io/bazel/kotlin/integration:local_integration_tests",
"//src/test/kotlin/io/bazel/worker:local_worker_tests",
"//src/test/starlark:convert_tests",
],
)
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/io/bazel/kotlin/builder/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ java_library(
test_suite(
name = "builder_tests",
tests = [
"//src/test/kotlin/io/bazel/kotlin/builder/tasks",
"//src/test/kotlin/io/bazel/kotlin/builder/utils",
"//src/test/kotlin/io/bazel/kotlin/builder/tasks:tasks_tests",
"//src/test/kotlin/io/bazel/kotlin/builder/utils:utils_tests",
],
visibility = ["//visibility:public"],
)
13 changes: 12 additions & 1 deletion src/test/kotlin/io/bazel/kotlin/builder/tasks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,16 @@ kt_rules_test(
)

test_suite(
name = "tasks",
name = "tasks_tests",
tests = [
":JdepsMergerTest",
":JdepsParserTest",
":KotlinBuilderJsTest",
":KotlinBuilderJvmAbiTest",
":KotlinBuilderJvmBasicTest",
":KotlinBuilderJvmCoverageTest",
":KotlinBuilderJvmJdepsTest",
":KotlinBuilderJvmKaptTest",
":KotlinBuilderJvmStrictDepsTest",
],
)
7 changes: 6 additions & 1 deletion src/test/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ kt_jvm_test(
)

test_suite(
name = "utils",
name = "utils_tests",
tests = [
":ArgMapTest",
":JarCreatorTest",
":SourceJarCreatorTest",
],
)
15 changes: 15 additions & 0 deletions src/test/kotlin/io/bazel/kotlin/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ kt_jvm_test(
"@kotlin_rules_maven//:junit_junit",
],
)

test_suite(
name = "integration_tests",
tests = [
":WriteWorkspaceTest",
],
)

test_suite(
name = "local_integration_tests",
tests = [
":MixedSourceCompileTest",
":integration_tests",
],
)
18 changes: 18 additions & 0 deletions src/test/kotlin/io/bazel/worker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,21 @@ kt_jvm_test(
"@kotlin_rules_maven//:com_google_truth_truth",
],
)

test_suite(
name = "worker_tests",
tests = [
":IOTest",
":InvocationWorkerTest",
":JavaPersistentWorkerTest",
":WorkerContextTest",
":WorkerEnvironmentTest",
],
)

test_suite(
name = "local_worker_tests",
tests = [
":worker_tests",
],
)
36 changes: 18 additions & 18 deletions src/test/kotlin/io/bazel/worker/WorkerEnvironmentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,52 @@ import org.junit.Test
class WorkerEnvironmentTest {

@Test
fun send() {
val give = (1..5).map { WorkRequest.newBuilder().setRequestId(it).addArguments("foo").build() }
fun sendOne() {
val give = WorkRequest.newBuilder().setRequestId(1).addArguments("foo").build()
val got = WorkerEnvironment.inProcess {
task { stdIn, stdOut ->
generateSequence {
WorkRequest.parseDelimitedFrom(stdIn)
WorkRequest.parseDelimitedFrom(stdIn).also { println("got $it") }
}.forEach { req ->
WorkerProtocol.WorkResponse.newBuilder().setRequestId(req.requestId).build()
.also { println("sent $it") }
.writeDelimitedTo(stdOut)
}
}

give.forEach { writeStdIn(it) }
writeStdIn(give)
closeStdIn()

return@inProcess generateSequence { readStdOut() }.toSet()
return@inProcess readStdOut()
}

assertThat(got).containsExactlyElementsIn(
(1..5).map { id ->
WorkerProtocol.WorkResponse.newBuilder().setRequestId(id).build()
}
)
assertThat(got)
.isEqualTo(WorkerProtocol.WorkResponse.newBuilder().setRequestId(1).build())
}

@Test
fun sendOne() {
val give = WorkRequest.newBuilder().setRequestId(1).addArguments("foo").build()
fun send() {
val give = (1..5).map { WorkRequest.newBuilder().setRequestId(it).addArguments("foo").build() }
val got = WorkerEnvironment.inProcess {
task { stdIn, stdOut ->
generateSequence {
WorkRequest.parseDelimitedFrom(stdIn).also { println("got $it") }
WorkRequest.parseDelimitedFrom(stdIn)
}.forEach { req ->
WorkerProtocol.WorkResponse.newBuilder().setRequestId(req.requestId).build()
.also { println("sent $it") }
.writeDelimitedTo(stdOut)
}
}

writeStdIn(give)
give.forEach { writeStdIn(it) }
closeStdIn()

return@inProcess readStdOut()
return@inProcess generateSequence { readStdOut() }.toSet()
}

assertThat(got)
.isEqualTo(WorkerProtocol.WorkResponse.newBuilder().setRequestId(1).build())
assertThat(got).containsExactlyElementsIn(
(1..5).map { id ->
WorkerProtocol.WorkResponse.newBuilder().setRequestId(id).build()
}
)
}
}

0 comments on commit ffff1cf

Please sign in to comment.