-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WI-79725 Fix error stripe highlighting for arbitrary highlighting pat…
…terns GitOrigin-RevId: b1ac8cdb2f2232edae96f63f831d1d5b1b1160ba
- Loading branch information
1 parent
93f7f6b
commit 8d06963
Showing
9 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/test/kotlin/com/intellij/ideolog/highlighting/ErrorStripeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.intellij.ideolog.highlighting | ||
|
||
import com.intellij.ideolog.file.LogFileEditor | ||
import com.intellij.ideolog.file.LogFileEditorProvider | ||
import com.intellij.ideolog.highlighting.settings.DefaultSettingsStoreItems | ||
import com.intellij.ideolog.highlighting.settings.LogHighlightingPattern | ||
import com.intellij.ideolog.highlighting.settings.LogHighlightingSettingsStore | ||
import com.intellij.ideolog.util.ideologContext | ||
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl | ||
import com.intellij.openapi.editor.markup.MarkupModel | ||
import com.intellij.openapi.editor.markup.RangeHighlighter | ||
import com.intellij.openapi.util.Disposer | ||
import com.intellij.testFramework.PlatformTestUtil | ||
import com.intellij.testFramework.TestDataPath | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
import com.intellij.util.ui.UIUtil | ||
import java.awt.Color | ||
import kotlin.math.abs | ||
|
||
@TestDataPath("\$CONTENT_ROOT/src/test/resources/highlighting/errorStripe") | ||
class ErrorStripeTest : BasePlatformTestCase() { | ||
private lateinit var editor: LogFileEditor | ||
private lateinit var highlightingPatternsBackup: List<LogHighlightingPattern> | ||
|
||
override fun setUp() { | ||
super.setUp() | ||
highlightingPatternsBackup = LogHighlightingSettingsStore.getInstance().myState.patterns.map { it.copy() } | ||
} | ||
|
||
override fun tearDown() { | ||
try { | ||
LogHighlightingSettingsStore.getInstance().myState.patterns.clear() | ||
LogHighlightingSettingsStore.getInstance().myState.patterns.addAll(highlightingPatternsBackup) | ||
if (::editor.isInitialized) { | ||
Disposer.dispose(editor) | ||
} | ||
} | ||
catch (e: Throwable) { | ||
addSuppressedException(e) | ||
} | ||
finally { | ||
super.tearDown() | ||
} | ||
} | ||
|
||
override fun getTestDataPath(): String = "src/test/resources/highlighting/errorStripe" | ||
|
||
fun testUndetectedFormat() { | ||
val markupModel = createMarkupModel() | ||
val format = markupModel.document.ideologContext.detectLogFileFormat() | ||
assertNull(format.myRegexLogParser?.uuid) | ||
|
||
val highlighters = markupModel.allHighlighters.map { highlighter -> | ||
highlighter.getTextAttributes(editor.editor.colorsScheme)?.errorStripeColor?.toTimeIndependent() | ||
}.toSet() | ||
assertSize(1, highlighters) | ||
} | ||
|
||
fun testFirstNonStripedEventLineNotOnStripe() { | ||
val highlighters = calculateHighlighters() | ||
val endOfFirstLine = editor.editor.document.getLineEndOffset(0) | ||
val visibleHighlighters = highlighters.filter { it.startOffset > endOfFirstLine + 1 }.mapNotNull { highlighter -> | ||
highlighter.getTextAttributes(editor.editor.colorsScheme)?.errorStripeColor?.toTimeIndependent() | ||
}.toSet() | ||
assertSize(1, visibleHighlighters) | ||
} | ||
|
||
fun testFirstStripedEventLineNotOnStripe() { | ||
val highlighters = calculateHighlighters() | ||
val endOfFirstLine = editor.editor.document.getLineEndOffset(0) | ||
val visibleHighlighters = highlighters.filter { it.startOffset > endOfFirstLine + 1 }.mapNotNull { highlighter -> | ||
highlighter.getTextAttributes(editor.editor.colorsScheme)?.errorStripeColor?.toTimeIndependent() | ||
}.toSet() | ||
assertSize(1, visibleHighlighters) | ||
} | ||
|
||
fun testNoStripedEvents() { | ||
val highlighters = calculateUniqueHighlighters() | ||
assertSize(1, highlighters) | ||
} | ||
|
||
fun testDefaultErrorStripedEvents() { | ||
val highlighters = calculateUniqueHighlighters() | ||
assertSize(2, highlighters) | ||
} | ||
|
||
fun testCustomStripedEvents() { | ||
assertTrue(LogHighlightingSettingsStore.getInstance().myState.patterns.removeIf { | ||
it.uuid.toString() == "11ff1574-2118-4722-905a-61bec89b079e" | ||
}) | ||
LogHighlightingSettingsStore.getInstance().myState.patterns.add(DefaultSettingsStoreItems.Warning.copy(showOnStripe = true)) | ||
val highlighters = calculateUniqueHighlighters() | ||
assertSize(2, highlighters) | ||
} | ||
|
||
private fun calculateHighlighters(): Array<out RangeHighlighter> { | ||
val markupModel = createMarkupModel() | ||
return markupModel.allHighlighters | ||
} | ||
|
||
private fun calculateUniqueHighlighters(): Set<Color?> { | ||
val markupModel = createMarkupModel() | ||
return markupModel.allHighlighters.mapNotNull { highlighter -> | ||
highlighter.getTextAttributes(editor.editor.colorsScheme)?.errorStripeColor?.toTimeIndependent() | ||
}.toSet() | ||
} | ||
|
||
private fun createMarkupModel(): MarkupModel { | ||
val file = myFixture.copyFileToProject(getTestName(false) + ".log") | ||
editor = LogFileEditorProvider().createEditor(project, file) as LogFileEditor | ||
val mapRenderer = LogFileMapRenderer.getLogFileMapRenderer(editor.editor) | ||
Thread.sleep(1000) | ||
NonBlockingReadActionImpl.waitForAsyncTaskCompletion() | ||
UIUtil.dispatchAllInvocationEvents() | ||
PlatformTestUtil.dispatchAllEventsInIdeEventQueue() | ||
assertNotNull(mapRenderer) | ||
val markupModel = editor.editor.markupModel | ||
assertEquals(1024, markupModel.allHighlighters.size) | ||
return markupModel | ||
} | ||
|
||
private fun Color.toTimeIndependent(): Color = Color(abs(this.red - this.blue), 0, 0) | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/resources/highlighting/errorStripe/CustomStripedEvents.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[2022-07-11 10:00:47] production.WARNING: No application encryption key has been specified. | ||
[2022-07-11 10:00:47] custom.INFO: Successfully imported customer 123456 | ||
[2022-07-11 10:00:47] production.WARNING: No application encryption key has been specified. |
3 changes: 3 additions & 0 deletions
3
src/test/resources/highlighting/errorStripe/DefaultErrorStripedEvents.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[2022-07-11 10:00:47] production.ERROR: No application encryption key has been specified. | ||
[2022-07-11 10:00:47] custom.INFO: Successfully imported customer 123456 | ||
[2022-07-11 10:00:47] production.ERROR: No application encryption key has been specified. |
2 changes: 2 additions & 0 deletions
2
src/test/resources/highlighting/errorStripe/FirstNonStripedEventLineNotOnStripe.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[2022-07-11 10:00:47] custom.INFO: Successfully imported customer 123456 | ||
[2022-07-11 10:00:47] production.ERROR: No application encryption key has been specified. |
2 changes: 2 additions & 0 deletions
2
src/test/resources/highlighting/errorStripe/FirstStripedEventLineNotOnStripe.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[2022-07-11 10:00:47] production.ERROR: No application encryption key has been specified. | ||
[2022-07-11 10:00:47] custom.INFO: Successfully imported customer 123456 |
6 changes: 6 additions & 0 deletions
6
src/test/resources/highlighting/errorStripe/NoStripedEvents.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[2022-07-11 10:00:47] production.WARNING: Vite manifest not found | ||
[2018-08-02 03:02:42] custom.INFO: Successfully imported customer 123456 | ||
[2022-07-11 10:00:47] production.WARNING: Vite manifest not found | ||
[2018-08-02 03:02:42] custom.INFO: Successfully imported customer 123456 | ||
[2018-08-02 03:02:42] custom.INFO: Successfully imported customer 123456 | ||
[2022-07-11 10:00:47] production.WARNING: Vite manifest not found |
12 changes: 12 additions & 0 deletions
12
src/test/resources/highlighting/errorStripe/UndetectedFormat.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[??] production.WARNING: Vite manifest not found | ||
[??] custom.INFO: Successfully imported customer 123456 | ||
[??] production.WARNING: Vite manifest not found | ||
[??] production.ERROR: No application encryption key has been specified. | ||
#0 something | ||
at somewhere | ||
[??] custom.INFO: Successfully imported customer 123456 | ||
[??] custom.INFO: Successfully imported customer 123456 | ||
[??] production.WARNING: Vite manifest not found | ||
[??] production.ERROR: No application encryption key has been specified. | ||
#0 something | ||
at somewhere |