Skip to content

Commit

Permalink
Merge pull request #1211 from olafurpg/1207
Browse files Browse the repository at this point in the history
Don't crash on isWindows check, fixes #1207
  • Loading branch information
olafurpg authored Jun 5, 2018
2 parents 645e72b + fa9c2ab commit 0758cdb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package org.scalafmt.util

/** Utils related to differences between various operating systems. */
object OsSpecific {
val isWindows: Boolean =
System.getProperty("os.name").toLowerCase().startsWith("windows")
val lineSeparator: String = System.getProperty("line.separator")
def isWindows: Boolean =
// NOTE: org.scalameta:io implements java.io.File for Node.js so this will work correctly
// on Node.js + Window and also in the browser.
java.io.File.separatorChar == '\\'

def fixSeparatorsInPathPattern(unixSpecificPattern: String): String =
if (isWindows) unixSpecificPattern.replace("/", """\\""")
else unixSpecificPattern
unixSpecificPattern.replace('/', java.io.File.separatorChar)

implicit class XtensionStringAsFilename(string: String) {
def asFilename: String = fixSeparatorsInPathPattern(string)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.scalafmt

class ScalafmtConfigTest extends org.scalatest.FunSuite {

test("project.matcher") {
val config = Scalafmt
.parseHoconConfig(
"""
|project.excludeFilters = [
| "scalafmt-benchmarks/src/resources"
| "sbt-test"
| "bin/issue"
|]
""".stripMargin
)
.get
assert(config.project.matcher.matches("qux/Kazbar.scala"))
assert(!config.project.matcher.matches("sbt-test/src/main"))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ class ScalafmtTest extends org.scalatest.FunSuite {
|""".stripMargin,
config.ScalafmtConfig.default40
)

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.scalafmt

import org.scalafmt.util.DiffAssertions
import org.scalafmt.util.OsSpecific.lineSeparator
import java.lang.System.lineSeparator
import org.scalatest.FunSuite

class EmptyFileTest extends FunSuite with DiffAssertions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ trait HasTests extends FunSuiteLike with FormatAssertions {

def parseDiffTests(content: String, filename: String): Seq[DiffTest] = {
val sep =
if (content.contains(OsSpecific.lineSeparator)) OsSpecific.lineSeparator
if (content.contains(System.lineSeparator)) System.lineSeparator
else "\n"
val spec = filename.stripPrefix(testDir + File.separator)
val moduleOnly = isOnly(content)
Expand Down

0 comments on commit 0758cdb

Please sign in to comment.