// depexpand_t.cxx #include #include #include #include using std::string; using std::cout; using std::endl; using std::ifstream; using std::ofstream; using std::istream; void msg(string txt) { cout << "--- "; cout << txt; cout << " ---" << endl; } void checkread(istream& out, string exp) { string pkg; assert( out.good() || out.eof() ); out >> pkg; assert( out.good() || out.eof() ); if ( pkg == exp ) { cout << "| " << pkg << endl; } else { cout << "| " << pkg << " != " << exp << endl; assert(false); } } int runcom(string command) { cout << command << endl; string fullcom = command; fullcom += " >out.dat; echo $? >stat.dat"; system(fullcom.c_str()); ifstream fin("stat.dat"); int stat; fin >> stat; return stat; } int depexpand_t() { msg("Create directories"); system("rm -rf dev"); system("mkdir -p dev/pkg10/spkg11"); system("mkdir -p dev/pkg10/spkg12"); system("mkdir -p dev/pkg10/spkg13"); system("mkdir -p dev/pkg10/spkg14"); system("mkdir -p dev/pkg10/spkg15"); system("mkdir -p dev/pkg20"); ofstream f11("dev/pkg10/spkg11/DEPS"); ofstream f12("dev/pkg10/spkg12/DEPS"); ofstream f13("dev/pkg10/spkg13/DEPS"); ofstream f14("dev/pkg10/spkg14/DEPS"); ofstream f15("dev/pkg10/spkg15/DEPS"); ofstream f20("dev/pkg20/DEPS"); f12 << "pkg10/spkg11" << endl; f13 << "pkg10/spkg12" << endl; f13 << "pkg20" << endl; f20 << "pkg10/spkg11" << endl; f20 << "pkg10/spkg12" << endl; f14 << "pkg10/spkg15" << endl; f15 << "pkg10/spkg14" << endl; msg("Expand spkg11"); assert( runcom("depexpand DEPS pkg10/spkg11 dev dev2") == 0 ); { ifstream fout("out.dat"); checkread(fout, "pkg10/spkg11"); checkread(fout, ""); } msg("Expand spkg12"); assert( runcom("depexpand DEPS pkg10/spkg12 dev dev2") == 0 ); { ifstream fout("out.dat"); checkread(fout, "pkg10/spkg11"); checkread(fout, "pkg10/spkg12"); checkread(fout, ""); } msg("Expand pkg20"); assert( runcom("depexpand DEPS pkg20 dev dev2") == 0 ); { ifstream fout("out.dat"); checkread(fout, "pkg10/spkg11"); checkread(fout, "pkg10/spkg12"); checkread(fout, "pkg20"); checkread(fout, ""); } msg("Expand spkg13"); assert( runcom("depexpand DEPS pkg10/spkg13 dev dev2") == 0 ); { ifstream fout("out.dat"); checkread(fout, "pkg10/spkg11"); checkread(fout, "pkg10/spkg12"); checkread(fout, "pkg20"); checkread(fout, "pkg10/spkg13"); checkread(fout, ""); } msg("Expand spkg14 (circular)"); assert( runcom("depexpand DEPS pkg10/spkg14 dev dev2") != 0 ); { ifstream fout("out.dat"); checkread(fout, ""); } return 0; } #ifdef CTEST_MAIN int main() { return depexpand_t(); } #endif