diff --git a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt index ee4175742371..d2a749c1d4da 100644 --- a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt +++ b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt @@ -1033,4 +1033,11 @@ fun T.disableKotlinNotification(): T = apply { */ fun T.assertCaretPosition(line: Int, column: Int): T = apply { addCommand("${CMD_PREFIX}assertCaretPosition $line $column") +} + +/** + * Assert the current file in editor. + */ +fun T.assertCurrentFile(name: String): T = apply { + addCommand("${CMD_PREFIX}assertCurrentFile $name") } \ No newline at end of file diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java index 09f7c5773780..988efad31cca 100644 --- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java @@ -112,7 +112,8 @@ public final class BaseCommandProvider implements CommandProvider { Map.entry(AddContentRootToModule.PREFIX, AddContentRootToModule::new), Map.entry(DisableKotlinNotificationCommand.PREFIX, DisableKotlinNotificationCommand::new), Map.entry(RequestHeavyScanningOnNextStartCommand.PREFIX, RequestHeavyScanningOnNextStartCommand::new), - Map.entry(AssertCaretPositionCommand.PREFIX, AssertCaretPositionCommand::new) + Map.entry(AssertCaretPositionCommand.PREFIX, AssertCaretPositionCommand::new), + Map.entry(AssertCurrentFileCommand.PREFIX, AssertCurrentFileCommand::new) ); } } diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/AssertCurrentFileCommand.kt b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/AssertCurrentFileCommand.kt new file mode 100644 index 000000000000..9d6f6ee97d19 --- /dev/null +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/AssertCurrentFileCommand.kt @@ -0,0 +1,37 @@ +package com.jetbrains.performancePlugin.commands + +import com.intellij.openapi.application.readAction +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.ui.playback.PlaybackContext +import org.jetbrains.annotations.NonNls + +/** + * Assert the current file in editor. + * + * Syntax: `%assertCurrentFile ` + * + * Example: `%assertCurrentFile AssertCurrentFileCommand.kt` + */ +class AssertCurrentFileCommand(text: String, line: Int) : PerformanceCommandCoroutineAdapter(text, line) { + companion object { + const val NAME: @NonNls String = "assertCurrentFile" + const val PREFIX: String = CMD_PREFIX + NAME + } + + override suspend fun doExecute(context: PlaybackContext) { + val fileName = extractCommandArgument(PREFIX).split(" ").filterNot { it.trim() == "" }.singleOrNull() + if (fileName == null) { + throw IllegalArgumentException("File name is not provided") + } + + readAction { + val editor = checkNotNull(FileEditorManager.getInstance(context.project).selectedTextEditor) + val currentFileName = editor.virtualFile.name + if (fileName != currentFileName) { + throw Exception("Current file name is $currentFileName, expected $fileName") + } + } + } + + override fun getName(): String = NAME +} \ No newline at end of file