mirror of https://github.com/sbt/sbt.git
Moved tests to internal package
This commit is contained in:
parent
9294351e24
commit
2a603da0a8
|
|
@ -10,6 +10,7 @@ import Types.Endo
|
||||||
import compiler.Eval
|
import compiler.Eval
|
||||||
|
|
||||||
import SessionSettings._
|
import SessionSettings._
|
||||||
|
import sbt.internals.parser.SbtRefactorings
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents (potentially) transient settings added into a build via commands/user.
|
* Represents (potentially) transient settings added into a build via commands/user.
|
||||||
|
|
@ -192,7 +193,7 @@ object SessionSettings {
|
||||||
}
|
}
|
||||||
val newSettings = settings diff replace
|
val newSettings = settings diff replace
|
||||||
val oldContent = IO.readLines(writeTo)
|
val oldContent = IO.readLines(writeTo)
|
||||||
val exist: List[String] = SessionSettingsNoBlankies.oldLinesToNew(oldContent, statements)
|
val exist: List[String] = SbtRefactorings.applyStatements(oldContent, statements)
|
||||||
val adjusted = if (!newSettings.isEmpty && needsTrailingBlank(exist)) exist :+ "" else exist
|
val adjusted = if (!newSettings.isEmpty && needsTrailingBlank(exist)) exist :+ "" else exist
|
||||||
val lines = adjusted ++ newSettings.flatMap(_._2 ::: "" :: Nil)
|
val lines = adjusted ++ newSettings.flatMap(_._2 ::: "" :: Nil)
|
||||||
IO.writeLines(writeTo, lines)
|
IO.writeLines(writeTo, lines)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
package sbt
|
package sbt.internals.parser
|
||||||
|
|
||||||
import scala.reflect.runtime.universe._
|
import scala.reflect.runtime.universe._
|
||||||
import sbt.internals.parser.{ XmlContent, SplitExpressionsNoBlankies }
|
|
||||||
|
|
||||||
object SessionSettingsNoBlankies {
|
private[sbt] object SbtRefactorings {
|
||||||
|
|
||||||
import SplitExpressionsNoBlankies.FAKE_FILE
|
|
||||||
|
|
||||||
|
import sbt.internals.parser.SplitExpressionsNoBlankies.{ END_OF_LINE, FAKE_FILE }
|
||||||
|
val EMPTY_STRING = ""
|
||||||
val REVERSE_ORDERING_INT = Ordering[Int].reverse
|
val REVERSE_ORDERING_INT = Ordering[Int].reverse
|
||||||
|
|
||||||
def oldLinesToNew(lines: List[String], setCommands: List[List[String]]): List[String] = {
|
def applyStatements(lines: List[String], setCommands: List[List[String]]): List[String] = {
|
||||||
val split = SplitExpressionsNoBlankies(FAKE_FILE, lines)
|
val split = SplitExpressionsNoBlankies(FAKE_FILE, lines)
|
||||||
val recordedCommand = setCommands.flatMap {
|
val recordedCommand = setCommands.flatMap {
|
||||||
command =>
|
command =>
|
||||||
|
|
@ -21,9 +20,9 @@ object SessionSettingsNoBlankies {
|
||||||
val treeName = extractSettingName(tree)
|
val treeName = extractSettingName(tree)
|
||||||
if (name == treeName) {
|
if (name == treeName) {
|
||||||
val replacement = if (acc.isEmpty) {
|
val replacement = if (acc.isEmpty) {
|
||||||
command.mkString("\n")
|
command.mkString(END_OF_LINE)
|
||||||
} else {
|
} else {
|
||||||
""
|
EMPTY_STRING
|
||||||
}
|
}
|
||||||
(tree.pos.start, statement, replacement) +: acc
|
(tree.pos.start, statement, replacement) +: acc
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -39,7 +38,6 @@ object SessionSettingsNoBlankies {
|
||||||
val before = acc.substring(0, from)
|
val before = acc.substring(0, from)
|
||||||
val after = acc.substring(from + old.length, acc.length)
|
val after = acc.substring(from + old.length, acc.length)
|
||||||
before + replacement + after
|
before + replacement + after
|
||||||
// acc.replace(old, replacement)
|
|
||||||
}
|
}
|
||||||
newContent.lines.toList
|
newContent.lines.toList
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ private[sbt] case class SplitExpressionsNoBlankies(file: File, lines: Seq[String
|
||||||
import scala.reflect.runtime._
|
import scala.reflect.runtime._
|
||||||
|
|
||||||
import scala.compat.Platform.EOL
|
import scala.compat.Platform.EOL
|
||||||
import BugInParser._
|
import MissingBracketHandler._
|
||||||
import XmlContent._
|
import XmlContent._
|
||||||
import scala.tools.reflect.{ ToolBox, ToolBoxError }
|
import scala.tools.reflect.{ ToolBox, ToolBoxError }
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ private[sbt] case class SplitExpressionsNoBlankies(file: File, lines: Seq[String
|
||||||
* Scala parser cuts last bracket -
|
* Scala parser cuts last bracket -
|
||||||
* @see http://stackoverflow.com/questions/25547149/scala-parser-cuts-last-bracket
|
* @see http://stackoverflow.com/questions/25547149/scala-parser-cuts-last-bracket
|
||||||
*/
|
*/
|
||||||
private[sbt] object BugInParser {
|
private[sbt] object MissingBracketHandler {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param content - parsed file
|
* @param content - parsed file
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
k1 := {}
|
||||||
|
|
||||||
|
k2 := {}
|
||||||
|
|
||||||
|
k3 := {
|
||||||
|
|
||||||
|
|
||||||
|
val x = "hi"
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
k4 := { }; k5 := ()
|
||||||
|
|
||||||
|
k1 <<= k1 map {_ => error("k1")}
|
||||||
|
|
||||||
|
k4 := { val x = k4.value; () }
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
k4 := ()
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
k1 := {}
|
||||||
|
|
||||||
|
k2 := {}
|
||||||
|
|
||||||
|
k3 := {
|
||||||
|
|
||||||
|
|
||||||
|
val x = "hi"
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
k4 := (); k5 := ()
|
||||||
|
|
||||||
|
k1 <<= k1 map {_ => error("k1")}
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
name := "alaMaKota"
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<settings>
|
|
||||||
<setting>
|
|
||||||
<start>1</start>
|
|
||||||
<end>2</end>
|
|
||||||
<set><![CDATA[name := "alaMaKota"]]></set>
|
|
||||||
</setting>
|
|
||||||
</settings>
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
name := "alaMaKota"
|
||||||
|
organization := "scalania"
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
<settings>
|
|
||||||
<setting>
|
|
||||||
<start>1</start>
|
|
||||||
<end>2</end>
|
|
||||||
<set><![CDATA[name := "alaMaKota"]]></set>
|
|
||||||
</setting>
|
|
||||||
<setting>
|
|
||||||
<start>25</start>
|
|
||||||
<end>26</end>
|
|
||||||
<set><![CDATA[organization := "scalania"]]></set>
|
|
||||||
</setting>
|
|
||||||
</settings>
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
checkPom := "OK"
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<settings>
|
|
||||||
<setting>
|
|
||||||
<start>4</start>
|
|
||||||
<end>11</end>
|
|
||||||
<set><![CDATA[checkPom := "OK"]]></set>
|
|
||||||
</setting>
|
|
||||||
</settings>
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
name := "alaMaKota"
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<settings>
|
|
||||||
<setting>
|
|
||||||
<start>1</start>
|
|
||||||
<end>2</end>
|
|
||||||
<set><![CDATA[name := "alaMaKota"]]></set>
|
|
||||||
</setting>
|
|
||||||
</settings>
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
scmpom := <a/><b a="rt">OK</b>
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<settings>
|
|
||||||
<setting>
|
|
||||||
<start>5</start>
|
|
||||||
<end>18</end>
|
|
||||||
<set><![CDATA[scmpom := <a/><b a="rt">OK</b>]]></set>
|
|
||||||
</setting>
|
|
||||||
</settings>
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
k1 := {}
|
||||||
|
|
||||||
|
k2 := {}
|
||||||
|
|
||||||
|
k3 := {
|
||||||
|
|
||||||
|
|
||||||
|
val x = "hi"
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
k4 := { }; k5 := ()
|
||||||
|
|
||||||
|
k1 <<= k1 map {_ => error("k1")}
|
||||||
|
|
||||||
|
k4 := { val x = k4.value; () }
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
k4 := ()
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
k1 := {}
|
||||||
|
|
||||||
|
k2 := {}
|
||||||
|
|
||||||
|
k3 := {
|
||||||
|
|
||||||
|
|
||||||
|
val x = "hi"
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
k4 := (); k5 := ()
|
||||||
|
|
||||||
|
k1 <<= k1 map {_ => error("k1")}
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ class ErrorSpec extends AbstractSpec with ScalaCheck {
|
||||||
| } /* */ //
|
| } /* */ //
|
||||||
|}
|
|}
|
||||||
""".stripMargin
|
""".stripMargin
|
||||||
BugInParser.findMissingText(buildSbt, buildSbt.length, 2, "fake.txt", new MessageOnlyException("fake")) must throwA[MessageOnlyException]
|
MissingBracketHandler.findMissingText(buildSbt, buildSbt.length, 2, "fake.txt", new MessageOnlyException("fake")) must throwA[MessageOnlyException]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
package sbt
|
package sbt.internals.parser
|
||||||
|
|
||||||
import java.io.{ File, FilenameFilter }
|
import java.io.{ File, FilenameFilter }
|
||||||
|
|
||||||
import org.specs2.matcher.MatchResult
|
import org.specs2.matcher.MatchResult
|
||||||
import sbt.internals.parser.{ AbstractSpec, SplitExpressionsNoBlankies }
|
|
||||||
|
|
||||||
import scala.collection.GenTraversableOnce
|
import scala.collection.GenTraversableOnce
|
||||||
import scala.io.Source
|
import scala.io.Source
|
||||||
import scala.xml.XML
|
|
||||||
|
|
||||||
abstract class AbstractSessionSettingsSpec(folder: String, printDetails: Boolean = false) extends AbstractSpec {
|
abstract class AbstractSessionSettingsSpec(folder: String, deepCompare: Boolean = false) extends AbstractSpec {
|
||||||
protected val rootPath = getClass.getResource("").getPath + folder
|
protected val rootPath = getClass.getClassLoader.getResource("").getPath + folder
|
||||||
println(s"Reading files from: $rootPath")
|
println(s"Reading files from: $rootPath")
|
||||||
protected val rootDir = new File(rootPath)
|
protected val rootDir = new File(rootPath)
|
||||||
|
|
||||||
|
|
@ -25,7 +23,7 @@ abstract class AbstractSessionSettingsSpec(folder: String, printDetails: Boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def runTestOnFiles(expectedResultAndMap: File => Seq[(List[String], List[List[String]])]): MatchResult[GenTraversableOnce[File]] = {
|
private def runTestOnFiles(expectedResultAndMap: File => Seq[(List[String], List[String])]): MatchResult[GenTraversableOnce[File]] = {
|
||||||
|
|
||||||
val allFiles = rootDir.listFiles(new FilenameFilter() {
|
val allFiles = rootDir.listFiles(new FilenameFilter() {
|
||||||
def accept(dir: File, name: String) = name.endsWith(".sbt.txt")
|
def accept(dir: File, name: String) = name.endsWith(".sbt.txt")
|
||||||
|
|
@ -34,11 +32,15 @@ abstract class AbstractSessionSettingsSpec(folder: String, printDetails: Boolean
|
||||||
file =>
|
file =>
|
||||||
val originalLines = Source.fromFile(file).getLines().toList
|
val originalLines = Source.fromFile(file).getLines().toList
|
||||||
foreach(expectedResultAndMap(file)) {
|
foreach(expectedResultAndMap(file)) {
|
||||||
case (expectedResultList, map) =>
|
case (expectedResultList, commands) =>
|
||||||
val resultList = SessionSettingsNoBlankies.oldLinesToNew(originalLines, map)
|
val resultList = SbtRefactorings.applyStatements(originalLines, commands.map(List(_)))
|
||||||
val expected = SplitExpressionsNoBlankies(file, expectedResultList)
|
val expected = SplitExpressionsNoBlankies(file, expectedResultList)
|
||||||
val result = SplitExpressionsNoBlankies(file, resultList)
|
val result = SplitExpressionsNoBlankies(file, resultList)
|
||||||
|
if (deepCompare) {
|
||||||
|
expectedResultList must_== resultList
|
||||||
|
}
|
||||||
result.settings must_== expected.settings
|
result.settings must_== expected.settings
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,28 +51,22 @@ abstract class AbstractSessionSettingsSpec(folder: String, printDetails: Boolean
|
||||||
val startsWith = f.getName + "_"
|
val startsWith = f.getName + "_"
|
||||||
name.startsWith(startsWith)
|
name.startsWith(startsWith)
|
||||||
}
|
}
|
||||||
}).toList
|
}).toSeq
|
||||||
dirs.flatMap {
|
dirs.flatMap {
|
||||||
dir =>
|
dir =>
|
||||||
val files = dir.listFiles(new FilenameFilter {
|
val files = dir.listFiles(new FilenameFilter {
|
||||||
override def accept(dir: File, name: String) = name.endsWith(".xml")
|
override def accept(dir: File, name: String) = name.endsWith(".set")
|
||||||
})
|
})
|
||||||
files.map { xmlFile =>
|
files.map { file =>
|
||||||
val xml = XML.loadFile(xmlFile)
|
val list = Source.fromFile(file).getLines().toList
|
||||||
val result = Source.fromFile(xmlFile.getAbsolutePath + ".result").getLines().toList
|
val result = Source.fromFile(file.getAbsolutePath + ".result").getLines().toList
|
||||||
val tupleCollection = (xml \\ "settings" \\ "setting").map {
|
(result, list)
|
||||||
node =>
|
|
||||||
val set = (node \\ "set").text
|
|
||||||
val start = (node \\ "start").text.toInt
|
|
||||||
val end = (node \\ "end").text.toInt
|
|
||||||
List(set)
|
|
||||||
}.toList
|
|
||||||
|
|
||||||
(result, tupleCollection)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SessionSettingsSpec extends AbstractSessionSettingsSpec("../session-settings")
|
class SessionSettingsSpec extends AbstractSessionSettingsSpec("session-settings")
|
||||||
|
|
||||||
|
//class SessionSettingsQuickSpec extends AbstractSessionSettingsSpec("session-settings-quick", true)
|
||||||
Loading…
Reference in New Issue