diff --git a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java index a8f37c2fd691..01a9badcfca1 100644 --- a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java +++ b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java @@ -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) ); } } diff --git a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/AssertFindUsagesCommand.kt b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/AssertFindUsagesCommand.kt new file mode 100644 index 000000000000..ca82d1fda3da --- /dev/null +++ b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/AssertFindUsagesCommand.kt @@ -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}") + } + } +} \ No newline at end of file