Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ object os extends Module {
object jvm extends Cross[OsJvmModule](scalaVersions)
trait OsJvmModule extends OsModule with MiMaChecks {
object test extends ScalaTests with OsLibTestModule
object nohometest extends ScalaTests with OsLibTestModule
}

object native extends Cross[OsNativeModule](scalaVersions)
Expand All @@ -134,6 +135,7 @@ object os extends Module {
object test extends ScalaNativeTests with OsLibTestModule {
def nativeLinkStubs = true
}
object nohometest extends ScalaNativeTests with OsLibTestModule
}

object watch extends Module {
Expand Down
25 changes: 25 additions & 0 deletions os/nohometest/src/NoHomeTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package test.os

import utest._

object NoHomeTests extends TestSuite {
private lazy val isWindows = sys.props("os.name").toLowerCase().contains("windows")

val tests = Tests {
test("pwd when home is not available") {
System.setProperty("user.home", "?")
val homeException = intercept[IllegalArgumentException] { os.home }
.getMessage()

val expectedException =
if (isWindows)
"Illegal char <?> at index 0: ?"
else
"requirement failed: ? is not an absolute path"

assert(homeException == expectedException)
os.pwd
()
}
}
}
9 changes: 8 additions & 1 deletion os/src-jvm/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ package object os {
os.ResourcePath.resource(resRoot)
}

// See https://github.com/com-lihaoyi/os-lib/pull/239
// and https://github.com/lightbend/mima/issues/794
// why the need the inner object to preserve binary compatibility
private object _home {
lazy val value = Path(System.getProperty("user.home"))
}

/**
* The user's home directory
*/
val home: Path = Path(System.getProperty("user.home"))
def home: Path = _home.value

/**
* The current working directory for this process.
Expand Down
9 changes: 8 additions & 1 deletion os/src-native/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ package object os {
path
}

// See https://github.com/com-lihaoyi/os-lib/pull/239
// and https://github.com/lightbend/mima/issues/794
// why the need the inner object to preserve binary compatibility
private object _home {
lazy val value = Path(System.getProperty("user.home"))
}

/**
* The user's home directory
*/
val home: Path = Path(System.getProperty("user.home"))
def home: Path = _home.value

/**
* The current working directory for this process.
Expand Down