protected final void copyRow(Parse row) {
   int nrOfCells = countCells(row);
   mTestLine.createParts(nrOfCells);
   int cellNr = 0;
   for (Parse cell = row.parts; cell != null; cell = cell.more) {
     mTestLine.setPart(cellNr++, cell.text());
   }
 }
 @Override
 public final void processFinished(Parse row, boolean anyErrors) {
   if (!anyErrors) {
     row.addToTag(" class=\"pass\"");
   } else {
     row.addToTag(" class=\"fail\"");
   }
 }
  protected final List<String> readSentence(Parse instructionNameCell) {
    String instructionName = instructionNameCell.text();
    Parse currentCell = instructionNameCell;

    final List<String> parts = new ArrayList<String>();
    parts.add("");
    boolean isAParameter = true;
    while ((currentCell = currentCell.more) != null) {
      final String text = currentCell.text();
      if (isAParameter) {
        parts.add(text);
        if (!instructionName.isEmpty()) {
          instructionName += " _";
        }
      } else if (!text.isEmpty()) {
        instructionName += " " + text;
      }
      isAParameter = !isAParameter;
    }
    parts.set(0, instructionName);
    return parts;
  }
  public TestResult runTest(TestDescriptor test) {
    if (!test.getContent().contains("<table")) {
      return new SingleTestResult(new Counts(), test.getName(), " contains no tables");
    }
    try {
      Parse tables = new Parse(test.getContent());
      FitLibraryServer fls = new FitLibraryServer();
      SimpleCounter pdl = new SimpleCounter();
      fls.fixtureListener = pdl;
      fls.doTables(tables);

      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      tables.print(pw);
      pw.flush();

      return new SingleTestResult(pdl.getCounts(), test.getName(), sw.getBuffer().toString());
    } catch (Exception e) {
      Counts c = new Counts();
      c.exceptions = 1;
      return new SingleTestResult(c, test.getName(), e.toString());
    }
  }
  public void doCell(Fixture fixture, Parse cell) {
    ContentOfTableCell content = new ContentOfTableCell(cell.text());
    try {
      if (content.isSymbolSetter()) {
        Object actual = this.adapter.get();
        dbfit.util.SymbolUtil.setSymbol(content.text(), actual);
        cell.addToBody(Fixture.gray("= " + String.valueOf(actual)));
        // fixture.ignore(cell);
      } else if (content.isSymbolGetter()) {
        Object actual = this.adapter.get();
        Object expected = this.adapter.parse(content.text());
        cell.addToBody(Fixture.gray("= " + String.valueOf(expected)));

        if (adapter.equals(actual, expected)) {
          fixture.right(cell);
        } else {
          fixture.wrong(cell, String.valueOf(actual));
        }
      } else if (content.isExpectingInequality()) {
        // expect failing comparison
        Object actual = this.adapter.get();
        String expectedVal = content.getExpectedFailureValue();
        cell.addToBody(Fixture.gray("= " + String.valueOf(actual)));

        if (adapter.equals(actual, adapter.parse(expectedVal))) {
          fixture.wrong(cell);
        } else {
          fixture.right(cell);
        }
      } else {
        super.doCell(fixture, cell);
      }
    } catch (Throwable t) {
      fixture.exception(cell, t);
    }
  }
 protected final void linkToLogFile(Parse cell) {
   cell.body =
       String.format("<A href=\"%s#id%s\">%s</A>", mLogFilePath, mReference.advance(), cell.body);
 }
示例#7
0
  @Override
  public void doRows(Parse rows) {
    if (args.length < 1 || args.length > 2) {
      exception(
          rows.parts,
          new Exception("Usage: !|SqlScript|data-source-name|[ignore errors: true|false]|"));
      return;
    }

    String dataSourceName = args[0];
    boolean ignoreErrors = false;
    List<Result> result = null;

    if (args.length == 2) {
      ignoreErrors = Boolean.parseBoolean(args[1]);
    }

    logger.info("SqlScript from data-source {}, ignore errors {}", dataSourceName, ignoreErrors);

    try {
      DataSourceInfo ds = dbUtil.getDataSource(dataSourceName);
      List<String> sqlCommands = new ArrayList<String>();

      logger.info("header: {}", rows.parts.text());
      Parse row = rows;

      while ((row = row.more) != null) {
        Parse column = row.parts;

        do {
          logger.info("sql: {}", column.text());
          sqlCommands.add(column.text());
        } while ((column = column.more) != null);
      }

      try {
        result = executeSql(ds, ignoreErrors, (String[]) sqlCommands.toArray(new String[0]));
      } catch (Throwable t) {
        logger.error("SqlScript", t);
        result = null;
        logger.error("calling exception t");
        exception(rows.parts, t);
        return;
      }

      if (result != null) {
        row = rows;
        int i = 0;

        while ((row = row.more) != null) {
          Parse column = row.parts;

          do {
            if (result.get(i).success) {
              right(column);
            } else if (result.get(i).error == null) {
              wrong(column);
            } else {
              exception(column, result.get(i).error);
            }
            ++i;
          } while ((column = column.more) != null);
        }
      }
    } catch (Throwable e) {
      logger.error("SqlScript", e);
      exception(rows, e);
    }
  }