executetest_linuxsolaris.groovy

来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 58 行

GROOVY
58
字号
#! /usr/bin/env groovy 

import java.io.IOException

/**
 *  Test to ensure that the execute mechanism works fine on Linux and Solaris.  For these OSs we
 *  can effectively guarantee the existance of some programs that we can run.  Assume the search
 *  path is partway reasonable so we can access sh and echo.
 *
 *  <p>These test are a bit trivial but at least they are here :-)</p>
 *
 *  @author Russel Winder
 *  @version $Revision: 2618 $
 */
class ExecuteTest_LinuxSolaris extends GroovyTestCase {
  void testShellEchoOneArray ( ) {
    def process = ( [ "sh" , "-c" , "echo 1" ] as String[] ).execute ( )
    process.waitFor ( )
    assert process.in.getText ( ).trim ( ) == "1"
  }
  void testShellEchoOneList ( ) {
    def process = [ "sh" , "-c" , "echo 1" ].execute ( )
    process.waitFor ( )
    assert process.in.getText ( ).trim ( ) == "1"
  }
  void testEchoOneArray ( ) {
    try {
      def process = ( [ "echo 1" ] as String[] ).execute ( )
      process.waitFor ( )
       fail ( "Should have thrown java.io.IOException: echo 1: not found" )
    }
    catch ( IOException ioe ) { }
  }
  void testEchoOneList ( ) {
    try {
      def process = [ "echo 1" ].execute ( )
      process.waitFor ( )
       fail ( "Should have thrown java.io.IOException: echo 1: not found" )
    }
    catch ( IOException ioe ) { }
  }
  void testEchoOneScalar ( ) {
    def process = "echo 1".execute ( )
    process.waitFor ( )
    assert process.in.getText ( ).trim ( ) == "1"
  }
  void testEchoArray ( ) {
    def process = ( [ "echo" , "1" ] as String[] ).execute ( )
    process.waitFor ( )
    assert process.in.getText ( ).trim ( ) == "1"
   }
  void testEchoList ( ) {
    def process = [ "echo" , "1" ].execute ( )
    process.waitFor ( )
    assert process.in.getText ( ).trim ( ) == "1"
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?