Skip to content

Commit 9c1add6

Browse files
committed
Add #[Bench] attribute support and --type bench for benchmark runs
- Add \Testo\Bench\Bench constant to TestoClasses and BENCH_ATTRIBUTES so #[Bench] attribute gets a gutter run icon via RUNNABLE_ATTRIBUTES - Set selectedType="bench" in TestoRunConfigurationProducer when the element being configured is a bench method (isTestoBench()) - Add --type argument to prepareArguments() based on selectedType, so benchmark runs pass --type bench to the CLI - Tests: update BENCH_ATTRIBUTES count, add --type bench tests, add order verification, add explicit Bench constant check https://claude.ai/code/session_01TmFvjfMtoxTvddQRBzsbPN
1 parent d22509d commit 9c1add6

6 files changed

Lines changed: 65 additions & 10 deletions

File tree

src/main/kotlin/com/github/xepozz/testo/TestoClasses.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ object TestoClasses {
1414
const val DATA_CROSS = "\\Testo\\Data\\DataCross"
1515
const val DATA_ZIP = "\\Testo\\Data\\DataZip"
1616

17+
const val BENCH = "\\Testo\\Bench\\Bench"
1718
const val BENCH_WITH = "\\Testo\\Bench\\BenchWith"
1819

1920
const val ASSERT = "\\Testo\\Assert"
@@ -38,6 +39,7 @@ object TestoClasses {
3839
TEST_INLINE_NEW,
3940
)
4041
val BENCH_ATTRIBUTES = arrayOf(
42+
BENCH,
4143
BENCH_WITH,
4244
)
4345
}

src/main/kotlin/com/github/xepozz/testo/tests/run/TestoRunConfigurationHandler.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class TestoRunConfigurationHandler : PhpTestRunConfigurationHandler {
3232
fun prepareArguments(arguments: MutableList<String?>, testoSettings: TestoRunConfigurationSettings) {
3333
val runner = testoSettings.runnerSettings
3434

35+
if (runner.selectedType.isNotEmpty()) {
36+
arguments.add("--type")
37+
arguments.add(runner.selectedType)
38+
}
3539
if (runner.suite.isNotEmpty()) {
3640
arguments.add("--suite")
3741
arguments.add(runner.suite)

src/main/kotlin/com/github/xepozz/testo/tests/run/TestoRunConfigurationProducer.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.xepozz.testo.tests.run
22

33
import com.github.xepozz.testo.TestoUtil
44
import com.github.xepozz.testo.index.TestoDataProviderUtils
5+
import com.github.xepozz.testo.isTestoBench
56
import com.github.xepozz.testo.isTestoClass
67
import com.github.xepozz.testo.isTestoDataProviderLike
78
import com.github.xepozz.testo.isTestoExecutable
@@ -67,6 +68,10 @@ class TestoRunConfigurationProducer : PhpTestConfigurationProducer<TestoRunConfi
6768
testRunnerSettings.dataProviderIndex = index
6869
testRunnerSettings.dataSetIndex = -1
6970

71+
if (function.isTestoBench()) {
72+
testRunnerSettings.selectedType = BENCH_TYPE
73+
}
74+
7075
return element
7176
}
7277
if (element is PhpYield) {
@@ -113,7 +118,11 @@ class TestoRunConfigurationProducer : PhpTestConfigurationProducer<TestoRunConfi
113118
}
114119
}
115120
}
116-
return super.setupConfiguration(testRunnerSettings, element, virtualFile)
121+
val result = super.setupConfiguration(testRunnerSettings, element, virtualFile)
122+
if (element.isTestoBench()) {
123+
testRunnerSettings.selectedType = BENCH_TYPE
124+
}
125+
return result
117126
}
118127

119128
override fun isConfigurationFromContext(
@@ -514,6 +523,8 @@ class TestoRunConfigurationProducer : PhpTestConfigurationProducer<TestoRunConfi
514523
}
515524

516525
companion object Companion {
526+
const val BENCH_TYPE = "bench"
527+
517528
val METHOD = Condition<PsiElement> {
518529
it.isTestoExecutable() || (it is Method && TestoDataProviderUtils.isDataProvider(it))
519530
}

src/test/kotlin/com/github/xepozz/testo/TestoClassesTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ class TestoClassesTest : TestCase() {
3232

3333
fun testBenchAttributes_containsExpectedValues() {
3434
val attrs = TestoClasses.BENCH_ATTRIBUTES
35-
assertEquals(1, attrs.size)
35+
assertEquals(2, attrs.size)
36+
assertTrue(attrs.contains("\\Testo\\Bench\\Bench"))
3637
assertTrue(attrs.contains("\\Testo\\Bench\\BenchWith"))
3738
}
3839

40+
fun testConstants_bench() {
41+
assertEquals("\\Testo\\Bench\\Bench", TestoClasses.BENCH)
42+
}
43+
3944
fun testConstants_assertionException() {
4045
assertEquals("\\Testo\\Assert\\State\\Assertion\\AssertionException", TestoClasses.ASSERTION_EXCEPTION)
4146
}

src/test/kotlin/com/github/xepozz/testo/TestoLineMarkerCompanionTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class TestoLineMarkerCompanionTest : TestCase() {
2626
}
2727
}
2828

29+
fun testRunnableAttributes_containsBenchAttribute() {
30+
val runnable = TestoTestRunLineMarkerProvider.RUNNABLE_ATTRIBUTES.toSet()
31+
assertTrue("Should contain \\Testo\\Bench\\Bench", runnable.contains(TestoClasses.BENCH))
32+
}
33+
2934
fun testRunnableAttributes_doesNotContainPlainTestAttributes() {
3035
val runnable = TestoTestRunLineMarkerProvider.RUNNABLE_ATTRIBUTES.toSet()
3136
for (attr in TestoClasses.TEST_ATTRIBUTES) {

src/test/kotlin/com/github/xepozz/testo/TestoRunConfigurationHandlerTest.kt

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ class TestoRunConfigurationHandlerTest : TestCase() {
5252
assertTrue("No arguments should be added for default settings", arguments.isEmpty())
5353
}
5454

55+
fun testPrepareArguments_withSelectedType_bench() {
56+
val settings = TestoRunConfigurationSettings()
57+
settings.runnerSettings.selectedType = "bench"
58+
val arguments = mutableListOf<String?>()
59+
60+
TestoRunConfigurationHandler.INSTANCE.prepareArguments(arguments, settings)
61+
62+
assertEquals(2, arguments.size)
63+
assertEquals("--type", arguments[0])
64+
assertEquals("bench", arguments[1])
65+
}
66+
67+
fun testPrepareArguments_withSelectedType_empty_skipped() {
68+
val settings = TestoRunConfigurationSettings()
69+
settings.runnerSettings.selectedType = ""
70+
val arguments = mutableListOf<String?>()
71+
72+
TestoRunConfigurationHandler.INSTANCE.prepareArguments(arguments, settings)
73+
74+
assertTrue("Empty selectedType should not add arguments", arguments.isEmpty())
75+
}
76+
5577
fun testPrepareArguments_withSuite() {
5678
val settings = TestoRunConfigurationSettings()
5779
settings.runnerSettings.suite = "unit"
@@ -125,6 +147,7 @@ class TestoRunConfigurationHandlerTest : TestCase() {
125147

126148
fun testPrepareArguments_allOptions() {
127149
val settings = TestoRunConfigurationSettings()
150+
settings.runnerSettings.selectedType = "bench"
128151
settings.runnerSettings.suite = "integration"
129152
settings.runnerSettings.group = "db"
130153
settings.runnerSettings.excludeGroup = "slow"
@@ -134,7 +157,9 @@ class TestoRunConfigurationHandlerTest : TestCase() {
134157

135158
TestoRunConfigurationHandler.INSTANCE.prepareArguments(arguments, settings)
136159

137-
assertEquals(10, arguments.size)
160+
assertEquals(12, arguments.size)
161+
assertTrue(arguments.contains("--type"))
162+
assertTrue(arguments.contains("bench"))
138163
assertTrue(arguments.contains("--suite"))
139164
assertTrue(arguments.contains("integration"))
140165
assertTrue(arguments.contains("--group"))
@@ -149,19 +174,22 @@ class TestoRunConfigurationHandlerTest : TestCase() {
149174

150175
fun testPrepareArguments_orderIsCorrect() {
151176
val settings = TestoRunConfigurationSettings()
177+
settings.runnerSettings.selectedType = "bench"
152178
settings.runnerSettings.suite = "unit"
153179
settings.runnerSettings.group = "fast"
154180
settings.runnerSettings.parallel = 2
155181
val arguments = mutableListOf<String?>()
156182

157183
TestoRunConfigurationHandler.INSTANCE.prepareArguments(arguments, settings)
158184

159-
// suite comes first, then group, then parallel
160-
assertEquals("--suite", arguments[0])
161-
assertEquals("unit", arguments[1])
162-
assertEquals("--group", arguments[2])
163-
assertEquals("fast", arguments[3])
164-
assertEquals("--parallel", arguments[4])
165-
assertEquals("2", arguments[5])
185+
// type comes first, then suite, then group, then parallel
186+
assertEquals("--type", arguments[0])
187+
assertEquals("bench", arguments[1])
188+
assertEquals("--suite", arguments[2])
189+
assertEquals("unit", arguments[3])
190+
assertEquals("--group", arguments[4])
191+
assertEquals("fast", arguments[5])
192+
assertEquals("--parallel", arguments[6])
193+
assertEquals("2", arguments[7])
166194
}
167195
}

0 commit comments

Comments
 (0)