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 |
# File 'lib/res/parsers/android_junit.rb', line 20 def parse(output) 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_STATUS_CODE: (.*)$') case Regexp.last_match[1] when '1' # Skip if this is just the 'pre-run' test next when '0' test[:status] = 'passed' when '-2' test[:status] = 'failed' else test[:status] = 'unknown' end result.last[:children] << test 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 end end result end |