<commit_before>require 'builder'
require 'nokogiri'

module Barthes
	class Reporter
		class JunitXml
			def initialize
				@xml = Builder::XmlMarkup.new
				@xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
			end

			def after_run(features)
				result = @xml.testsuites do |xml|
					features.each do |feature|
						walk_json(feature)
					end
				end
				puts Nokogiri::XML(result).to_xml(indent: 2)
			end

			def walk_json(json, parents=[]) 
				case json.first
				when 'feature', 'scenario'
					if json.last.class == Array
						@xml.testsuite(name: json[1], tests: json.last.size) do
							parents.push json[1]
							json.last.each do |child|
								walk_json(child, parents)
							end
							parents.pop
						end
					end
				when 'action'
					@xml.testsuite(name: json[1], tests: 1) do
						name = [parents, "##{json.last['number'].to_s} #{json[1]}"].join('.')
						@xml.testcase(name: name) do
							case json.last['status']
							when 'skipped'
								@xml.skipped
							when 'failure'
							when 'error'
							end
							if json.last['status'] != 'skipped' && json.last['request'] && json.last['response']
								stdout = "request:\n"
								stdout += "#{JSON.pretty_generate(json.last['request'])}\n"
								stdout += "response:\n"
								stdout += "#{JSON.pretty_generate(json.last['response'])}\n"
								@xml.tag!(:'system-out', stdout)
							end
						end
					end
				else
					puts json
				end
			end
<commit_msg>update junit xml reporter<commit_after>require 'builder'
require 'nokogiri'

module Barthes
	class Reporter
		class JunitXml
			def initialize
				@xml = Builder::XmlMarkup.new
				@xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
			end

			def after_run(features)
				result = @xml.testsuites do |xml|
					features.each do |feature|
						walk_json(feature)
					end
				end
				puts Nokogiri::XML(result).to_xml(indent: 2)
			end

			def walk_json(json, parents=[]) 
				case json.first
				when 'feature', 'scenario'
					if json.last.class == Array
						@xml.testsuite(name: json[1], tests: json.last.size) do
							parents.push json[1]
							json.last.each do |child|
								walk_json(child, parents)
							end
							parents.pop
						end
					end
				when 'action'
					name = [parents, "##{json.last['number'].to_s} #{json[1]}"].join('.')
					@xml.testcase(name: name) do
						case json.last['status']
						when 'skipped'
							@xml.skipped
						when 'failure'
						when 'error'
						end
						if json.last['status'] != 'skipped' && json.last['request'] && json.last['response']
							stdout = "request:\n"
							stdout += "#{JSON.pretty_generate(json.last['request'])}\n"
							stdout += "response:\n"
							stdout += "#{JSON.pretty_generate(json.last['response'])}\n"
							@xml.tag!(:'system-out', stdout)
						end
					end
				else
					puts json
				end
			end

{'fraction_non_alphanumeric': 0.1505413901501921, 'fraction_numerical': 0.005588543485853999, 'mean_word_length': 2.4715151515151517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6698490', 'n_tokens_mistral': 1386, 'n_tokens_neox': 966, 'n_words': 215}