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

Support serialization tests when generating ci.json #100

Merged
merged 2 commits into from
Jul 31, 2023
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
29 changes: 25 additions & 4 deletions aggregate/convert_to_json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,27 @@ def add_fails(first, *seconds)
end

def add_kst_adoption(tests, log_dir)
kst_tests = File.readlines("#{log_dir}/kst_adoption.log")
kst_tests = File.readlines("#{log_dir}/kst_adoption.log").map { |name| name.chomp }
kst_test_used = {}
kst_tests.each { |name| kst_test_used[name] = false }
tests.each_pair { |name, test_result|
kst_name = nil
if kst_test_used.has_key?(name)
kst_name = name
elsif name =~ /^(.+?)\./ && kst_test_used.has_key?($1)
kst_name = $1
end

if kst_name
test_result['is_kst'] = true
kst_test_used[kst_name] = true
end
}
kst_tests.each { |name|
name.chomp!
tests[name] ||= {}
tests[name]['is_kst'] = true
if !kst_test_used.fetch(name)
tests[name] ||= {}
tests[name]['is_kst'] = true
end
}
tests
end
Expand Down Expand Up @@ -101,6 +117,11 @@ when 'php', 'python', 'construct'
JUnitXMLParser.new(infile).to_h,
infile
)
when 'python-write'
add_kst_adoption(
JUnitXMLParser.new(infile, true).to_h,
infile
)
when 'ruby'
add_kst_adoption(
RSpecJSONParser.new("#{infile}/test-output-ruby.json").to_h,
Expand Down
18 changes: 14 additions & 4 deletions aggregate/junit_xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'rexml/document'

class JUnitXMLParser < TestParser
def initialize(fn)
def initialize(fn, include_classname = false)
@include_classname = include_classname
@docs = if not File.exists?(fn)
[]
elsif File.directory?(fn)
Expand Down Expand Up @@ -35,10 +36,19 @@ def each_test
name = underscore_to_ucamelcase($1)
else
raise "Unable to parse name: \"#{name}\"" unless name =~ /^[Tt]est(.*?)$/
if $1[0] == '_'
name = underscore_to_ucamelcase($1)
name = $1
if @include_classname
classname = tc.attribute('classname').value
raise "Unable to parse classname: \"#{classname}\"" unless classname =~ /\.Test([^.]*)$/
classname = $1
if name[0] == '_'
name = underscore_to_lcamelcase(name[1..-1])
end
name = "#{classname}.#{name}"
else
name = $1
if name[0] == '_'
name = underscore_to_ucamelcase(name[1..-1])
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions aggregate/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def underscore_to_ucamelcase(s)
s.split(/_/).map { |x| x.capitalize }.join
end

def underscore_to_lcamelcase(s)
first_word, *rest_words = s.split(/_/)
([first_word] + rest_words.map { |x| x.capitalize }).join
end

class TestParser
def each_test
raise 'Abstract method'
Expand Down
7 changes: 5 additions & 2 deletions ci-python
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

. ./config

rm -rf "$TEST_OUT_DIR/python"
PYTHONPATH="$PYTHON_RUNTIME_DIR:compiled/python:spec/python/extra" python ./run-python-xml.py spec/python "$TEST_OUT_DIR/python"
rm -rf "$TEST_OUT_DIR/python" "$TEST_OUT_DIR/python-write"
PYTHONPATH="$PYTHON_RUNTIME_DIR:compiled/python:spec/python/extra" python ./run-python-xml.py spec/python/spec "$TEST_OUT_DIR/python"
PYTHONPATH="$PYTHON_RUNTIME_DIR:compiled/python:spec/python:spec/python/extra" python ./run-python-xml.py spec/python/specwrite "$TEST_OUT_DIR/python-write"

./kst-adoption-report python
./kst-adoption-report python-write
aggregate/convert_to_json python "$TEST_OUT_DIR/python" "$TEST_OUT_DIR/python/ci.json"
aggregate/convert_to_json python-write "$TEST_OUT_DIR/python-write" "$TEST_OUT_DIR/python-write/ci.json"
6 changes: 4 additions & 2 deletions kst-adoption-report
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def glob_spec_files(lang)
when 'php'
Dir.glob('spec/php/*Test.php')
when 'python'
Dir.glob('spec/python/**/test_*.py')
Dir.glob("spec/python/spec/test_*.py")
when 'python-write'
Dir.glob("spec/python/specwrite/test_*.py")
when 'construct'
Dir.glob('spec/construct/**/test_*.py')
when 'ruby'
Expand Down Expand Up @@ -68,7 +70,7 @@ def spec_file_to_test_name(lang, fn)
when 'php'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)Test\.php$/
$1
when 'python', 'construct'
when 'python', 'python-write', 'construct'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.py$/
underscore_to_ucamelcase($1)
when 'ruby'
Expand Down