Exemplo n.º 1
0
void SQLUtility::execSQLFile(const std::string &sqlFile,
                             const std::string &ansFile) {
  // do precheck for sqlFile & ansFile
  if (StringUtil::StartWith(sqlFile, "/") ||
      StringUtil::StartWith(ansFile, "/"))
    ASSERT_TRUE(false) << "For sqlFile and ansFile, relative path to feature "
                          "test root dir is needed";
  std::string ansFileAbsPath = testRootPath + "/" + ansFile;
  if (!std::ifstream(ansFileAbsPath))
    ASSERT_TRUE(false) << ansFileAbsPath << " doesn't exist";
  FilePath fp = splitFilePath(ansFileAbsPath);
  // double check to avoid empty fileBaseName
  if (fp.fileBaseName.empty())
    ASSERT_TRUE(false) << ansFileAbsPath << " is invalid";

  // generate new sql file with set search_path added at the begining
  const std::string newSqlFile = generateSQLFile(sqlFile);

  // outFile is located in the same folder with ansFile
  std::string outFileAbsPath = fp.path + "/" + fp.fileBaseName + ".out";
  conn->setOutputFile(outFileAbsPath);
  EXPECT_EQ(conn->runSQLFile(newSqlFile).getLastStatus(), 0);
  conn->resetOutput();
  EXPECT_FALSE(conn->checkDiff(ansFileAbsPath, outFileAbsPath, true));
  if (conn->checkDiff(ansFileAbsPath, outFileAbsPath, true) == false) {
    // no diff, continue to delete the generated sql file
    if (remove(newSqlFile.c_str()))
      ASSERT_TRUE(false) << "Error deleting file " << newSqlFile;
  } else {
    EXPECT_FALSE(true);
  }
}
Exemplo n.º 2
0
bool SQLUtility::execSQLFile(const string &sqlFile) {
    // do precheck for sqlFile
    if (hawq::test::startsWith(sqlFile, "/"))
        return false;

    // double check to avoid empty fileBaseName
    FilePath fp = splitFilePath(sqlFile);
    if (fp.fileBaseName.empty())
        return false;

    // outFile is located in the same folder with ansFile
    string outFileAbsPath = "/tmp/" + fp.fileBaseName + ".out";

    // generate new sql file with set search_path added at the begining
    const string newSqlFile = generateSQLFile(sqlFile);

    // run sql file and store its result in output file
    conn->setOutputFile(outFileAbsPath);
    return conn->runSQLFile(newSqlFile).getLastStatus() == 0 ? true : false;
}