Skip to content

Commit

Permalink
Use static test tags, consistify should usage
Browse files Browse the repository at this point in the history
Fixes #479.
  • Loading branch information
FWDekker committed Oct 22, 2023
1 parent 75f43a6 commit 941c214
Show file tree
Hide file tree
Showing 44 changed files with 161 additions and 107 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ See [Plugin Signing](https://plugins.jetbrains.com/docs/intellij/plugin-signing.
```bash
$ gradlew test # Run tests (and collect coverage)
$ gradlew test --tests X # Run tests in class X (package name optional)
$ gradlew test -Pkotest.tags="X" # Run tests with `NamedTag` X (also supports not (!), and (&), or (|))
$ gradlew test -Pkotest.tags="X" # Run tests matching tag(s) X (also supports not (!), and (&), or (|))
$ gradlew koverHtmlReport # Create HTML coverage report for previous test run
$ gradlew check # Run tests and static analysis
$ gradlew runPluginVerifier # Check for compatibility issues
```

#### 🏷️ Filtering tests
#### 🏷️ Tagging and filtering tests
[Kotest tests can be tagged](https://kotest.io/docs/framework/tags.html) to allow selectively running tests.
The tags for Randomness are statically defined in
[`Tags`](https://github.com/FWDekker/intellij-randomness/blob/main/src/test/kotlin/com/fwdekker/randomness/testhelpers/Tags.kt).

Tag an entire test class by adding `tags(...)` to the class definition, or tag an individual test `context` by
writing `context("foo").config(tags = setOf(...)) {`.
It is not possible to tag an individual `test` due to limitations in Kotest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ fun <E> Cell<ComboBox<E>>.withSimpleRenderer(toString: (E) -> String = { it.toSt
* A predicate that always returns [output].
*/
class LiteralPredicate(private val output: Boolean) : ComponentPredicate() {
/**
* Does nothing, because there's no need to respond to any events to determine the output of [invoke].
*/
override fun addListener(listener: (Boolean) -> Unit) = Unit

/**
* Returns [output].
*/
override fun invoke() = output
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.fwdekker.randomness

import com.fwdekker.randomness.testhelpers.matchBundle
import io.kotest.assertions.retry
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldBeEqualIgnoringCase
Expand Down Expand Up @@ -72,7 +74,7 @@ object CapitalizationModeTest : FunSpec({

context("toLocalizedString") {
test("returns the associated localized string") {
CapitalizationMode.FIRST_LETTER.toLocalizedString() shouldBe Bundle("shared.capitalization.first_letter")
CapitalizationMode.FIRST_LETTER.toLocalizedString() should matchBundle("shared.capitalization.first_letter")
}
}
})
4 changes: 2 additions & 2 deletions src/test/kotlin/com/fwdekker/randomness/ErrorReporterTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.fwdekker.randomness

import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.afterNonContainer
import com.fwdekker.randomness.testhelpers.beforeNonContainer
import com.intellij.testFramework.fixtures.IdeaTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldNotContain
Expand All @@ -14,7 +14,7 @@ import io.kotest.matchers.string.shouldNotContain
* Unit tests for [ErrorReporter].
*/
object ErrorReporterTest : FunSpec({
tags(NamedTag("IdeaFixture"))
tags(Tags.IDEA_FIXTURE)


lateinit var ideaFixture: IdeaTestFixture
Expand Down
8 changes: 4 additions & 4 deletions src/test/kotlin/com/fwdekker/randomness/IconsTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fwdekker.randomness

import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.beforeNonContainer
import com.fwdekker.randomness.testhelpers.guiGet
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.shouldContainExactly
Expand Down Expand Up @@ -65,7 +65,7 @@ object TypeIconTest : FunSpec({


context("paintIcon") {
tags(NamedTag("Swing"))
tags(Tags.SWING)


lateinit var image: BufferedImage
Expand Down Expand Up @@ -105,7 +105,7 @@ object TypeIconTest : FunSpec({
*/
object OverlayIconTest : FunSpec({
context("paintIcon") {
tags(NamedTag("Swing"))
tags(Tags.SWING)


lateinit var image: BufferedImage
Expand Down Expand Up @@ -207,7 +207,7 @@ object OverlayedIconTest : FunSpec({


context("paintIcon") {
tags(NamedTag("Swing"))
tags(Tags.SWING)


lateinit var image: BufferedImage
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/fwdekker/randomness/SchemeEditorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fwdekker.randomness.testhelpers.DummyDecoratorScheme
import com.fwdekker.randomness.testhelpers.DummyDecoratorSchemeEditor
import com.fwdekker.randomness.testhelpers.DummyScheme
import com.fwdekker.randomness.testhelpers.DummySchemeEditor
import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.afterNonContainer
import com.fwdekker.randomness.testhelpers.beforeNonContainer
import com.fwdekker.randomness.testhelpers.guiGet
Expand All @@ -13,7 +14,6 @@ import com.intellij.testFramework.fixtures.IdeaTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.ui.dsl.builder.bindText
import com.intellij.ui.dsl.builder.panel
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual
Expand All @@ -33,7 +33,7 @@ import javax.swing.JCheckBox
* Unit tests for [SchemeEditor].
*/
object SchemeEditorTest : FunSpec({
tags(NamedTag("IdeaFixture"), NamedTag("Swing"))
tags(Tags.EDITOR, Tags.IDEA_FIXTURE, Tags.SWING)


lateinit var ideaFixture: IdeaTestFixture
Expand Down
9 changes: 6 additions & 3 deletions src/test/kotlin/com/fwdekker/randomness/SchemeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.fwdekker.randomness

import com.fwdekker.randomness.testhelpers.DummyDecoratorScheme
import com.fwdekker.randomness.testhelpers.DummyScheme
import com.fwdekker.randomness.testhelpers.Tags
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.shouldContainExactly
Expand All @@ -18,10 +18,10 @@ import java.awt.Color
* Unit tests for [Scheme].
*/
object SchemeTest : FunSpec({
tags(NamedTag("Scheme"))
tags(Tags.SCHEME)


context("icon") {
context("f:icon") {
test("returns null if the type icon is null") {
val scheme = DummyScheme()

Expand Down Expand Up @@ -146,6 +146,9 @@ object SchemeTest : FunSpec({
* Unit tests for [DecoratorScheme].
*/
object DecoratorSchemeTest : FunSpec({
tags(Tags.SCHEME)


context("generateStrings") {
test("throws an exception if the decorator is invalid") {
val decorator = DummyDecoratorScheme(enabled = true, valid = false)
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/fwdekker/randomness/StateTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fwdekker.randomness

import com.fwdekker.randomness.testhelpers.DummyState
import io.kotest.core.NamedTag
import com.fwdekker.randomness.testhelpers.Tags
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.shouldBe
Expand All @@ -13,7 +13,7 @@ import io.kotest.matchers.types.shouldBeSameInstanceAs
* Unit tests for [State].
*/
object StateTest : FunSpec({
tags(NamedTag("Scheme"))
tags(Tags.SCHEME)


context("uuid") {
Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/com/fwdekker/randomness/TimelyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.fwdekker.randomness

import com.fwdekker.randomness.Timely.GENERATOR_TIMEOUT
import com.fwdekker.randomness.Timely.generateTimely
import com.fwdekker.randomness.testhelpers.matchBundle
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe


Expand All @@ -17,7 +19,7 @@ object TimelyTest : FunSpec({

test("throws an exception if the generator does not finish within time") {
shouldThrow<DataGenerationException> { generateTimely { Thread.sleep(GENERATOR_TIMEOUT + 1000L) } }
.message shouldBe Bundle("helpers.error.timed_out")
.message should matchBundle("helpers.error.timed_out")
}

test("throws an exception if the generator throws an exception") {
Expand Down
20 changes: 11 additions & 9 deletions src/test/kotlin/com/fwdekker/randomness/XmlHelpersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.fwdekker.randomness
import com.intellij.openapi.util.JDOMUtil
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.nulls.beNull
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe


Expand Down Expand Up @@ -55,7 +57,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getContentByName("needle")?.name shouldBe null
element.getContentByName("needle")?.name should beNull()
}

test("returns `null` if multiple children have the given name") {
Expand All @@ -70,7 +72,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getContentByName("needle")?.name shouldBe null
element.getContentByName("needle")?.name should beNull()
}
}

Expand Down Expand Up @@ -100,7 +102,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getAttributeValueByName("needle") shouldBe null
element.getAttributeValueByName("needle") should beNull()
}

test("returns `null` if multiple children have the given name") {
Expand All @@ -115,7 +117,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getAttributeValueByName("needle") shouldBe null
element.getAttributeValueByName("needle") should beNull()
}

test("returns `null` if the child does not have a value attribute") {
Expand All @@ -129,7 +131,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getAttributeValueByName("needle") shouldBe null
element.getAttributeValueByName("needle") should beNull()
}
}

Expand Down Expand Up @@ -161,7 +163,7 @@ object XmlHelpersTest : FunSpec({
</tag>
""".trimIndent()
)
element.getAttributeValueByName("needle") shouldBe null
element.getAttributeValueByName("needle") should beNull()

element.setAttributeValueByName("needle", "new-value")

Expand Down Expand Up @@ -214,7 +216,7 @@ object XmlHelpersTest : FunSpec({
test("returns `null` if there are no children") {
val element = JDOMUtil.load("<tag></tag>")

element.getSingleContent() shouldBe null
element.getSingleContent() should beNull()
}

test("returns `null` if there are multiple children") {
Expand All @@ -227,7 +229,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getSingleContent() shouldBe null
element.getSingleContent() should beNull()
}
}

Expand Down Expand Up @@ -291,7 +293,7 @@ object XmlHelpersTest : FunSpec({
""".trimIndent()
)

element.getContentByPath("wrong", null, "prong", null)?.name shouldBe null
element.getContentByPath("wrong", null, "prong", null)?.name should beNull()
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fwdekker.randomness.affix

import com.fwdekker.randomness.editorApplyTestFactory
import com.fwdekker.randomness.editorFieldsTestFactory
import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.afterNonContainer
import com.fwdekker.randomness.testhelpers.beforeNonContainer
import com.fwdekker.randomness.testhelpers.guiGet
Expand All @@ -13,7 +14,6 @@ import com.intellij.testFramework.fixtures.IdeaTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.ui.layout.selected
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.data.row
import io.kotest.datatest.withData
Expand All @@ -29,7 +29,7 @@ import javax.swing.JCheckBox
* Unit tests for [AffixDecoratorEditor].
*/
object AffixDecoratorEditorTest : FunSpec({
tags(NamedTag("Editor"), NamedTag("IdeaFixture"), NamedTag("Swing"))
tags(Tags.EDITOR, Tags.IDEA_FIXTURE, Tags.SWING)


lateinit var ideaFixture: IdeaTestFixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fwdekker.randomness.affix

import com.fwdekker.randomness.stateDeepCopyTestFactory
import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.shouldValidateAsBundle
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.data.row
import io.kotest.datatest.withData
Expand All @@ -13,7 +13,7 @@ import io.kotest.matchers.shouldBe
* Unit tests for [AffixDecorator].
*/
object AffixDecoratorTest : FunSpec({
tags(NamedTag("Scheme"))
tags(Tags.SCHEME)


context("generateStrings") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fwdekker.randomness.array

import com.fwdekker.randomness.editorApplyTestFactory
import com.fwdekker.randomness.editorFieldsTestFactory
import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.afterNonContainer
import com.fwdekker.randomness.testhelpers.beforeNonContainer
import com.fwdekker.randomness.testhelpers.guiGet
Expand All @@ -14,7 +15,6 @@ import com.fwdekker.randomness.testhelpers.valueProp
import com.intellij.testFramework.fixtures.IdeaTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.ui.TitledSeparator
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.data.row
import io.kotest.matchers.collections.beEmpty
Expand All @@ -29,7 +29,7 @@ import javax.swing.JCheckBox
* Unit tests for [ArrayDecoratorEditor].
*/
object ArrayDecoratorEditorTest : FunSpec({
tags(NamedTag("Editor"), NamedTag("IdeaFixture"), NamedTag("Swing"))
tags(Tags.EDITOR, Tags.IDEA_FIXTURE, Tags.SWING)


lateinit var ideaFixture: IdeaTestFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.fwdekker.randomness.array

import com.fwdekker.randomness.affix.AffixDecorator
import com.fwdekker.randomness.stateDeepCopyTestFactory
import com.fwdekker.randomness.testhelpers.Tags
import com.fwdekker.randomness.testhelpers.shouldValidateAsBundle
import io.kotest.core.NamedTag
import io.kotest.core.spec.style.FunSpec
import io.kotest.data.row
import io.kotest.datatest.withData
Expand All @@ -15,7 +15,7 @@ import io.kotest.matchers.shouldBe
* Unit tests for [ArrayDecorator].
*/
object ArrayDecoratorTest : FunSpec({
tags(NamedTag("Scheme"))
tags(Tags.SCHEME)


context("generateStrings") {
Expand Down
Loading

0 comments on commit 941c214

Please sign in to comment.