First pass for windows support.
This commit is contained in:
107
src/test/groovy/net/rubygrapefruit/platform/PosixFileTest.groovy
Normal file → Executable file
107
src/test/groovy/net/rubygrapefruit/platform/PosixFileTest.groovy
Normal file → Executable file
@@ -1,52 +1,55 @@
|
||||
package net.rubygrapefruit.platform
|
||||
|
||||
import spock.lang.Specification
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class PosixFileTest extends Specification {
|
||||
@Rule TemporaryFolder tmpDir
|
||||
final PosixFile file = Native.get(PosixFile.class)
|
||||
|
||||
def "can set mode on a file"() {
|
||||
def testFile = tmpDir.newFile("test.txt")
|
||||
|
||||
when:
|
||||
file.setMode(testFile, 0740)
|
||||
|
||||
then:
|
||||
file.getMode(testFile) == 0740
|
||||
}
|
||||
|
||||
def "can set mode on a file with unicode in its name"() {
|
||||
def testFile = tmpDir.newFile("test\u03b1.txt")
|
||||
|
||||
when:
|
||||
file.setMode(testFile, 0740)
|
||||
|
||||
then:
|
||||
file.getMode(testFile) == 0740
|
||||
}
|
||||
|
||||
def "throws exception on failure to set mode"() {
|
||||
def file = new File(tmpDir.root, "unknown")
|
||||
|
||||
when:
|
||||
this.file.setMode(file, 0660)
|
||||
|
||||
then:
|
||||
NativeException e = thrown()
|
||||
e.message == "Could not set UNIX mode on $file: could not chmod file (errno 2)"
|
||||
}
|
||||
|
||||
def "throws exception on failure to get mode"() {
|
||||
def file = new File(tmpDir.root, "unknown")
|
||||
|
||||
when:
|
||||
this.file.getMode(file)
|
||||
|
||||
then:
|
||||
NativeException e = thrown()
|
||||
e.message == "Could not get UNIX mode on $file: could not stat file (errno 2)"
|
||||
}
|
||||
}
|
||||
package net.rubygrapefruit.platform
|
||||
|
||||
import spock.lang.Specification
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import spock.lang.IgnoreIf
|
||||
import net.rubygrapefruit.platform.internal.Platform
|
||||
|
||||
@IgnoreIf({Platform.current().windows})
|
||||
class PosixFileTest extends Specification {
|
||||
@Rule TemporaryFolder tmpDir
|
||||
final PosixFile file = Native.get(PosixFile.class)
|
||||
|
||||
def "can set mode on a file"() {
|
||||
def testFile = tmpDir.newFile("test.txt")
|
||||
|
||||
when:
|
||||
file.setMode(testFile, 0740)
|
||||
|
||||
then:
|
||||
file.getMode(testFile) == 0740
|
||||
}
|
||||
|
||||
def "can set mode on a file with unicode in its name"() {
|
||||
def testFile = tmpDir.newFile("test\u03b1.txt")
|
||||
|
||||
when:
|
||||
file.setMode(testFile, 0740)
|
||||
|
||||
then:
|
||||
file.getMode(testFile) == 0740
|
||||
}
|
||||
|
||||
def "throws exception on failure to set mode"() {
|
||||
def file = new File(tmpDir.root, "unknown")
|
||||
|
||||
when:
|
||||
this.file.setMode(file, 0660)
|
||||
|
||||
then:
|
||||
NativeException e = thrown()
|
||||
e.message == "Could not set UNIX mode on $file: could not chmod file (errno 2)"
|
||||
}
|
||||
|
||||
def "throws exception on failure to get mode"() {
|
||||
def file = new File(tmpDir.root, "unknown")
|
||||
|
||||
when:
|
||||
this.file.getMode(file)
|
||||
|
||||
then:
|
||||
NativeException e = thrown()
|
||||
e.message == "Could not get UNIX mode on $file: could not stat file (errno 2)"
|
||||
}
|
||||
}
|
||||
|
||||
30
src/test/groovy/net/rubygrapefruit/platform/ProcessTest.groovy
Normal file → Executable file
30
src/test/groovy/net/rubygrapefruit/platform/ProcessTest.groovy
Normal file → Executable file
@@ -1,15 +1,15 @@
|
||||
package net.rubygrapefruit.platform
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import spock.lang.Specification
|
||||
|
||||
class ProcessTest extends Specification {
|
||||
@Rule TemporaryFolder tmpDir
|
||||
final Process process = Native.get(Process.class)
|
||||
|
||||
def "can get PID"() {
|
||||
expect:
|
||||
process.getPid() != 0
|
||||
}
|
||||
}
|
||||
package net.rubygrapefruit.platform
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import spock.lang.Specification
|
||||
|
||||
class ProcessTest extends Specification {
|
||||
@Rule TemporaryFolder tmpDir
|
||||
final Process process = Native.get(Process.class)
|
||||
|
||||
def "can get PID"() {
|
||||
expect:
|
||||
process.getProcessId() != 0
|
||||
}
|
||||
}
|
||||
|
||||
50
src/test/groovy/net/rubygrapefruit/platform/TerminalTest.groovy
Normal file → Executable file
50
src/test/groovy/net/rubygrapefruit/platform/TerminalTest.groovy
Normal file → Executable file
@@ -1,25 +1,25 @@
|
||||
package net.rubygrapefruit.platform
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import spock.lang.Specification
|
||||
|
||||
class TerminalTest extends Specification {
|
||||
@Rule TemporaryFolder tmpDir
|
||||
final TerminalAccess terminal = Native.get(TerminalAccess.class)
|
||||
|
||||
def "can check if attached to terminal"() {
|
||||
expect:
|
||||
!terminal.isTerminal(TerminalAccess.Output.Stdout);
|
||||
!terminal.isTerminal(TerminalAccess.Output.Stderr);
|
||||
}
|
||||
|
||||
def "cannot determine terminal size from a test"() {
|
||||
when:
|
||||
terminal.getTerminal(TerminalAccess.Output.Stdout)
|
||||
|
||||
then:
|
||||
NativeException e = thrown()
|
||||
e.message == 'Could not open terminal: not a terminal'
|
||||
}
|
||||
}
|
||||
package net.rubygrapefruit.platform
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import spock.lang.Specification
|
||||
|
||||
class TerminalTest extends Specification {
|
||||
@Rule TemporaryFolder tmpDir
|
||||
final TerminalAccess terminal = Native.get(TerminalAccess.class)
|
||||
|
||||
def "can check if attached to terminal"() {
|
||||
expect:
|
||||
!terminal.isTerminal(TerminalAccess.Output.Stdout);
|
||||
!terminal.isTerminal(TerminalAccess.Output.Stderr);
|
||||
}
|
||||
|
||||
def "cannot access terminal from a test"() {
|
||||
when:
|
||||
terminal.getTerminal(TerminalAccess.Output.Stdout)
|
||||
|
||||
then:
|
||||
NativeException e = thrown()
|
||||
e.message == 'Could not open terminal: not a terminal'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user