Example #1
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();
  }
Example #2
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);
      }
    }
  }