RULEAPI-788 Allow multiple compliant solutions (#3034)
See https://discuss.sonarsource.com/t/layc-diff-view-validation/15392/7
This commit is contained in:
parent
aecbd213d7
commit
7f98f4246c
@ -129,28 +129,25 @@ class SourceLogger < Asciidoctor::Extensions::TreeProcessor
|
|||||||
blocks_per_id[id].push(block)
|
blocks_per_id[id].push(block)
|
||||||
end
|
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.
|
# Find blocks that break this rule.
|
||||||
blocks_per_id.each do |id, blocks|
|
blocks_per_id.each do |id, blocks|
|
||||||
# Sort to ensure deterministic output.
|
# Sort to ensure deterministic output.
|
||||||
blocks.sort_by! { |block| get_source_location(block) }
|
blocks.sort_by! { |block| get_source_location(block) }
|
||||||
|
|
||||||
case blocks.length
|
locs = blocks.map { |block| get_source_location(block) }.join(', ')
|
||||||
when 1
|
|
||||||
loc = get_source_location(blocks[0])
|
compliant = blocks.count { |block| block.attr('diff-type') == 'compliant' }
|
||||||
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] Incomplete example for diff-id=#{id}, missing counterpart for #{loc}")
|
if compliant == 0
|
||||||
when 2
|
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] diff-id=#{id} has zero compliant example: #{locs}")
|
||||||
type1 = blocks[0].attr('diff-type')
|
end
|
||||||
type2 = blocks[1].attr('diff-type')
|
|
||||||
if type1 == type2
|
noncompliant = blocks.count { |block| block.attr('diff-type') == 'noncompliant' }
|
||||||
loc1 = get_source_location(blocks[0])
|
if noncompliant != 1
|
||||||
loc2 = get_source_location(blocks[1])
|
message = noncompliant == 0 ? "zero noncompliant example" : "too many noncompliant examples"
|
||||||
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] Two #{type1} examples for diff-id=#{id}: #{loc1} and #{loc2}")
|
logger.info("ASCIIDOC LOGGER DIFF:[#{rule}] diff-id=#{id} has #{message}: #{locs}")
|
||||||
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}")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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-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-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/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] diff-id=1 has zero noncompliant example: .*/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] diff-id=2 has zero compliant example: .*/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] diff-id=3 has zero noncompliant example: .*/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" \
|
"\[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] 3 examples for diff-id=1: .*/rules/S200/rule.adoc:12, .*/rules/S200/rule.adoc:2, .*/rules/S200/rule.adoc:7" \
|
"\[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] Two noncompliant examples for diff-id=2: .*/rules/S200/rule.adoc:17 and .*/rules/S200/rule.adoc:22"
|
"\[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"
|
echo "All tests passed"
|
||||||
|
@ -13,3 +13,20 @@ noncompliant
|
|||||||
----
|
----
|
||||||
compliant
|
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
|
||||||
|
----
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user