From aa79aa83de43f9d0c12201c2354cf0ebce7dc9b0 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 31 Jul 2023 01:28:21 +0200 Subject: [PATCH 1/2] Support Python serialization tests when generating `ci.json` --- aggregate/convert_to_json | 29 +++++++++++++++++++++++++---- aggregate/junit_xml_parser.rb | 18 ++++++++++++++---- aggregate/test_parser.rb | 5 +++++ ci-python | 7 +++++-- kst-adoption-report | 6 ++++-- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/aggregate/convert_to_json b/aggregate/convert_to_json index 671878670..a39efc4da 100755 --- a/aggregate/convert_to_json +++ b/aggregate/convert_to_json @@ -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 @@ -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, diff --git a/aggregate/junit_xml_parser.rb b/aggregate/junit_xml_parser.rb index d97fbf867..c3420aa1a 100644 --- a/aggregate/junit_xml_parser.rb +++ b/aggregate/junit_xml_parser.rb @@ -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) @@ -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 diff --git a/aggregate/test_parser.rb b/aggregate/test_parser.rb index 0c7758e4c..017365b04 100644 --- a/aggregate/test_parser.rb +++ b/aggregate/test_parser.rb @@ -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' diff --git a/ci-python b/ci-python index a49287ada..1651929d7 100755 --- a/ci-python +++ b/ci-python @@ -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" diff --git a/kst-adoption-report b/kst-adoption-report index 571869ae0..30f1ce0e8 100755 --- a/kst-adoption-report +++ b/kst-adoption-report @@ -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' @@ -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' From cbcc4009832b52705b9a8afa7d6e3b3223be09c1 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 31 Jul 2023 15:11:36 +0200 Subject: [PATCH 2/2] Support Java serialization tests when generating `ci.json` --- aggregate/convert_to_json | 13 ++++--------- aggregate/junit_xml_parser.rb | 10 ++++------ aggregate/test_parser.rb | 5 ----- builder/java_builder.rb | 14 ++++++++------ ci-java | 6 +++++- kst-adoption-report | 6 ++++-- run-java | 2 +- spec/java/testng.xml | 6 +++++- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/aggregate/convert_to_json b/aggregate/convert_to_json index a39efc4da..9e7d3f36b 100755 --- a/aggregate/convert_to_json +++ b/aggregate/convert_to_json @@ -87,10 +87,10 @@ when 'cpp_stl' ), infile ) -when 'java' +when 'java', 'java-write' add_kst_adoption( add_fails( - JUnitXMLParser.new("#{infile}/junitreports").to_h, + JUnitXMLParser.new("#{infile}/junitreports", lang == 'java-write').to_h, BuildFailedParser.new("#{infile}/build_failed_tests.txt").to_h ), infile @@ -112,14 +112,9 @@ when 'javascript' JUnitXMLParser.new("#{infile}/test-output-javascript.xml").to_h, infile ) -when 'php', 'python', 'construct' +when 'php', 'python', 'python-write', 'construct' add_kst_adoption( - JUnitXMLParser.new(infile).to_h, - infile - ) -when 'python-write' - add_kst_adoption( - JUnitXMLParser.new(infile, true).to_h, + JUnitXMLParser.new(infile, lang == 'python-write').to_h, infile ) when 'ruby' diff --git a/aggregate/junit_xml_parser.rb b/aggregate/junit_xml_parser.rb index c3420aa1a..c16197363 100644 --- a/aggregate/junit_xml_parser.rb +++ b/aggregate/junit_xml_parser.rb @@ -37,18 +37,16 @@ def each_test else raise "Unable to parse name: \"#{name}\"" unless name =~ /^[Tt]est(.*?)$/ name = $1 + if name[0] == '_' + name = underscore_to_ucamelcase(name[1..-1]) + end + 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 - if name[0] == '_' - name = underscore_to_ucamelcase(name[1..-1]) - end end end diff --git a/aggregate/test_parser.rb b/aggregate/test_parser.rb index 017365b04..0c7758e4c 100644 --- a/aggregate/test_parser.rb +++ b/aggregate/test_parser.rb @@ -5,11 +5,6 @@ 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' diff --git a/builder/java_builder.rb b/builder/java_builder.rb index 987bd1436..a7285f92a 100644 --- a/builder/java_builder.rb +++ b/builder/java_builder.rb @@ -5,8 +5,11 @@ require_relative 'shellconfig' class JavaBuilder < PartialBuilder - def initialize - super + def initialize(suite_names, test_out_dir) + super() + + @suite_names = suite_names || 'spec,specwrite' + @test_out_dir = File.absolute_path(test_out_dir || "#{@config['TEST_OUT_DIR']}/java") @spec_dir = File.join('spec', 'java', 'src') @compiled_dir = File.join("#{@config['FORMATS_COMPILED_DIR']}", 'java') @@ -22,9 +25,6 @@ def initialize @java_classes_dir = "#{@compiled_dir}/bin" @java_classes_dir = File.absolute_path(@java_classes_dir) @java_classpath = [@java_classes_dir, @java_testng_jar].join(File::PATH_SEPARATOR) - - @test_out_dir = "#{@config['TEST_OUT_DIR']}/java" - @test_out_dir = File.absolute_path(@test_out_dir) end def list_mandatory_files @@ -92,7 +92,9 @@ def run_tests 'java', '-cp', @java_classpath, 'org.testng.TestNG', - '-d', @test_out_dir, File.absolute_path(File.join('spec', 'java', 'testng.xml')) + '-d', @test_out_dir, + '-testnames', @suite_names, + File.absolute_path(File.join('spec', 'java', 'testng.xml')) ] out_log = File.join(@test_out_dir, 'test_run.stdout') diff --git a/ci-java b/ci-java index 167f41f43..b84bce58e 100755 --- a/ci-java +++ b/ci-java @@ -2,7 +2,11 @@ . ./config -./run-java +rm -rf "$TEST_OUT_DIR/java" "$TEST_OUT_DIR/java-write" +./run-java spec "$TEST_OUT_DIR/java" +./run-java specwrite "$TEST_OUT_DIR/java-write" ./kst-adoption-report java +./kst-adoption-report java-write aggregate/convert_to_json java "$TEST_OUT_DIR/java" "$TEST_OUT_DIR/java/ci.json" +aggregate/convert_to_json java-write "$TEST_OUT_DIR/java-write" "$TEST_OUT_DIR/java-write/ci.json" diff --git a/kst-adoption-report b/kst-adoption-report index 30f1ce0e8..659f78f8d 100755 --- a/kst-adoption-report +++ b/kst-adoption-report @@ -17,7 +17,9 @@ def glob_spec_files(lang) when 'go' Dir.glob('spec/go/*_test.go') when 'java' - Dir.glob('spec/java/src/**/Test*.java') + Dir.glob('spec/java/src/**/spec/Test*.java') + when 'java-write' + Dir.glob('spec/java/src/**/specwrite/Test*.java') when 'javascript' Dir.glob('spec/javascript/test_*.js') when 'lua' @@ -52,7 +54,7 @@ def spec_file_to_test_name(lang, fn) when 'go' raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)_test\.go$/ underscore_to_ucamelcase($1) - when 'java' + when 'java', 'java-write' raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^Test(.*?)\.java$/ $1 when 'javascript' diff --git a/run-java b/run-java index e3434dd43..39581d264 100755 --- a/run-java +++ b/run-java @@ -1,4 +1,4 @@ #!/usr/bin/env ruby require_relative 'builder/java_builder' -JavaBuilder.new.command_line(ARGV) +JavaBuilder.new(ARGV[0], ARGV[1]).command_line(ARGV[2..-1] || []) diff --git a/spec/java/testng.xml b/spec/java/testng.xml index 44e9b2f8e..88accb107 100644 --- a/spec/java/testng.xml +++ b/spec/java/testng.xml @@ -1,8 +1,12 @@ - + + + + +