Class: ASAutotest::OutputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/asautotest/compilation-output-parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, request, stopwatch, result) ⇒ OutputParser

Returns a new instance of OutputParser.



22
23
24
25
26
27
28
29
30
# File 'lib/asautotest/compilation-output-parser.rb', line 22

def initialize(output, request, stopwatch, result)
  @output = output
  @request = request
  @stopwatch = stopwatch
  @result = result

  @problematic_file_names = Set.new
  @n_problems = 0
end

Class Method Details

.parse(*arguments) ⇒ Object



32
33
34
# File 'lib/asautotest/compilation-output-parser.rb', line 32

def self.parse(*arguments)
  new(*arguments).run
end

Instance Method Details

#add_problem(file_name, problem) ⇒ Object



85
86
87
88
89
90
# File 'lib/asautotest/compilation-output-parser.rb', line 85

def add_problem(file_name, problem)
  @first_problem ||= problem
  @problematic_file_names << file_name
  @n_problems += 1
  @result.add_problem(file_name, problem)
end

#add_summaryObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/asautotest/compilation-output-parser.rb', line 92

def add_summary
  @result.add_summary \
    :request => @request,
    :successful? => @successful,
    :n_recompiled_files => @n_recompiled_files,
    :n_problematic_files => @problematic_file_names.size,
    :n_problems => @n_problems,
    :first_problem => @first_problem,
    :compilation_time => @stopwatch
end

#has_more_lines?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/asautotest/compilation-output-parser.rb', line 103

def has_more_lines?
  not @output.empty?
end

#parse_line(line) ⇒ Object



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
# File 'lib/asautotest/compilation-output-parser.rb', line 51

def parse_line(line)
  case line
  when /^Loading configuration file /
  when /^fcsh: Assigned (\d+) as the compile target id/
    @request.compile_id = $1
  when /^Recompile: /
  when /^Reason: /
  when /^\s*$/
  when /\(\d+ bytes\)$/
    @successful = true
  when /^Nothing has changed /
    @n_recompiled_files = 0
  when /^Files changed: (\d+) Files affected: (\d+)/
    @n_recompiled_files = $1.to_i + $2.to_i
  when /^(.*?)\((\d+)\): col: (\d+) (.*)/
    file_name = $1
    line_number = $2.to_i
    column_number = $3.to_i - 1
    message = $4
    source_line = read_lines(4)[1]

    location = Location[line_number, column_number, source_line]
    problem = Problem[message, location]

    add_problem(file_name, problem)
  when /^Error: (.*)/
    add_problem(nil, Problem[$1, nil])
  when /^(.*?): (.*)/
    add_problem($1, Problem[$2, nil])
  else
    @result.add_unrecognized_line(line)
  end
end

#parse_linesObject



41
42
43
44
45
46
47
48
49
# File 'lib/asautotest/compilation-output-parser.rb', line 41

def parse_lines
  @result.source_directories = @request.source_directories

  while has_more_lines?
    line = read_line
    puts ">> #{line}" if Logging.verbose?
    parse_line(line)
  end
end

#read_lineObject



111
112
113
# File 'lib/asautotest/compilation-output-parser.rb', line 111

def read_line
  @output.shift.chomp
end

#read_lines(n) ⇒ Object



107
108
109
# File 'lib/asautotest/compilation-output-parser.rb', line 107

def read_lines(n)
  @output.shift(n).map(&:chomp)
end

#runObject



36
37
38
39
# File 'lib/asautotest/compilation-output-parser.rb', line 36

def run
  parse_lines
  add_summary
end