Skip to content

Commit

Permalink
Cleanup duplicate scripts and inconsistencies between platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
reibitto committed Aug 19, 2024
1 parent 800599f commit 2ace2c2
Show file tree
Hide file tree
Showing 20 changed files with 19 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ private[process] object FilePlatformSpecific {
type File = String
type Path = String

def fileOf(file: String): File = file

def getAbsolute(file: File): js.Any = {
val path = js.Dynamic.global.require("path")
val nodejs = js.Dynamic.global.require("process")
Expand Down
9 changes: 0 additions & 9 deletions zio-process/js/src/test/bash/both-streams-test.sh

This file was deleted.

3 changes: 0 additions & 3 deletions zio-process/js/src/test/bash/echo-repeat.sh

This file was deleted.

5 changes: 0 additions & 5 deletions zio-process/js/src/test/bash/kill-test/sample-child.sh

This file was deleted.

7 changes: 0 additions & 7 deletions zio-process/js/src/test/bash/kill-test/sample-parent.sh

This file was deleted.

3 changes: 0 additions & 3 deletions zio-process/js/src/test/bash/no-permissions.sh

This file was deleted.

6 changes: 0 additions & 6 deletions zio-process/js/src/test/bash/stdin-echo.sh

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ package zio.process
private[process] object FilePlatformSpecific {
type File = java.io.File

def fileOf(file: String): File = new File(file)

def exists(file: File): Boolean = file.exists()
}
9 changes: 0 additions & 9 deletions zio-process/jvm/src/test/bash/both-streams-test.sh

This file was deleted.

3 changes: 0 additions & 3 deletions zio-process/jvm/src/test/bash/echo-repeat.sh

This file was deleted.

5 changes: 0 additions & 5 deletions zio-process/jvm/src/test/bash/kill-test/sample-child.sh

This file was deleted.

7 changes: 0 additions & 7 deletions zio-process/jvm/src/test/bash/kill-test/sample-parent.sh

This file was deleted.

3 changes: 0 additions & 3 deletions zio-process/jvm/src/test/bash/no-permissions.sh

This file was deleted.

6 changes: 0 additions & 6 deletions zio-process/jvm/src/test/bash/stdin-echo.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ object CommandPlatformSpecificSpec extends ZIOProcessBaseSpec {
def spec = suite("CommandSpec")(
test("killTree also kills child processes") {
for {
process <- Command("./sample-parent.sh").workingDirectory(new File("src/test/bash/kill-test")).run
process <-
Command("./sample-parent.sh").workingDirectory(fileOf("zio-process/shared/src/test/bash/kill-test")).run
pids <- process.stdout.stream
.via(ZPipeline.utf8Decode)
.via(ZPipeline.splitLines)
Expand All @@ -28,7 +29,8 @@ object CommandPlatformSpecificSpec extends ZIOProcessBaseSpec {
} @@ TestAspect.nonFlaky(25),
test("killTreeForcibly also kills child processes") {
for {
process <- Command("./sample-parent.sh").workingDirectory(new File("src/test/bash/kill-test")).run
process <-
Command("./sample-parent.sh").workingDirectory(fileOf("zio-process/shared/src/test/bash/kill-test")).run
pids <- process.stdout.stream
.via(ZPipeline.utf8Decode)
.via(ZPipeline.splitLines)
Expand All @@ -43,7 +45,8 @@ object CommandPlatformSpecificSpec extends ZIOProcessBaseSpec {
} @@ TestAspect.nonFlaky(25),
test("kill only kills parent process") {
for {
process <- Command("./sample-parent.sh").workingDirectory(new File("src/test/bash/kill-test")).run
process <-
Command("./sample-parent.sh").workingDirectory(fileOf("zio-process/shared/src/test/bash/kill-test")).run
pids <- process.stdout.stream
.via(ZPipeline.utf8Decode)
.via(ZPipeline.splitLines)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ package zio.process
private[process] object FilePlatformSpecific {
type File = java.io.File

def fileOf(file: String): File = new File(file)

def exists(file: File): Boolean = file.exists()
}

This file was deleted.

13 changes: 7 additions & 6 deletions zio-process/shared/src/test/scala/zio/process/CommandSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import zio.stream.ZPipeline
import zio.test.Assertion._
import zio.test._
import zio._
import zio.process.FilePlatformSpecific.fileOf

import java.nio.charset.StandardCharsets

// TODO: Add aspects for different OSes? scala.util.Properties.isWin, etc. Also try to make this as OS agnostic as possible in the first place
object CommandSpec extends ZIOProcessBaseSpec with SpecProperties {
object CommandSpec extends ZIOProcessBaseSpec {

def spec = suite("CommandSpec")(
test("convert stdout to string") {
Expand Down Expand Up @@ -53,7 +54,7 @@ object CommandSpec extends ZIOProcessBaseSpec with SpecProperties {
test("accept file stdin") {
for {
lines <-
Command("cat").stdin(ProcessInput.fromFile(mkFile(s"zio-process/shared/src/test/bash/echo-repeat.sh"))).lines
Command("cat").stdin(ProcessInput.fromFile(fileOf(s"zio-process/shared/src/test/bash/echo-repeat.sh"))).lines
} yield assertTrue(lines.head == "#!/bin/bash")
},
test("support different encodings") {
Expand All @@ -65,12 +66,12 @@ object CommandSpec extends ZIOProcessBaseSpec with SpecProperties {
assertZIO(zio)(equalTo("piped in"))
},
test("set workingDirectory") {
val zio = Command("ls").workingDirectory(mkFile(s"zio-process/shared/src/test/bash")).lines
val zio = Command("ls").workingDirectory(fileOf(s"zio-process/shared/src/test/bash")).lines

assertZIO(zio)(contains("no-permissions.sh"))
},
test("be able to fallback to a different program using typed error channel") {
val zio = Command("echo", "-n", "wrong").workingDirectory(mkFile("no-folder")).string.catchSome {
val zio = Command("echo", "-n", "wrong").workingDirectory(fileOf("no-folder")).string.catchSome {
case CommandError.WorkingDirectoryMissing(_) =>
Command("echo", "-n", "test").string
}
Expand Down Expand Up @@ -136,7 +137,7 @@ object CommandSpec extends ZIOProcessBaseSpec with SpecProperties {
},
test("typed error for non-existent working directory") {
for {
exit <- Command("ls").workingDirectory(mkFile("/some/bad/path")).lines.exit
exit <- Command("ls").workingDirectory(fileOf("/some/bad/path")).lines.exit
} yield assert(exit)(fails(isSubtype[CommandError.WorkingDirectoryMissing](anything)))
},
test("end of stream also closes underlying process") {
Expand All @@ -153,7 +154,7 @@ object CommandSpec extends ZIOProcessBaseSpec with SpecProperties {
for {
commandQueue <- Queue.unbounded[Chunk[Byte]]
process <- Command("./stdin-echo.sh")
.workingDirectory(mkFile(s"zio-process/shared/src/test/bash"))
.workingDirectory(fileOf(s"zio-process/shared/src/test/bash"))
.stdin(ProcessInput.fromQueue(commandQueue))
.run
_ <- commandQueue.offer(Chunk.fromArray("line1\nline2\n".getBytes(StandardCharsets.UTF_8)))
Expand Down

0 comments on commit 2ace2c2

Please sign in to comment.