// ssystem_t.cxx #include "dataset_util/ssystem.h" #include #include using std::string; using std::cout; using std::endl; void msg(string msg) { cout << "----- "; cout << msg; cout << " -----" << endl; } int check(string com) { cout << "Command: " << com << endl; int rstat = ssystem(com); cout << "Return: " << rstat << endl; if ( rstat != 0 ) { cout << "System error " << errno << ": " << strerror(errno) << endl; } return rstat; } int ssystem_t() { string com = "date"; msg(com); assert( check(com) == 0 ); system("rm date.dat"); com += " > date.dat"; assert( check(com) == 0 ); com = "NoSuchCommand"; assert( check(com) != 0 ); msg("Date without env"); int sstat = ssystem("/bin/date", false); cout << "Status: " << errno << ": " << strerror(errno) << endl; assert( sstat == 0 ); msg("Set with env"); assert( ssystem("set", true) == 0 ); msg("Set without env"); assert( ssystem("set", false) == 0 ); msg("Exports without env"); assert( ssystem("export -p", false) == 0 ); msg("All tests passed."); return 0; } #ifdef CTEST_MAIN int main() { return ssystem_t(); } #endif