Class: Res::Parsers::AndroidJunit
- Inherits:
-
Object
- Object
- Res::Parsers::AndroidJunit
- Defined in:
- lib/res/parsers/android_junit.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
Instance Method Summary collapse
-
#initialize(instrument_output) ⇒ AndroidJunit
constructor
A new instance of AndroidJunit.
- #parse(output) ⇒ Object
Constructor Details
#initialize(instrument_output) ⇒ AndroidJunit
Returns a new instance of AndroidJunit.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/res/parsers/android_junit.rb', line 8 def initialize(instrument_output) result = parse(instrument_output) ir = ::Res::IR.new( :type => 'AndroidJUnitRunner', :started => '', :finished => Time.now, :results => result ) @io = File.open('./instruments.res', 'w') @io.puts ir.json @io.close end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
6 7 8 |
# File 'lib/res/parsers/android_junit.rb', line 6 def io @io end |
Instance Method Details
#parse(output) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/res/parsers/android_junit.rb', line 20 def parse(output) test_complete = false total_tests = 0 passed = 0 failed = 0 class_name = [] result = [] test = { type: 'AndroidJUnit::Test', name: 'UNKNOWN', status: 'unknown' } File.open(output) do |f| f.each_line do |line| if !line.match('INSTRUMENTATION_RESULT') && !test_complete if line.match('INSTRUMENTATION_STATUS: numtests=(.*)$') total_tests = Regexp.last_match[1].to_i end if line.match('INSTRUMENTATION_STATUS_CODE: (.*)$') case Regexp.last_match[1].strip when '1' # Skip if this is just the 'pre-run' test next when '0' test[:status] = 'passed' passed += 1 when '-2' test[:status] = 'failed' when '-3' # Ignored (skipped) test test[:status] = 'ignored' else test[:status] = 'unknown' end result.last[:children] << test if test[:status] != 'ignored' test = { type: 'AndroidJUnit::Test', name: 'UNKNOWN', status: 'unknown' } end if line.include?('class=') line = line.gsub('INSTRUMENTATION_STATUS: class=', '').strip unless class_name.include? line class_name.push(line) result << { type: 'AndroidJUnit::Class', name: class_name.last, children: Array.new } end elsif line.include?('test=') test[:name] = line.gsub('INSTRUMENTATION_STATUS: test=', '').strip elsif line.include?('Error in ') test[:status] = 'failed' end else if line.match('Tests run: (.*), Failures: (.*)$') failed = Regexp.last_match[2].to_i if total_tests != (passed + failed) result << { type: 'AndroidJUnit::Exception', name: 'Exception(s): Check in logs for more info', status: 'failed' } end end test_complete = true end end end result end |