You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/10/24 15:03:01 UTC
incubator-groovy git commit: show tests written for a different
operating system as skipped tests
Repository: incubator-groovy
Updated Branches:
refs/heads/master 5661ef701 -> 799e066b6
show tests written for a different operating system as skipped tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/799e066b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/799e066b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/799e066b
Branch: refs/heads/master
Commit: 799e066b6d630950934c784f3c6edb2444afa5b3
Parents: 5661ef7
Author: pascalschumacher <pa...@gmx.net>
Authored: Sat Oct 24 15:02:44 2015 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Oct 24 15:02:44 2015 +0200
----------------------------------------------------------------------
gradle/test.gradle | 7 -
src/spec/test/gdk/WorkingWithIOSpecTest.groovy | 139 +++++++++++--------
.../execute/ExecuteTest_LinuxSolaris.groovy | 30 ++++
.../groovy/execute/ExecuteTest_Windows.groovy | 21 +++
.../completion/FileNameCompleterTest.groovy | 23 ++-
5 files changed, 149 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/799e066b/gradle/test.gradle
----------------------------------------------------------------------
diff --git a/gradle/test.gradle b/gradle/test.gradle
index 6267450..d2f3a56 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -89,13 +89,6 @@ tasks.addRule('Pattern: testSingle<Name> will test **/<Name>.class') { String ta
def buildExcludeFilter() {
def excludes = []
- // deal with OS specific tests
- if (Os.isFamily(Os.FAMILY_WINDOWS)) {
- excludes << 'ExecuteTest_LinuxSolaris'
- } else if (Os.isFamily(Os.FAMILY_UNIX)) {
- excludes << 'ExecuteTest_Windows'
- }
-
// if not compiled with indy support, disable indy tests
if (!rootProject.useIndy()) {
excludes += ['indy', 'Indy']
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/799e066b/src/spec/test/gdk/WorkingWithIOSpecTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/gdk/WorkingWithIOSpecTest.groovy b/src/spec/test/gdk/WorkingWithIOSpecTest.groovy
index 3d362ec..ebd8102 100644
--- a/src/spec/test/gdk/WorkingWithIOSpecTest.groovy
+++ b/src/spec/test/gdk/WorkingWithIOSpecTest.groovy
@@ -23,15 +23,25 @@ package gdk
import groovy.io.FileType
import groovy.io.FileVisitResult
import groovy.transform.CompileStatic
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import static org.junit.Assume.assumeTrue
+
+@RunWith(JUnit4)
class WorkingWithIOSpecTest extends GroovyTestCase {
private final static boolean unixlike =
System.getProperty('os.name').contains('Linux') ||
System.getProperty('os.name').contains('Mac OS')
- private final static boolean windoz =
+ private final static boolean windoz =
System.getProperty('os.name').contains('Windows')
+ private assumeUnixLikeSystem() {
+ assumeTrue('Test requires unix like system.', unixlike)
+ }
+
@CompileStatic
private void doInTmpDir(Closure cl) {
def baseDir = File.createTempDir()
@@ -42,6 +52,7 @@ class WorkingWithIOSpecTest extends GroovyTestCase {
}
}
+ @Test
void testFileIntro() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -76,6 +87,7 @@ Le bruit de l'eau.''')
}
}
+ @Test
void testWithReader() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -101,6 +113,7 @@ Fin.''')
}
}
+ @Test
void testWithWriter() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -114,6 +127,7 @@ Fin.''')
}
}
+ @Test
void testLeftShift() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -125,6 +139,7 @@ Fin.''')
}
}
+ @Test
void testSetBytes() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -135,6 +150,7 @@ Fin.''')
}
}
+ @Test
void testEachFile() {
doInTmpDir { builder ->
File dir = builder {
@@ -153,6 +169,7 @@ Fin.''')
}
}
+ @Test
void testEachFileRecurse() {
doInTmpDir { builder ->
File dir = builder {
@@ -174,6 +191,7 @@ Fin.''')
}
}
+ @Test
void testTraverse() {
doInTmpDir { builder ->
File dir = builder {
@@ -197,6 +215,7 @@ Fin.''')
}
}
+ @Test
void testGetInputStreamFromFile() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -218,6 +237,7 @@ Fin.''')
}
}
+ @Test
void testFileOutputStream() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -235,6 +255,7 @@ Fin.''')
}
}
+ @Test
void testDataInputOutput() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -257,6 +278,7 @@ Fin.''')
}
}
+ @Test
void testObjectInputOutput() {
doInTmpDir { dir ->
File baseDir = dir.baseDir
@@ -278,6 +300,7 @@ Fin.''')
}
}
+ @Test
void testProcess1() {
if (unixlike) {
// tag::process_list_files[]
@@ -303,72 +326,74 @@ Fin.''')
}
}
- void testProcess2() {
- if (unixlike) {
- // tag::process_list_files_line_by_line[]
- def process = "ls -l".execute() // <1>
- process.in.eachLine { line -> // <2>
- println line // <3>
- }
- // end::process_list_files_line_by_line[]
- assert process instanceof Process
+ @Test
+ void testProcess2() {
+ assumeUnixLikeSystem()
+
+ // tag::process_list_files_line_by_line[]
+ def process = "ls -l".execute() // <1>
+ process.in.eachLine { line -> // <2>
+ println line // <3>
}
+ // end::process_list_files_line_by_line[]
+ assert process instanceof Process
}
+ @Test
void testProcessConsumeOutput() {
- if (unixlike) {
- doInTmpDir { b ->
- File file = null
- def tmpDir = b.tmp {
- file = 'foo.tmp'('foo')
- }
- assert file.exists()
- // tag::consumeoutput[]
- def p = "rm -f foo.tmp".execute([], tmpDir)
- p.consumeProcessOutput()
- p.waitFor()
- // end::consumeoutput[]
- assert !file.exists()
- }
+ assumeUnixLikeSystem()
+ doInTmpDir { b ->
+ File file = null
+ def tmpDir = b.tmp {
+ file = 'foo.tmp'('foo')
+ }
+ assert file.exists()
+ // tag::consumeoutput[]
+ def p = "rm -f foo.tmp".execute([], tmpDir)
+ p.consumeProcessOutput()
+ p.waitFor()
+ // end::consumeoutput[]
+ assert !file.exists()
}
}
+ @Test
void testProcessPipe() {
- if (unixlike) {
- doInTmpDir { b ->
- def proc1, proc2, proc3, proc4
- // tag::pipe_example_1[]
- proc1 = 'ls'.execute()
- proc2 = 'tr -d o'.execute()
- proc3 = 'tr -d e'.execute()
- proc4 = 'tr -d i'.execute()
- proc1 | proc2 | proc3 | proc4
- proc4.waitFor()
- if (proc4.exitValue()) {
- println proc4.err.text
- } else {
- println proc4.text
- }
- // end::pipe_example_1[]
-
- // tag::pipe_example_2[]
- def sout = new StringBuilder()
- def serr = new StringBuilder()
- proc2 = 'tr -d o'.execute()
- proc3 = 'tr -d e'.execute()
- proc4 = 'tr -d i'.execute()
- proc4.consumeProcessOutput(sout, serr)
- proc2 | proc3 | proc4
- [proc2, proc3].each { it.consumeProcessErrorStream(serr) }
- proc2.withWriter { writer ->
- writer << 'testfile.groovy'
- }
- proc4.waitForOrKill(1000)
- println "Standard output: $sout"
- println "Standard error: $serr"
- // end::pipe_example_2[]
+ assumeUnixLikeSystem()
+
+ doInTmpDir { b ->
+ def proc1, proc2, proc3, proc4
+ // tag::pipe_example_1[]
+ proc1 = 'ls'.execute()
+ proc2 = 'tr -d o'.execute()
+ proc3 = 'tr -d e'.execute()
+ proc4 = 'tr -d i'.execute()
+ proc1 | proc2 | proc3 | proc4
+ proc4.waitFor()
+ if (proc4.exitValue()) {
+ println proc4.err.text
+ } else {
+ println proc4.text
+ }
+ // end::pipe_example_1[]
+
+ // tag::pipe_example_2[]
+ def sout = new StringBuilder()
+ def serr = new StringBuilder()
+ proc2 = 'tr -d o'.execute()
+ proc3 = 'tr -d e'.execute()
+ proc4 = 'tr -d i'.execute()
+ proc4.consumeProcessOutput(sout, serr)
+ proc2 | proc3 | proc4
+ [proc2, proc3].each { it.consumeProcessErrorStream(serr) }
+ proc2.withWriter { writer ->
+ writer << 'testfile.groovy'
}
+ proc4.waitForOrKill(1000)
+ println "Standard output: $sout"
+ println "Standard error: $serr"
+ // end::pipe_example_2[]
}
}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/799e066b/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy b/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
index 8f66593..9c8307f 100644
--- a/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
+++ b/src/test/groovy/execute/ExecuteTest_LinuxSolaris.groovy
@@ -21,6 +21,13 @@
package groovy.execute
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+import static org.junit.Assume.assumeTrue
+
/**
* Test to ensure that the execute mechanism works fine on *nix-like systems. For these OSs we
* can effectively guarantee the existence of some programs that we can run. Assume the search
@@ -30,17 +37,32 @@ package groovy.execute
*
* @author Russel Winder
*/
+@RunWith(JUnit4)
class ExecuteTest_LinuxSolaris extends GroovyTestCase {
+
+ private static final boolean linuxOrSolaris = System.getProperty('os.name').contains('Linux') ||
+ System.getProperty('os.name').contains('sunos')
+
+ @Before
+ void assumeUnixOrSolaris() {
+ assumeTrue('Test requires Linux or Solaris.', linuxOrSolaris)
+ }
+
+ @Test
void testShellEchoOneArray ( ) {
def process = ( [ "sh" , "-c" , "echo 1" ] as String[] ).execute ( )
process.waitFor ( )
assert process.in.text.trim ( ) == "1"
}
+
+ @Test
void testShellEchoOneList ( ) {
def process = [ "sh" , "-c" , "echo 1" ].execute ( )
process.waitFor ( )
assert process.in.text.trim ( ) == "1"
}
+
+ @Test
void testEchoOneArray ( ) {
try {
def process = ( [ "echo 1" ] as String[] ).execute ( )
@@ -49,6 +71,8 @@ class ExecuteTest_LinuxSolaris extends GroovyTestCase {
}
catch ( IOException ioe ) { }
}
+
+ @Test
void testEchoOneList ( ) {
try {
def process = [ "echo 1" ].execute ( )
@@ -57,16 +81,22 @@ class ExecuteTest_LinuxSolaris extends GroovyTestCase {
}
catch ( IOException ioe ) { }
}
+
+ @Test
void testEchoOneScalar ( ) {
def process = "echo 1".execute ( )
process.waitFor ( )
assert process.in.text.trim ( ) == "1"
}
+
+ @Test
void testEchoArray ( ) {
def process = ( [ "echo" , "1" ] as String[] ).execute ( )
process.waitFor ( )
assert process.in.text.trim ( ) == "1"
}
+
+ @Test
void testEchoList ( ) {
def process = [ "echo" , "1" ].execute ( )
process.waitFor ( )
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/799e066b/src/test/groovy/execute/ExecuteTest_Windows.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/execute/ExecuteTest_Windows.groovy b/src/test/groovy/execute/ExecuteTest_Windows.groovy
index edc677b..41a97ce 100644
--- a/src/test/groovy/execute/ExecuteTest_Windows.groovy
+++ b/src/test/groovy/execute/ExecuteTest_Windows.groovy
@@ -18,6 +18,13 @@
*/
package groovy.execute
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+import static org.junit.Assume.assumeTrue
+
/**
* Test to ensure that the execute mechanism works fine on Windows systems.
* <p>
@@ -25,19 +32,31 @@ package groovy.execute
*
* @author Paul King
*/
+@RunWith(JUnit4)
class ExecuteTest_Windows extends GroovyTestCase {
+
+ private static final boolean windows = System.properties['os.name'].toLowerCase().contains('windows')
+
+ @Before
+ void assumeUnixOrSolaris() {
+ assumeTrue('Test requires Windows.', windows)
+ }
+
+ @Test
void testCmdEchoOneArray() {
def process = ( [ "cmd.exe" , "/c" , "echo 1" ] as String[] ).execute()
process.waitFor()
assert process.in.text.trim() == "1"
}
+ @Test
void testCmdEchoOneList() {
def process = [ "cmd.exe" , "/c" , "echo 1" ].execute ( )
process.waitFor()
assert process.in.text.trim() == "1"
}
+ @Test
void testCmdDate() {
def process = "cmd.exe /c date.exe /t".execute()
process.waitFor()
@@ -50,6 +69,7 @@ class ExecuteTest_Windows extends GroovyTestCase {
assert theDate.size() >= minLen, "Expected '$theDate' to be at least $minLen chars long"
}
+ @Test
void testEchoOneArray() {
try {
def process = ( [ "echo 1" ] as String[] ).execute()
@@ -59,6 +79,7 @@ class ExecuteTest_Windows extends GroovyTestCase {
catch ( IOException ioe ) { }
}
+ @Test
void testEchoOneList() {
try {
def process = [ "echo 1" ].execute()
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/799e066b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/completion/FileNameCompleterTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/completion/FileNameCompleterTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/completion/FileNameCompleterTest.groovy
index 41273d6..b5e2c79 100644
--- a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/completion/FileNameCompleterTest.groovy
+++ b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/completion/FileNameCompleterTest.groovy
@@ -18,10 +18,17 @@
*/
package org.codehaus.groovy.tools.shell.completion
+import org.junit.Test
import org.junit.rules.TemporaryFolder
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import static org.junit.Assume.assumeFalse
+
+@RunWith(JUnit4)
class FileNameCompleterTest extends GroovyTestCase {
+ @Test
void testRender() {
assert FileNameCompleter.render('foo') == 'foo'
assert FileNameCompleter.render('foo bar') == 'foo\\ bar'
@@ -29,6 +36,7 @@ class FileNameCompleterTest extends GroovyTestCase {
assert FileNameCompleter.render('foo \'\"bar') == 'foo\\ \\\'\\\"bar' + ''
}
+ @Test
void testCompletionNoFiles() {
// abusing junit testrule
TemporaryFolder testFolder = null;
@@ -53,13 +61,14 @@ class FileNameCompleterTest extends GroovyTestCase {
}
}
+ @Test
void testMatchFiles_Unix() {
- if(! System.getProperty('os.name').startsWith('Windows')) {
- FileNameCompleter completer = new FileNameCompleter()
- List<String> candidates = []
- int resultIndex = completer.matchFiles('foo/bar', '/foo/bar', [new File('/foo/baroo'), new File('/foo/barbee')] as File[], candidates)
- assert resultIndex == 'foo/'.length()
- assert candidates == ['baroo ', 'barbee ']
- }
+ assumeFalse('Test requires unix like system.', System.getProperty('os.name').startsWith('Windows'))
+
+ FileNameCompleter completer = new FileNameCompleter()
+ List<String> candidates = []
+ int resultIndex = completer.matchFiles('foo/bar', '/foo/bar', [new File('/foo/baroo'), new File('/foo/barbee')] as File[], candidates)
+ assert resultIndex == 'foo/'.length()
+ assert candidates == ['baroo ', 'barbee ']
}
}