From c4f6217a7071390b51849060a83d993d2c993be7 Mon Sep 17 00:00:00 2001 From: Dan Sanduleac Date: Fri, 4 Apr 2014 10:04:11 +0100 Subject: [PATCH] Fix URITests to work under Windows --- launch/src/test/scala/URITests.scala | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/launch/src/test/scala/URITests.scala b/launch/src/test/scala/URITests.scala index 42c2dc2bd..1fc18b949 100644 --- a/launch/src/test/scala/URITests.scala +++ b/launch/src/test/scala/URITests.scala @@ -8,14 +8,23 @@ import java.net.URI object URITests extends Properties("URI Tests") { + // Need a platform-specific root, otherwise URI will not be absolute (e.g. if we use a "/a/b/c" path in Windows) + // Note: + // If I use "C:" instead of "/C:", then isAbsolute == true for the resulting URI, but resolve is broken: + // e.g. scala> new URI("file", "c:/a/b'/has spaces", null).resolve("a") broken + // res0: java.net.URI = a + // scala> new URI("file", "/c:/a/b'/has spaces", null).resolve("a") working + // res1: java.net.URI = file:/c:/a/b'/a + val Root = if (xsbt.boot.Pre.isWindows) "/C:/" else "/" + val FileProtocol = "file" property("directoryURI adds trailing slash") = secure { - val dirURI = directoryURI(new File("/a/b/c")) - val directURI = filePathURI("/a/b/c/") + val dirURI = directoryURI(new File(Root + "a/b/c")) + val directURI = filePathURI(Root + "a/b/c/") dirURI == directURI } property("directoryURI preserves trailing slash") = secure { - directoryURI(new File("/a/b/c/")) == filePathURI("/a/b/c/") + directoryURI(new File(Root + "a/b/c/")) == filePathURI(Root + "a/b/c/") } property("filePathURI encodes spaces") = secure { @@ -33,18 +42,18 @@ object URITests extends Properties("URI Tests") } property("filePathURI and File.toURI agree for absolute file") = secure { - val s = "/a/b'/has spaces" + val s = Root + "a/b'/has spaces" val viaPath = filePathURI(s) - val viaFile = (new File(s)).toURI + val viaFile = new File(s).toURI s"via path: $viaPath" |: s"via file: $viaFile" |: (viaPath == viaFile) } property("filePathURI supports URIs") = secure { - val s = "file:///is/a/uri/with%20spaces" - val decoded = "/is/a/uri/with spaces" - val encoded = "/is/a/uri/with%20spaces" + val s = s"file://${Root}is/a/uri/with%20spaces" + val decoded = Root + "is/a/uri/with spaces" + val encoded = Root + "is/a/uri/with%20spaces" val fpURI = filePathURI(s) val directURI = new URI(s) s"filePathURI: $fpURI" |: