Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RULEAPI-788 Allow multiple compliant solutions #3034

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions ci/asciidoc_validation/custom-asciidoctor
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,26 @@ class SourceLogger < Asciidoctor::Extensions::TreeProcessor
blocks_per_id[id].push(block)
end

# Each diff-id should have exactly 1 compliant and 1 noncompliant block.
# Each diff-id should have:
# * exactly 1 noncompliant block, and
# * 1 or more compliant blocks.
# Find blocks that break this rule.
blocks_per_id.each do |id, blocks|
# Sort to ensure deterministic output.
blocks.sort_by! { |block| get_source_location(block) }

case blocks.length
when 1
loc = get_source_location(blocks[0])
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] Incomplete example for diff-id=#{id}, missing counterpart for #{loc}")
when 2
type1 = blocks[0].attr('diff-type')
type2 = blocks[1].attr('diff-type')
if type1 == type2
loc1 = get_source_location(blocks[0])
loc2 = get_source_location(blocks[1])
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] Two #{type1} examples for diff-id=#{id}: #{loc1} and #{loc2}")
end
else
locs = blocks.map { |block| get_source_location(block) }
locs = locs.join(', ')
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] #{blocks.length} examples for diff-id=#{id}: #{locs}")
locs = blocks.map { |block| get_source_location(block) }
locs = locs.join(', ')
marco-antognini-sonarsource marked this conversation as resolved.
Show resolved Hide resolved

compliant = blocks.count { |block| block.attr('diff-type') == 'compliant' }
if compliant == 0
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] diff-id=#{id} has zero compliant example: #{locs}")
end

noncompliant = blocks.count { |block| block.attr('diff-type') == 'noncompliant' }
if noncompliant != 1
message = noncompliant == 0 ? "zero noncompliant example" : "too many noncompliant examples"
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] diff-id=#{id} has #{message}: #{locs}")
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions ci_tests/asciidoc_validation/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ run_test "test_diff_source" \
"\[S100/cfamily] diff-type is missing in .*/shared_content/cfamily/shared.adoc:3" \
"\[S100/cfamily] diff-id is missing in .*/shared_content/cfamily/shared.adoc:8" \
"\[S100/cfamily] diff-type 'shared' is not valid in .*/shared_content/cfamily/shared.adoc:13" \
"\[S100/java] Incomplete example for diff-id=1, missing counterpart for .*/rules/S100/java/rule.adoc:3" \
"\[S100/java] Incomplete example for diff-id=2, missing counterpart for .*/rules/S100/java/rule.adoc:8" \
"\[S100/java] Incomplete example for diff-id=3, missing counterpart for .*/shared_content/java/example.adoc:3" \
"\[S100/java] 3 examples for diff-id=4: .*/rules/S100/java/rule.adoc:15, .*/shared_content/java/example.adoc:13, .*/shared_content/java/example.adoc:8" \
"\[S200/default] 3 examples for diff-id=1: .*/rules/S200/rule.adoc:12, .*/rules/S200/rule.adoc:2, .*/rules/S200/rule.adoc:7" \
"\[S200/default] Two noncompliant examples for diff-id=2: .*/rules/S200/rule.adoc:17 and .*/rules/S200/rule.adoc:22"
"\[S100/java] diff-id=1 has zero noncompliant example: .*/rules/S100/java/rule.adoc:3" \
"\[S100/java] diff-id=2 has zero compliant example: .*/rules/S100/java/rule.adoc:8" \
"\[S100/java] diff-id=3 has zero noncompliant example: .*/shared_content/java/example.adoc:3" \
"\[S100/java] diff-id=4 has too many noncompliant examples: .*/rules/S100/java/rule.adoc:15, .*/shared_content/java/example.adoc:13, .*/shared_content/java/example.adoc:8" \
"\[S200/default] diff-id=1 has too many noncompliant examples: .*/rules/S200/rule.adoc:12, .*/rules/S200/rule.adoc:2, .*/rules/S200/rule.adoc:7" \
"\[S200/default] diff-id=2 has too many noncompliant examples: .*/rules/S200/rule.adoc:17, .*/rules/S200/rule.adoc:22" \
"\[S200/default] diff-id=2 has zero compliant example: .*/rules/S200/rule.adoc:17, .*/rules/S200/rule.adoc:22"

echo "All tests passed"
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@ noncompliant
----
compliant
----


[source,cpp,diff-id=2,diff-type=noncompliant]
----
noncompliant
----

[source,cpp,diff-id=2,diff-type=compliant]
----
compliant A
----

[source,cpp,diff-id=2,diff-type=compliant]
----
compliant B
----