diff --git a/sbt/src/sbt-test/reporter/source-mapper/build.sbt b/sbt/src/sbt-test/reporter/source-mapper/build.sbt new file mode 100644 index 000000000..3ca4753ed --- /dev/null +++ b/sbt/src/sbt-test/reporter/source-mapper/build.sbt @@ -0,0 +1,46 @@ +import java.util.Optional +import xsbti.Position + +val assertAbsolutePathConversion = taskKey[Unit]("checks source mappers convert to absolute path") + +val assertHandleFakePos = taskKey[Unit]("checks source mappers handle fake position") + +assertAbsolutePathConversion := { + val converter = fileConverter.value + val source = (Compile/sources).value.head + val position = newPosition(converter.toVirtualFile(source.toPath).id, source) + val mappedPos = sourcePositionMappers.value + .foldLeft(Option(position)) { + case (pos, mapper) => pos.flatMap(mapper) + } + assert { + mappedPos.get.sourcePath.asScala.contains(source.getAbsolutePath) + } +} + +assertHandleFakePos := { + val position = newPosition("", new File("")) + val mappedPos = sourcePositionMappers.value + .foldLeft(Option(position)) { + case (pos, mapper) => pos.flatMap(mapper) + } + assert { + mappedPos.get.sourcePath.asScala.get.contains("") + } +} + +def newPosition(path: String, file: File): Position = new Position { + override def line(): Optional[Integer] = Optional.empty() + + override def lineContent() = "" + + override def offset(): Optional[Integer] = Optional.empty() + + override def pointer(): Optional[Integer] = Optional.empty() + + override def pointerSpace(): Optional[String] = Optional.empty() + + override def sourcePath(): Optional[String] = Optional.of(path) + + override def sourceFile(): Optional[File] = Optional.of(file) +} \ No newline at end of file diff --git a/sbt/src/sbt-test/reporter/source-mapper/src/main/scala/Foo.scala b/sbt/src/sbt-test/reporter/source-mapper/src/main/scala/Foo.scala new file mode 100644 index 000000000..e69de29bb diff --git a/sbt/src/sbt-test/reporter/source-mapper/test b/sbt/src/sbt-test/reporter/source-mapper/test new file mode 100644 index 000000000..ced01bedc --- /dev/null +++ b/sbt/src/sbt-test/reporter/source-mapper/test @@ -0,0 +1,2 @@ +> assertAbsolutePathConversion +> assertHandleFakePos \ No newline at end of file