[performance-plugin] add assert find usage count command for perf tests

GitOrigin-RevId: 1265fad054429efe2f05fceea8fc982de22161a5
This commit is contained in:
roman.ivanitskii
2023-03-13 20:36:27 +00:00
committed by intellij-monorepo-bot
parent 520629186c
commit f2f6c9d1db
2 changed files with 35 additions and 1 deletions
@@ -75,7 +75,8 @@ public final class BaseCommandProvider implements CommandProvider {
Map.entry(CloseAllTabsCommand.PREFIX, CloseAllTabsCommand::new),
Map.entry(CollectAllFilesCommand.PREFIX, CollectAllFilesCommand::new),
Map.entry(ExecuteEditorActionCommand.PREFIX, ExecuteEditorActionCommand::new),
Map.entry(AssertCompletionCommand.PREFIX, AssertCompletionCommand::new)
Map.entry(AssertCompletionCommand.PREFIX, AssertCompletionCommand::new),
Map.entry(AssertFindUsagesCommand.PREFIX, AssertFindUsagesCommand::new)
);
}
}
@@ -0,0 +1,33 @@
package com.jetbrains.performancePlugin.commands
import com.intellij.openapi.ui.playback.PlaybackContext
import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter
import com.jetbrains.performancePlugin.utils.DataDumper
import org.jetbrains.annotations.NonNls
import java.nio.file.Files
class AssertFindUsagesCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) {
companion object {
const val PREFIX: @NonNls String = CMD_PREFIX + "assertFindUsagesCommand"
}
override suspend fun doExecute(context: PlaybackContext) {
val lastUsageReport = FindUsagesCommand.getFoundUsagesJsonPath()
if (lastUsageReport == null) {
throw IllegalStateException("Find usages report is null")
}
if (!Files.exists(lastUsageReport) || !Files.isRegularFile(lastUsageReport)) {
throw IllegalStateException("Find usages report file not exists $lastUsageReport")
}
val args = extractCommandArgument(PREFIX).split(" ").filterNot { it.trim() == "" }
if (args.isEmpty()) {
throw IllegalStateException("Provide expected count of usages")
}
val data: FindUsagesCommand.FoundUsagesReport = DataDumper.read(lastUsageReport, FindUsagesCommand.FoundUsagesReport::class.java)
val expected = args[0].toInt()
if (data.totalNumberOfUsages != expected) {
throw IllegalStateException("Expected ${expected} find usages, but got ${data.totalNumberOfUsages}")
}
}
}