-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
escape TC commands in test output, extract base highlighting test
- Loading branch information
Showing
2 changed files
with
134 additions
and
109 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
test/org/jetbrains/plugins/scala/projectHighlighting/AllProjectHighlightingTest.scala
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,127 @@ | ||
package org.jetbrains.plugins.scala.projectHighlighting | ||
|
||
import java.util | ||
|
||
import com.intellij.ide.highlighter.JavaFileType | ||
import com.intellij.lang.annotation.Annotation | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.openapi.vfs.{LocalFileSystem, VirtualFile} | ||
import com.intellij.psi.{PsiElement, PsiManager} | ||
import com.intellij.psi.impl.PsiManagerEx | ||
import com.intellij.psi.search.{FileTypeIndex, GlobalSearchScope} | ||
import org.jetbrains.plugins.scala.ScalaFileType | ||
import org.jetbrains.plugins.scala.annotator.{AnnotatorHolderMock, ScalaAnnotator} | ||
import org.jetbrains.plugins.scala.finder.SourceFilterScope | ||
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement | ||
import org.jetbrains.plugins.scala.lang.psi.api.ScalaRecursiveElementVisitor | ||
import org.junit.Assert | ||
|
||
/** | ||
* @author Mikhail Mutcianko | ||
* @since 30.08.16 | ||
*/ | ||
trait AllProjectHighlightingTest { | ||
|
||
def getProject: Project | ||
|
||
class DefaultReporter { | ||
var totalErrors = 0 | ||
def reportError(file: VirtualFile, range: TextRange, message: String) = { | ||
totalErrors += 1 | ||
println(s"Error: ${file.getName}${range.toString} - $message") | ||
} | ||
def updateProgress(percent: Int) = println(s"Highlighting - $percent%") | ||
def reportResults() = { | ||
Assert.assertTrue(s"Found $totalErrors errors while highlighting the project", totalErrors == 0) | ||
} | ||
} | ||
|
||
class TCReporter extends DefaultReporter { | ||
|
||
def escapeTC(message: String): String = { | ||
message | ||
.replaceAll("##", "") | ||
.replaceAll("([\"\'\n\r\\|\\[\\]])", "\\|$1") | ||
} | ||
|
||
override def updateProgress(percent: Int): Unit = println(s"##teamcity[progressMessage 'Highlighting - $percent%']") | ||
|
||
override def reportError(file: VirtualFile, range: TextRange, message: String): Unit = { | ||
totalErrors += 1 | ||
val escaped = escapeTC(message) | ||
val testName = s"${getClass.getName}.${file.getName}$range" | ||
println(s"##teamcity[testStarted name='$testName']") | ||
println(s"##teamcity[testFailed name='$testName' message='Highlighting error' details='$escaped']") | ||
println(s"##teamcity[testFinished name='$testName']") | ||
} | ||
|
||
override def reportResults(): Unit = { | ||
if (totalErrors > 0) | ||
println(s"##teamcity[buildProblem description='Found $totalErrors errors while highlighting the project' ]") | ||
else | ||
println("##teamcity[buildStatus status='SUCCESS' text='No highlighting errors found in project']") | ||
} | ||
} | ||
|
||
def doAllProjectHighlightingTest(): Unit = { | ||
import scala.collection.JavaConversions._ | ||
|
||
val reporter = if (sys.env.contains("TEAMCITY_VERSION")) | ||
new TCReporter | ||
else | ||
new DefaultReporter | ||
|
||
val searchScope = | ||
new SourceFilterScope(GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(getProject), | ||
ScalaFileType.SCALA_FILE_TYPE, JavaFileType.INSTANCE), getProject) | ||
|
||
val files: util.Collection[VirtualFile] = FileTypeIndex.getFiles(ScalaFileType.SCALA_FILE_TYPE, searchScope) | ||
|
||
LocalFileSystem.getInstance().refreshFiles(files) | ||
|
||
val fileManager = PsiManager.getInstance(getProject).asInstanceOf[PsiManagerEx].getFileManager | ||
val annotator = new ScalaAnnotator | ||
|
||
var percent = 0 | ||
val size: Int = files.size() | ||
|
||
for ((file, index) <- files.zipWithIndex) { | ||
val mock = new AnnotatorHolderMock { | ||
override def createErrorAnnotation(range: TextRange, message: String): Annotation = { | ||
reporter.reportError(file, range, message) | ||
super.createErrorAnnotation(range, message) | ||
} | ||
|
||
override def createErrorAnnotation(elt: PsiElement, message: String): Annotation = { | ||
reporter.reportError(file, elt.getTextRange, message) | ||
super.createErrorAnnotation(elt, message) | ||
} | ||
} | ||
|
||
if ((index + 1) * 100 >= (percent + 1) * size) { | ||
while ((index + 1) * 100 >= (percent + 1) * size) percent += 1 | ||
reporter.updateProgress(percent) | ||
} | ||
|
||
val psi = fileManager.findFile(file) | ||
|
||
val visitor = new ScalaRecursiveElementVisitor { | ||
override def visitElement(element: ScalaPsiElement) { | ||
try { | ||
annotator.annotate(element, mock) | ||
} catch { | ||
case e: Throwable => | ||
println(s"Exception in ${file.getName}, Stacktrace: ") | ||
e.printStackTrace() | ||
assert(false) | ||
} | ||
super.visitElement(element) | ||
} | ||
} | ||
psi.accept(visitor) | ||
} | ||
|
||
reporter.reportResults() | ||
} | ||
} |
116 changes: 7 additions & 109 deletions
116
...g/jetbrains/plugins/scala/projectHighlighting/ScalaCommunityProjectHighlightingTest.scala
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 |
---|---|---|
@@ -1,120 +1,18 @@ | ||
package org.jetbrains.plugins.scala.projectHighlighting | ||
|
||
import java.util | ||
|
||
import com.intellij.ide.highlighter.JavaFileType | ||
import com.intellij.lang.annotation.Annotation | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.openapi.vfs.{LocalFileSystem, VirtualFile} | ||
import com.intellij.psi.{PsiElement, PsiFile, PsiManager} | ||
import com.intellij.psi.impl.PsiManagerEx | ||
import com.intellij.psi.search.{FileTypeIndex, GlobalSearchScope} | ||
import org.jetbrains.plugins.scala.{HighlightingTests, ScalaFileType} | ||
import org.jetbrains.plugins.scala.annotator.{AnnotatorHolderMock, ScalaAnnotator} | ||
import org.jetbrains.plugins.scala.finder.SourceFilterScope | ||
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement | ||
import org.jetbrains.plugins.scala.lang.psi.api.ScalaRecursiveElementVisitor | ||
import org.jetbrains.plugins.scala.HighlightingTests | ||
import org.jetbrains.plugins.scala.performance.{DownloadingAndImportingTestCase, ScalaCommunityDownloadingAndImportingTestCase} | ||
import org.junit.Assert | ||
import org.junit.experimental.categories.Category | ||
|
||
@Category(Array(classOf[HighlightingTests])) | ||
class ScalaCommunityProjectHighlightingTest extends DownloadingAndImportingTestCase with ScalaCommunityDownloadingAndImportingTestCase { | ||
class ScalaCommunityProjectHighlightingTest extends DownloadingAndImportingTestCase | ||
with ScalaCommunityDownloadingAndImportingTestCase | ||
with AllProjectHighlightingTest { | ||
|
||
//revision: a9ac902 TeamCityServer on 27.08.16 at 0:42 [scala-plugin] | ||
override def revision: String = "a9ac902e8930c520b390095d9e9346d9ae546212" | ||
|
||
class DefaultReporter { | ||
var totalErrors = 0 | ||
def reportError(file: VirtualFile, range: TextRange, message: String) = { | ||
totalErrors += 1 | ||
println(s"Error: ${file.getName}${range.toString} - $message") | ||
} | ||
def updateProgess(percent: Int) = println(s"Highlighting - $percent%") | ||
def reportResults() = { | ||
Assert.assertTrue(s"Found $totalErrors errors while highlighting the project", totalErrors == 0) | ||
} | ||
} | ||
|
||
class TCReporter extends DefaultReporter { | ||
override def updateProgess(percent: Int): Unit = println(s"##teamcity[progressMessage 'Highlighting - $percent%']") | ||
|
||
override def reportError(file: VirtualFile, range: TextRange, message: String): Unit = { | ||
super.reportError(file, range, message) | ||
val testName = s"${getClass.getName}.${file.getName}$range" | ||
println( | ||
s""" | ||
|##teamcity[testStarted name='$testName'] | ||
|##teamcity[testFailed name='$testName' message='Highlighting error' details='$message'] | ||
|##teamcity[testFinished name='$testName'] | ||
""".stripMargin) | ||
} | ||
|
||
override def reportResults(): Unit = { | ||
if (totalErrors > 0) | ||
println(s"##teamcity[buildProblem description='Found $totalErrors errors while highlighting the project' ]") | ||
else | ||
println("##teamcity[buildStatus status='SUCCESS' text='No highlighting errors found in project']") | ||
} | ||
} | ||
|
||
def testAllHighlighting(): Unit = { | ||
import scala.collection.JavaConversions._ | ||
|
||
val reporter = if (sys.env.contains("TEAMCITY_VERSION")) | ||
new TCReporter | ||
else | ||
new DefaultReporter | ||
|
||
val searchScope = | ||
new SourceFilterScope(GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(myProject), | ||
ScalaFileType.SCALA_FILE_TYPE, JavaFileType.INSTANCE), myProject) | ||
|
||
val files: util.Collection[VirtualFile] = FileTypeIndex.getFiles(ScalaFileType.SCALA_FILE_TYPE, searchScope) | ||
|
||
LocalFileSystem.getInstance().refreshFiles(files) | ||
|
||
val fileManager = PsiManager.getInstance(myProject).asInstanceOf[PsiManagerEx].getFileManager | ||
val annotator = new ScalaAnnotator | ||
|
||
var percent = 0 | ||
val size: Int = files.size() | ||
|
||
for ((file, index) <- files.zipWithIndex) { | ||
val mock = new AnnotatorHolderMock { | ||
override def createErrorAnnotation(range: TextRange, message: String): Annotation = { | ||
reporter.reportError(file, range, message) | ||
super.createErrorAnnotation(range, message) | ||
} | ||
|
||
override def createErrorAnnotation(elt: PsiElement, message: String): Annotation = { | ||
reporter.reportError(file, elt.getTextRange, message) | ||
super.createErrorAnnotation(elt, message) | ||
} | ||
} | ||
|
||
if ((index + 1) * 100 >= (percent + 1) * size) { | ||
while ((index + 1) * 100 >= (percent + 1) * size) percent += 1 | ||
reporter.updateProgess(percent) | ||
} | ||
|
||
val psi = fileManager.findFile(file) | ||
|
||
val visitor = new ScalaRecursiveElementVisitor { | ||
override def visitElement(element: ScalaPsiElement) { | ||
try { | ||
annotator.annotate(element, mock) | ||
} catch { | ||
case e: Throwable => | ||
println(s"Exception in ${file.getName}, Stacktrace: ") | ||
e.printStackTrace() | ||
assert(false) | ||
} | ||
super.visitElement(element) | ||
} | ||
} | ||
psi.accept(visitor) | ||
} | ||
override def getProject = myProject | ||
|
||
reporter.reportResults() | ||
} | ||
def testScalaCommunityHighlighting(): Unit = doAllProjectHighlightingTest() | ||
} |