From 8b1ee8a8f264a5e2c0b6f47e966aa79c792d1622 Mon Sep 17 00:00:00 2001 From: kxbmap Date: Thu, 7 Apr 2016 04:08:11 +0900 Subject: [PATCH] Fix test failure on Windows --- .../scala/com/typesafe/config/impl/ConfParserTest.scala | 7 ++----- .../scala/com/typesafe/config/impl/ConfigValueTest.scala | 5 +++-- .../test/scala/com/typesafe/config/impl/TestUtils.scala | 6 ++++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfParserTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfParserTest.scala index 75610212..171778bb 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfParserTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfParserTest.scala @@ -5,15 +5,12 @@ package com.typesafe.config.impl import org.junit.Assert._ import org.junit._ -import java.io.Reader import java.io.StringReader import com.typesafe.config._ -import java.util.HashMap import scala.collection.JavaConverters._ import java.io.File import java.net.URL import java.util.Properties -import java.io.ByteArrayInputStream class ConfParserTest extends TestUtils { @@ -714,7 +711,7 @@ class ConfParserTest extends TestUtils { def includeFileNotQuoted() { // this test cannot work on Windows val f = resourceFile("test01") - if (f.toString.contains("\\")) { + if (isWindows) { System.err.println("includeFileNotQuoted test skipped on Windows") } else { val e = intercept[ConfigException.Parse] { @@ -727,7 +724,7 @@ class ConfParserTest extends TestUtils { @Test def includeFileNotQuotedAndSpecialChar() { val f = resourceFile("test01") - if (f.toString.contains("\\")) { + if (isWindows) { System.err.println("includeFileNotQuoted test skipped on Windows") } else { val e = intercept[ConfigException.Parse] { diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala index 9b2ea32d..059c1cad 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala @@ -13,7 +13,6 @@ import com.typesafe.config.ConfigObject import com.typesafe.config.ConfigList import com.typesafe.config.ConfigException import com.typesafe.config.ConfigValueType -import com.typesafe.config.ConfigOrigin import com.typesafe.config.ConfigRenderOptions import com.typesafe.config.ConfigValueFactory import com.typesafe.config.ConfigFactory @@ -721,7 +720,9 @@ class ConfigValueTest extends TestUtils { // the filename is made absolute when converting to url assertTrue(hasFilename.url.toExternalForm.contains("foo")) assertNull(noFilename.url) - assertEquals("file:/baz", SimpleConfigOrigin.newFile("/baz").url.toExternalForm) + val rootFile = SimpleConfigOrigin.newFile("/baz") + val rootFileURL = if (isWindows) s"file:/$userDrive/baz" else "file:/baz" + assertEquals(rootFileURL, rootFile.url.toExternalForm) val urlOrigin = SimpleConfigOrigin.newURL(new URL("file:/foo")) assertEquals("/foo", urlOrigin.filename) diff --git a/config/src/test/scala/com/typesafe/config/impl/TestUtils.scala b/config/src/test/scala/com/typesafe/config/impl/TestUtils.scala index 581a7355..a038b3ea 100644 --- a/config/src/test/scala/com/typesafe/config/impl/TestUtils.scala +++ b/config/src/test/scala/com/typesafe/config/impl/TestUtils.scala @@ -4,12 +4,10 @@ package com.typesafe.config.impl import org.junit.Assert._ -import org.junit._ import com.typesafe.config.ConfigOrigin import java.io.Reader import java.io.StringReader import com.typesafe.config.ConfigParseOptions -import com.typesafe.config.Config import com.typesafe.config.ConfigSyntax import com.typesafe.config.ConfigFactory import java.io.File @@ -20,6 +18,7 @@ import java.io.ObjectInputStream import java.io.NotSerializableException import scala.annotation.tailrec import java.net.URL +import java.util.Locale import java.util.concurrent.Executors import java.util.concurrent.Callable import com.typesafe.config._ @@ -712,6 +711,9 @@ abstract trait TestUtils { def nodeOptionalSubstitution(expression: Token*) = new ConfigNodeSimpleValue(tokenOptionalSubstitution(expression: _*)) def nodeSubstitution(expression: Token*) = new ConfigNodeSimpleValue(tokenSubstitution(expression: _*)) + def isWindows: Boolean = sys.props.get("os.name").exists(_.toLowerCase(Locale.ROOT).contains("windows")) + def userDrive: String = if (isWindows) sys.props.get("user.dir").fold("")(_.takeWhile(_ != File.separatorChar)) else "" + // this is importantly NOT using Path.newPath, which relies on // the parser; in the test suite we are often testing the parser, // so we don't want to use the parser to build the expected result.