Skip to content

Commit

Permalink
#315: Use readable names for tags with needed coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Mar 11, 2022
1 parent c2933e6 commit dbe9b13
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
6 changes: 6 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.5.0] - 2022-03-??

### Updated

- Use readable names for imported tags with needed coverage [#315](https://github.com/itsallcode/openfasttrace/issues/315) / [PR #316](https://github.com/itsallcode/openfasttrace/pull/316)

## [3.4.0] - 2022-01-31

### Added
Expand Down
15 changes: 15 additions & 0 deletions doc/spec/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,21 @@ Covers:

Needs: impl, utest

#### Coverage Tag With Needed Coverage Generates Readable Names
`dsn~import.full-coverage-tag-with-needed-coverage-readable-names~1`

OFT generates readable names without hash code ID for tags with needed coverage.

Rationale:

When you need to cover these items it's important that the name is predictable and does not change e.g. when the file changes.

Covers:

* `req~import.full-coverage-tag-format~1`

Needs: impl, utest

#### Short Coverage Tag Format
`dsn~import.short-coverage-tag~1`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ public void processMatch(final Matcher matcher, final int lineNumber, final int
this.listener.beginSpecificationItem();
this.listener.setLocation(this.file.getPath(), lineNumber);
final SpecificationItemId coveredId = SpecificationItemId.parseId(matcher.group(2));
final String generatedName = generateName(coveredId, lineNumber, lineMatchCount);
final SpecificationItemId generatedId = SpecificationItemId.createId(matcher.group(1),
generatedName, 0);

final List<String> neededArtifactTypes = parseCommaSeparatedList(matcher.group(6));
final SpecificationItemId generatedId = generateItemId(lineNumber, lineMatchCount, coveredId, matcher.group(1),
neededArtifactTypes);

if (neededArtifactTypes.isEmpty())
{
Expand Down Expand Up @@ -111,7 +109,25 @@ private List<String> parseCommaSeparatedList(String input)
.collect(toList());
}

private String generateName(final SpecificationItemId coveredId, final int lineNumber,
private SpecificationItemId generateItemId(final int lineNumber, final int lineMatchCount,
final SpecificationItemId coveredId, String artifactType, List<String> neededArtifactTypes)
{
final String name = getItemName(lineNumber, lineMatchCount, coveredId, neededArtifactTypes);
return SpecificationItemId.createId(artifactType, name, 0);
}

// [impl->dsn~import.full-coverage-tag-with-needed-coverage-readable-names~1]
private String getItemName(final int lineNumber, final int lineMatchCount, final SpecificationItemId coveredId,
List<String> neededArtifactTypes)
{
if (neededArtifactTypes.isEmpty())
{
return generateUniqueName(coveredId, lineNumber, lineMatchCount);
}
return coveredId.getName();
}

private String generateUniqueName(final SpecificationItemId coveredId, final int lineNumber,
final int counter)
{
final String uniqueName = new StringBuilder() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,24 @@ void tagWithNewlineNotRecognized()
}

// [utest->dsn~import.full-coverage-tag-with-needed-coverage~1]
// [utest->dsn~import.full-coverage-tag-with-needed-coverage-readable-names~1]
@Test
void tagWithSingleRequiredCoverage()
{
assertItems("[" + COVERING_ARTIFACT_TYPE1 + "->" + ID1_TEXT + ">>" + NEEDED_COVERAGE1 + "]", //
item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1, List.of(NEEDED_COVERAGE1)));
itemWithReadableName(COVERING_ARTIFACT_TYPE1, 1, ID1, List.of(NEEDED_COVERAGE1)));
}

// [utest->dsn~import.full-coverage-tag-with-needed-coverage~1]
// [utest->dsn~import.full-coverage-tag-with-needed-coverage-readable-names~1]
@Test
void tagWithMultipleRequiredCoverage()
{
assertItems(
"[" + COVERING_ARTIFACT_TYPE1 + "->" + ID1_TEXT + ">>" + NEEDED_COVERAGE1 + "," + NEEDED_COVERAGE2
"[" + COVERING_ARTIFACT_TYPE1 + "->" + ID1_TEXT + ">>" + NEEDED_COVERAGE1 + ","
+ NEEDED_COVERAGE2
+ "]", //
item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1, List.of(NEEDED_COVERAGE1, NEEDED_COVERAGE2)));
itemWithReadableName(COVERING_ARTIFACT_TYPE1, 1, ID1, List.of(NEEDED_COVERAGE1, NEEDED_COVERAGE2)));
}

@Test
Expand All @@ -286,7 +289,13 @@ void tagWithMultipleRequiredCoverageWithSpaces()
assertItems(
"[ " + COVERING_ARTIFACT_TYPE1 + " -> " + ID1_TEXT + " >> " + NEEDED_COVERAGE1 + " , "
+ NEEDED_COVERAGE2 + " ]", //
item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1, List.of(NEEDED_COVERAGE1, NEEDED_COVERAGE2)));
itemWithReadableName(COVERING_ARTIFACT_TYPE1, 1, ID1, List.of(NEEDED_COVERAGE1, NEEDED_COVERAGE2)));
}

@Test
void requiredCoverageIndicatorWithMissingTagIgnored()
{
assertItems("[" + COVERING_ARTIFACT_TYPE1 + "->" + ID1_TEXT + ">>]");
}

@Test
Expand Down Expand Up @@ -316,6 +325,19 @@ private static SpecificationItem item(final String artifactType, final int lineN
return item(artifactType, lineNumber, counter, coveredId, emptyList());
}

private static SpecificationItem itemWithReadableName(final String artifactType, final int lineNumber,
final SpecificationItemId coveredId, List<String> neededArtifactTypes)
{
final SpecificationItemId generatedId = SpecificationItemId.createId(artifactType,
coveredId.getName(), 0);
final Builder itemBuilder = SpecificationItem.builder() //
.id(generatedId) //
.addCoveredId(coveredId) //
.location(FILENAME, lineNumber);
neededArtifactTypes.forEach(itemBuilder::addNeedsArtifactType);
return itemBuilder.build();
}

private static SpecificationItem item(final String artifactType, final int lineNumber,
final int counter, final SpecificationItemId coveredId, List<String> neededArtifactTypes)
{
Expand Down

0 comments on commit dbe9b13

Please sign in to comment.