/** @file
$ Id $
$ Date $
$ Author $
@ copy & copy ; Marc W & auml ; ckerlin
@ license LGPL , see file < a href = " license.html " > COPYING < / a >
$ Log $
Revision 1.6 2004 / 12 / 14 20 : 30 : 10 marc
added possibility to pass string to stdin of child process
Revision 1.5 2004 / 10 / 13 10 : 43 : 11 marc
test for bad exception specification
Revision 1.4 2004 / 08 / 28 16 : 21 : 25 marc
mrw - c + + - 0.92 ( mrw )
- new file : version . cpp
- new file header for all sources
- work around warning in mrw : : auto < T >
- possibility to compile without log4cxx
- work around bugs in demangle . h and libiberty . h
- corrections in documentation
- added simple tracing mechanism
- more warnings
- small corrections in Auto < > : : Free and a new test for it
- possibility to compile without stack trace
*/
# include <mrw/exec.hpp>
# include <mrw/stacktrace.hpp>
# include <cppunit/TestFixture.h>
# include <cppunit/ui/text/TestRunner.h>
# include <cppunit/extensions/HelperMacros.h>
# include <cppunit/extensions/TestFactoryRegistry.h>
# include <string>
class ExecTest : public CppUnit : : TestFixture {
public :
void lsTest ( ) {
std : : string res = ( mrw : : Cmd ( " /bin/ls " ) , " -l " , " .. " ) . execute ( ) ;
CPPUNIT_ASSERT ( res . find ( " COPYING " ) < res . size ( ) ) ;
}
void catTest ( ) {
std : : string res = mrw : : Cmd ( " /bin/cat " ) . execute ( " This is a test " ) ;
CPPUNIT_ASSERT ( res = = " This is a test " ) ;
}
void excTest ( ) {
std : : string res1 = ( mrw : : Cmd ( " /bin/false " ) ) . execute ( ) . result ( ) ;
std : : string res2 = ( mrw : : Cmd ( " /bin/false " ) ) . execute ( " " ) . result ( ) ;
}
void unexpectedExc ( ) throw ( std : : bad_exception ) {
std : : string res = ( mrw : : Cmd ( " /bin/false " ) ) . execute ( ) . result ( ) ;
}
CPPUNIT_TEST_SUITE ( ExecTest ) ;
CPPUNIT_TEST ( lsTest ) ;
CPPUNIT_TEST ( catTest ) ;
CPPUNIT_TEST_EXCEPTION ( excTest , mrw : : ExecutionFailedExc ) ;
CPPUNIT_TEST_EXCEPTION ( unexpectedExc , std : : bad_exception ) ;
CPPUNIT_TEST_SUITE_END ( ) ;
} ;
CPPUNIT_TEST_SUITE_REGISTRATION ( ExecTest ) ;
int main ( ) {
CppUnit : : TextUi : : TestRunner runner ;
runner . addTest ( CppUnit : : TestFactoryRegistry : : getRegistry ( ) . makeTest ( ) ) ;
return runner . run ( ) ? 0 : 1 ;
}