Skip to content

Commit 80b8ef1

Browse files
committed
Dangerfile: highlight a testcase in a RobotFramework report.
Addressed to #537
1 parent 1a55765 commit 80b8ef1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Dangerfile

+27-3
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,34 @@ if File.file?(rf_report)
595595
end
596596
msg = node.text.sub(/\.$/, '')
597597
msg = msg.split(/\n/).delete_if {|el| el =~ /^(Build|System|Driver) info:/}.join("\n")
598-
file = suite['source'].sub(pwd, '')
599-
file = github.html_link(file)
598+
scenario_file = suite['source']
599+
file = scenario_file.sub(pwd, '')
600600
testcase = node.parent['name']
601-
# TODO: try to findout the test case and use it for highlighting line numbers
601+
602+
# locate the lines of a test case in a test suite
603+
from_line = -1
604+
to_line = -1
605+
current_line = 0
606+
File.readlines(scenario_file).each do |line|
607+
current_line += 1
608+
line.rstrip!
609+
610+
if line == testcase
611+
from_line = current_line
612+
next
613+
end
614+
615+
if from_line > 0 && line == ''
616+
to_line = current_line - 1
617+
break
618+
end
619+
end
620+
621+
line = ''
622+
if from_line > 0 && to_line > 0
623+
line = "#L#{from_line}-L#{to_line}"
624+
end
625+
file = github.html_link("#{file}#{line}")
602626
fail("robotframework-maven-plugin error in #{file}:\nTest case `#{testcase}` fails with message:\n#{msg}")
603627
end
604628
# TODO: add link to wiki page (#530)

0 commit comments

Comments
 (0)