Skip to content

Commit

Permalink
Run scalafix for test sources
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Dec 5, 2023
1 parent b920657 commit 99e29c3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
7 changes: 4 additions & 3 deletions tests/unit/src/test/scala/tests/telemetry/SampleReports.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tests.telemetry

import java.util.Optional
import java.{util => ju}

import scala.util.Random.nextBoolean

import scala.meta.internal.jdk.CollectionConverters._
import scala.meta.internal.telemetry

import java.util.Optional
import java.{util => ju}

object SampleReports {
private case class OptionalControl(setEmpty: Boolean)
private case class MapControl(setEmpty: Boolean)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package tests.telemetry

import tests.BaseSuite
import scala.meta.internal.telemetry

import tests.BaseSuite

/* Test checking correctness of to/from JSON serialization for telemetry model.
It's purpouse is to check if Optional[T] fields and Java collections are correctly serialized.
Optional fields would be used to evolve the model in backward compatible way, however by default GSON can initialize Optional fields to null if they're missing in the json fields.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package tests.telemetry

import tests.BaseSuite
import scala.meta.internal.metals.SourceCodeSanitizer
import scala.meta.internal.metals.ScalametaSourceCodeTransformer
import scala.meta.internal.metals.SourceCodeSanitizer

import tests.BaseSuite

class SourceCodeSanitizerSuite extends BaseSuite {

val sanitizer = new SourceCodeSanitizer(ScalametaSourceCodeTransformer)

val sampleScalaInput =
val sampleScalaInput: String =
"""
|package some.namespace.of.my.app
|class Foo{
Expand All @@ -23,14 +24,14 @@ class SourceCodeSanitizerSuite extends BaseSuite {
| else -1
|}
""".stripMargin
val sampleScalaOutput =
val sampleScalaOutput: String =
"""package som0.namxxxxx1.of.my.ap4
|class Fo0 { def myFx5: Int = 42 }
|trait Ba1 { def myBxxxxxxx6: String = "--_-----------------" }
|object Fooxx7 extends Fo0 with Ba1 { def comxxx8(inpx9: String, oth10: Ba1): Unit = if (myBxxxxxxx6.contains("-----------------") || this.myBxxxxxxx6 == oth10.myBxxxxxxx6) myFx5 * 42 else -1 }
""".stripMargin

val sampleStackTraceElements =
val sampleStackTraceElements: String =
"""
|scala.meta.internal.pc.completions.OverrideCompletions.scala$meta$internal$pc$completions$OverrideCompletions$$getMembers(OverrideCompletions.scala:180)
| scala.meta.internal.pc.completions.OverrideCompletions$OverrideCompletion.contribute(OverrideCompletions.scala:79)
Expand All @@ -41,7 +42,7 @@ class SourceCodeSanitizerSuite extends BaseSuite {
|
|""".stripMargin

val sampleJavaInput =
val sampleJavaInput: String =
"""
|package scala.meta.internal.telemetry;
|
Expand All @@ -67,7 +68,7 @@ class SourceCodeSanitizerSuite extends BaseSuite {
}
""".stripMargin

val sampleStackTrace =
val sampleStackTrace: String =
"""
|java.lang.RuntimeException
| at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Expand All @@ -85,12 +86,12 @@ class SourceCodeSanitizerSuite extends BaseSuite {
test("erases names from sources in Scala") {
val input = sampleScalaInput
val expected = sampleScalaOutput
assertEquals(expected.trim(), sanitizer(input).trim())
assertNoDiff(sanitizer(input), expected)
}

test("erases sources in non parsable sources") { // TODO: Java parsing
val input = sampleJavaInput
assertEquals("<unparsable>", sanitizer(input).trim())
assertNoDiff(sanitizer(input), "<unparsable>")
}

test("erases names from markdown snippets") {
Expand Down Expand Up @@ -155,7 +156,7 @@ class SourceCodeSanitizerSuite extends BaseSuite {
.map(_.trim())
.filterNot(_.isEmpty())
.mkString(System.lineSeparator())
assertEquals(trimLines(expected), trimLines(sanitizer(input)))
assertNoDiff(trimLines(sanitizer(input)), trimLines(expected))
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package tests.telemetry

import tests.BaseSuite
import tests.telemetry.SampleReports
import scala.meta.internal.telemetry
import scala.meta.internal.metals
import java.io.IOException
import java.net.InetSocketAddress
import java.net.ServerSocket

import scala.collection.mutable
import scala.util.control.NonFatal

import scala.meta.internal.jdk.CollectionConverters._
import scala.meta.internal.jdk.OptionConverters._
import scala.meta.internal.metals
import scala.meta.internal.telemetry

import io.undertow.server.handlers.PathHandler
import java.net.ServerSocket
import java.io.IOException
import scala.util.control.NonFatal
import scala.collection.mutable
import java.net.InetSocketAddress
import io.undertow.server.handlers.BlockingHandler
import io.undertow.server.handlers.PathHandler
import tests.BaseSuite
import tests.telemetry.SampleReports

class TelemetryReporterSuite extends BaseSuite {
def simpleReport(id: String) = metals.Report(
def simpleReport(id: String): metals.Report = metals.Report(
name = "name",
text = "text",
shortSummary = "sumamry",
Expand Down Expand Up @@ -106,7 +108,7 @@ object MockTelemetryServer {
def apply(
host: String,
preferredPort: Int,
)(implicit ctx: Context) = {
)(implicit ctx: Context): Undertow = {
val port = freePort(host, preferredPort)

val baseHandler = path()
Expand Down

0 comments on commit 99e29c3

Please sign in to comment.