Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit a70e9fd

Browse files
committed
Merge pull request #59 from som-snytt/issue/file-contents
Avoid "".lines ambiguity
2 parents 53a5130 + 56765ed commit a70e9fd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/scala/scala/tools/partest/nest/Runner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
274274
val prefix = "#partest"
275275
val b = new ListBuffer[String]()
276276
var on = true
277-
for (line <- file2String(checkFile).lines) {
277+
for (line <- file2String(checkFile).linesIfNonEmpty) {
278278
if (line startsWith prefix) {
279279
on = retainOn(line stripPrefix prefix)
280280
} else if (on) {
@@ -285,7 +285,7 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
285285
}
286286

287287
def currentDiff = {
288-
val logged = augmentString(file2String(logFile)).lines.toList
288+
val logged = file2String(logFile).linesIfNonEmpty.toList
289289
val (other, othername) = if (checkFile.canRead) (filteredCheck, checkFile.getName) else (Nil, "empty")
290290
compareContents(original = other, revised = logged, originalName = othername, revisedName = logFile.getName)
291291
}

src/main/scala/scala/tools/partest/package.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ package object partest {
4848
/** Sources have a numerical group, specified by name_7 and so on. */
4949
private val GroupPattern = """.*_(\d+)""".r
5050

51+
implicit class `special string ops`(private val s: String) extends AnyVal {
52+
def linesIfNonEmpty: Iterator[String] = if (!s.isEmpty) s.lines else Iterator.empty
53+
}
54+
5155
implicit class FileOps(val f: File) {
5256
private def sf = SFile(f)
5357

@@ -78,7 +82,7 @@ package object partest {
7882
}
7983

8084
def fileContents: String = try sf.slurp() catch { case _: java.io.FileNotFoundException => "" }
81-
def fileLines: List[String] = augmentString(fileContents).lines.toList
85+
def fileLines: List[String] = fileContents.linesIfNonEmpty.toList
8286
}
8387

8488
implicit class PathOps(p: Path) extends FileOps(p.jfile) { }

0 commit comments

Comments
 (0)