|
@@ -3,6 +3,7 @@
|
|
|
package file
|
|
|
|
|
|
import (
|
|
|
+ "os"
|
|
|
"testing"
|
|
|
|
|
|
"src.elv.sh/pkg/eval"
|
|
@@ -14,10 +15,22 @@ func TestIsTTY(t *testing.T) {
|
|
|
ev.ExtendGlobal(eval.BuildNs().AddNs("file", Ns))
|
|
|
}
|
|
|
|
|
|
- evaltest.TestWithSetup(t, setup,
|
|
|
- That("file:is-tty 0 < /dev/null").Puts(false),
|
|
|
- That("file:is-tty (num 0) < /dev/null").Puts(false),
|
|
|
- That("file:is-tty 0 < /dev/tty").Puts(true),
|
|
|
- That("file:is-tty (num 0) < /dev/tty").Puts(true),
|
|
|
- )
|
|
|
+ if canOpen("/dev/null") {
|
|
|
+ evaltest.TestWithSetup(t, setup,
|
|
|
+ That("file:is-tty 0 < /dev/null").Puts(false),
|
|
|
+ That("file:is-tty (num 0) < /dev/null").Puts(false),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if canOpen("/dev/tty") {
|
|
|
+ evaltest.TestWithSetup(t, setup,
|
|
|
+ That("file:is-tty 0 < /dev/tty").Puts(true),
|
|
|
+ That("file:is-tty (num 0) < /dev/tty").Puts(true),
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func canOpen(name string) bool {
|
|
|
+ f, err := os.Open(name)
|
|
|
+ f.Close()
|
|
|
+ return err == nil
|
|
|
}
|