class ADBTestParser
Constants
- PREFIX_CLASS
- PREFIX_CODE
- PREFIX_STACK
- PREFIX_STREAM
- PREFIX_TEST
Attributes
test_results[RW]
Public Class Methods
new()
click to toggle source
# File lib/quokkadb/adb_test_parser.rb, line 15 def initialize clear @test_results = [] @lock = Mutex.new end
Public Instance Methods
clear()
click to toggle source
# File lib/quokkadb/adb_test_parser.rb, line 67 def clear @parsing_error = false @test_occurences = 0 @current_test = Test.new() @current_result = TestResult.new() end
early_abort(background_black)
click to toggle source
# File lib/quokkadb/adb_test_parser.rb, line 74 def early_abort(background_black) @current_result.original_test = @current_test @current_result.passed = false @test_results.push(@current_result) print_result(@current_result, background_black: background_black) clear puts("Testing ended abruptly.".red) puts("This is likely due to a background thread encountering an exception. Check logcat for details.".yellow) end
parse_line(line:, background_black: false)
click to toggle source
# File lib/quokkadb/adb_test_parser.rb, line 21 def parse_line(line:, background_black: false) @lock.synchronize do early_abort(background_black) if line.include?('Process crashed') # If starts with prefix, we are not parsing an error any more (if we were) @parsing_error = false if line.include?('INSTRUMENTATION_STATUS') if (@parsing_error) # if we have started with the stack trace continue with it if (@current_result.stack_trace) @current_result.stack_trace += "\n#{line.gsub("\n", '')}" else @current_result.failure_output += "\n#{line.gsub("\n", '')}" end return end if (line.include?('INSTRUMENTATION_STATUS: id=')) # if we have already started parsing a second block for the test, this # is a new test if (@test_occurences > 1) @current_result.original_test = @current_test @current_result.passed = @current_result.result_code == "0" @test_results.push(@current_result) print_result(@current_result, background_black: background_black) clear end @test_occurences += 1 elsif line.include?(PREFIX_TEST) @current_test.name = strip(line, PREFIX_TEST) elsif line.include?(PREFIX_CLASS) @current_test.class_name = strip(line, PREFIX_CLASS) elsif line.include?(PREFIX_CODE) @current_result.result_code = strip(line, PREFIX_CODE) elsif line.include?(PREFIX_STREAM) @parsing_error = true @current_result.failure_output += "#{strip(line, PREFIX_STREAM)}" elsif line.include?(PREFIX_STACK) @parsing_error = true @current_result.stack_trace = "#{strip(line, PREFIX_STACK)}" end end end
print_result(result, background_black: false)
click to toggle source
# File lib/quokkadb/adb_test_parser.rb, line 90 def print_result(result, background_black: false) class_name = result.original_test.class_name.split('.').last class_name = '%30.30s' % class_name print("#{class_name} ") passed_string = " #{result.passed ? "P" : "F"} ".black if (result.passed) passed_string = passed_string.on_green else passed_string = passed_string.on_red end print passed_string test_name_string = " #{result.original_test.name} ".yellow if (background_black) test_name_string = test_name_string.yellow.on_light_black end puts(test_name_string) if (!result.passed) result.failure_output.each_line do |line| print("#{'%30.30s' % ""} #{line}".red) end end end
strip(str, substring)
click to toggle source
# File lib/quokkadb/adb_test_parser.rb, line 86 def strip(str, substring) str.sub(substring, '').gsub("\n", '').gsub("\r", '') end