예제 #1
0
  private void test_tags_withTagsAnd3Tags(
      final String fileNameWithoutExt, final String userTestName) throws Exception {
    // prepare
    final String filePath = PRETTY_NEW_DIR_LOCATION + fileNameWithoutExt + "." + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeTestCaseTableSection();
    TestCaseTable testCaseTable = modelFile.getTestCaseTable();

    RobotToken testName = new RobotToken();
    testName.setText(userTestName);
    TestCase test = new TestCase(testName);
    testCaseTable.addTest(test);
    TestCaseTags testTags = test.newTags();

    RobotToken tagOne = new RobotToken();
    tagOne.setText("tag1");
    RobotToken tagTwo = new RobotToken();
    tagTwo.setText("tag2");
    RobotToken tagThree = new RobotToken();
    tagThree.setText("tag3");
    testTags.addTag(tagOne);
    testTags.addTag(tagTwo);
    testTags.addTag(tagThree);

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(filePath, modelFile);
  }
예제 #2
0
  private void test_tagsDec_andComment(final String fileNameWithoutExt, final String userTestName)
      throws Exception {
    // prepare
    final String filePath = PRETTY_NEW_DIR_LOCATION + fileNameWithoutExt + "." + getExtension();
    final RobotFile modelFile = NewRobotFileTestHelper.getModelFileToModify("2.9");

    // test data prepare
    modelFile.includeTestCaseTableSection();
    TestCaseTable testCaseTable = modelFile.getTestCaseTable();

    RobotToken testName = new RobotToken();
    testName.setText(userTestName);
    TestCase test = new TestCase(testName);
    testCaseTable.addTest(test);
    TestCaseTags testTags = test.newTags();

    RobotToken cmTok1 = new RobotToken();
    cmTok1.setText("cm1");
    RobotToken cmTok2 = new RobotToken();
    cmTok2.setText("cm2");
    RobotToken cmTok3 = new RobotToken();
    cmTok3.setText("cm3");

    testTags.addCommentPart(cmTok1);
    testTags.addCommentPart(cmTok2);
    testTags.addCommentPart(cmTok3);

    // verify
    NewRobotFileTestHelper.assertNewModelTheSameAsInFile(filePath, modelFile);
  }
  @Override
  public void map(
      final RobotLine currentLine,
      final RobotToken rt,
      final ParsingState currentState,
      final RobotFile fileModel) {
    List<TestCase> testCases = fileModel.getTestCaseTable().getTestCases();
    TestCase testCase = testCases.get(testCases.size() - 1);

    List<TestCaseTags> tags = testCase.getTags();
    TestCaseTags testCaseTags = tags.get(tags.size() - 1);
    testCaseTags.addCommentPart(rt);
  }
예제 #4
0
 private List<? extends RobotExecutableRow<?>> collectTestCaseExeRowsForVariablesChecking(
     final TestCase testCase) {
   final List<RobotExecutableRow<?>> exeRows = newArrayList();
   final List<TestCaseSetup> setups = testCase.getSetups();
   if (!setups.isEmpty()) {
     exeRows.add(setups.get(0).asExecutableRow());
   }
   exeRows.addAll(testCase.getTestExecutionRows());
   final List<TestCaseTeardown> teardowns = testCase.getTeardowns();
   if (!teardowns.isEmpty()) {
     exeRows.add(teardowns.get(0).asExecutableRow());
   }
   return exeRows;
 }
예제 #5
0
  private void reportEmptyCases(final List<TestCase> cases) {
    for (final TestCase testCase : cases) {
      final RobotToken caseName = testCase.getTestName();

      if (!hasAnythingToExecute(testCase)) {
        final String name = caseName.getText();
        final RobotProblem problem =
            RobotProblem.causedBy(TestCasesProblem.EMPTY_CASE).formatMessageWith(name);
        final Map<String, Object> arguments =
            ImmutableMap.<String, Object>of(AdditionalMarkerAttributes.NAME, name);
        reporter.handleProblem(problem, validationContext.getFile(), caseName, arguments);
      }
    }
  }
예제 #6
0
  private void reportEmptyNamesOfCases(final List<TestCase> cases) {
    for (final TestCase testCase : cases) {
      final RobotToken caseName = testCase.getName();
      if (caseName.getText().trim().isEmpty()) {
        final RobotProblem problem = RobotProblem.causedBy(TestCasesProblem.EMPTY_CASE_NAME);
        final int startOffset = caseName.getStartOffset();
        final int endOffset = caseName.getEndOffset();

        final ProblemPosition problemPosition =
            new ProblemPosition(
                caseName.getFilePosition().getLine(), Range.closed(startOffset, endOffset));
        reporter.handleProblem(problem, validationContext.getFile(), problemPosition);
      }
    }
  }
예제 #7
0
 private boolean hasAnythingToExecute(final TestCase testCase) {
   for (final RobotExecutableRow<?> robotExecutableRow : testCase.getTestExecutionRows()) {
     if (robotExecutableRow.isExecutable()) {
       return true;
     }
   }
   return false;
 }
예제 #8
0
  @Test
  public void
      test_givenTwoTestCasesInTsvFile_oneIsEmpty_andSecondIsJustVariableName_withEmptyExecute()
          throws Exception {
    // prepare
    final RobotRuntimeEnvironment runtime = mock(RobotRuntimeEnvironment.class);
    when(runtime.getVersion()).thenReturn("2.9");
    final RobotProjectHolder projectHolder = spy(RobotProjectHolder.class);
    when(projectHolder.getRobotRuntime()).thenReturn(runtime);

    final RobotParser parser =
        spy(RobotParser.create(projectHolder, RobotParserConfig.allImportsLazy()));

    //// prepare paths
    final File startFile =
        new File(this.getClass().getResource("parser/bugs/tsv_positionCheck.tsv").toURI());

    // execute
    final List<RobotFileOutput> output = parser.parse(startFile);

    // verify
    assertThat(output).hasSize(1);
    final RobotFileOutput file = output.get(0);
    final RobotFile robotModel = file.getFileModel();
    assertThatTestCaseTableIsIncluded(robotModel);
    final TestCaseTable testCaseTable = robotModel.getTestCaseTable();
    final List<TestCase> testCases = testCaseTable.getTestCases();
    assertThat(testCases).hasSize(2);
    final TestCase testCaseT3 = testCases.get(0);

    //// verify test case T3
    final RobotToken testCaseT3Name = testCaseT3.getName();
    assertThat(testCaseT3Name.getText()).isEqualTo("T3");
    assertThat(testCaseT3Name.getRaw()).isEqualTo("T3");
    final FilePosition tcT3Pos = testCaseT3Name.getFilePosition();
    assertThat(tcT3Pos.isSamePlace(new FilePosition(2, 0, 20))).as("got %s", tcT3Pos).isTrue();
    assertThat(testCaseT3.getExecutionContext()).isEmpty();

    //// verify test case ${x}
    final TestCase testCaseSpacesX = testCases.get(1);
    assertThat(testCaseSpacesX.getName().getText()).isEqualTo("${x}");
    assertThat(testCaseSpacesX.getName().getRaw()).isEqualTo("${x}");
    final FilePosition tcXPos = testCaseSpacesX.getName().getFilePosition();
    assertThat(tcXPos.isSamePlace(new FilePosition(3, 4, 28))).as("got %s", tcXPos).isTrue();
    final List<RobotExecutableRow<TestCase>> xTestExecutionList =
        testCaseSpacesX.getExecutionContext();
    assertThat(xTestExecutionList).hasSize(1);
    final IExecutableRowDescriptor<TestCase> xTestFirstLineDescription =
        xTestExecutionList.get(0).buildLineDescription();

    final RobotAction action = xTestFirstLineDescription.getAction();
    final RobotToken emptyAction = action.getToken();
    assertThat(emptyAction.getText()).isEmpty();
    assertThat(emptyAction.getRaw()).isEmpty();
    final FilePosition emptyActionPosition = emptyAction.getFilePosition();
    assertThat(emptyActionPosition.isSamePlace(new FilePosition(4, 5, 43)))
        .as("got %s", emptyActionPosition)
        .isTrue();
  }
예제 #9
0
 private void reportUnknownVariablesInTimeoutSetting(
     final TestCase testCase, final Set<String> variables) {
   final List<TestCaseTimeout> timeouts = testCase.getTimeouts();
   for (final TestCaseTimeout testCaseTimeout : timeouts) {
     final RobotToken timeoutToken = testCaseTimeout.getTimeout();
     if (timeoutToken != null) {
       validateTimeoutSetting(validationContext, reporter, variables, timeoutToken);
     }
   }
 }
예제 #10
0
  private void reportDuplicatedCases(final List<TestCase> cases) {
    final Set<String> duplicatedNames = newHashSet();

    for (final TestCase case1 : cases) {
      for (final TestCase case2 : cases) {
        if (case1 != case2) {
          final String case1Name = case1.getTestName().getText();
          final String case2Name = case2.getTestName().getText();

          if (case1Name.equalsIgnoreCase(case2Name)) {
            duplicatedNames.add(case1Name.toLowerCase());
          }
        }
      }
    }

    for (final TestCase testCase : cases) {
      final RobotToken caseName = testCase.getTestName();
      final String name = caseName.getText();

      if (duplicatedNames.contains(name.toLowerCase())) {
        final RobotProblem problem =
            RobotProblem.causedBy(TestCasesProblem.DUPLICATED_CASE).formatMessageWith(name);
        final Map<String, Object> additionalArguments =
            ImmutableMap.<String, Object>of("name", name);
        reporter.handleProblem(problem, validationContext.getFile(), caseName, additionalArguments);
      }
    }
  }
예제 #11
0
 private void reportUnknownVariablesInTagsSetting(
     final TestCase testCase, final Set<String> variables) {
   final List<TestCaseTags> tags = testCase.getTags();
   for (final TestCaseTags testCaseTags : tags) {
     final List<RobotToken> tagsTokens = testCaseTags.getTags();
     for (final RobotToken tagToken : tagsTokens) {
       final List<VariableDeclaration> variablesDeclarationsInTag =
           new VariableExtractor()
               .extract(tagToken, validationContext.getFile().getName())
               .getCorrectVariables();
       if (!variablesDeclarationsInTag.isEmpty()) {
         reportUnknownVariablesInSettingWithoutExeRows(
             validationContext, reporter, variablesDeclarationsInTag, variables);
       }
     }
   }
 }