File: tc_logs.rb

package info (click to toggle)
collab-qa-tools 0.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,668 kB
  • ctags: 247
  • sloc: ruby: 3,432; makefile: 2
file content (50 lines) | stat: -rwxr-xr-x 1,475 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
#!/usr/bin/ruby -w

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'test/unit'
require 'collab-qa'

class LogsTest < Test::Unit::TestCase
  if File::directory?('test/source')
    SRCDIR = 'test/source'
    DSTDIR = 'test/dest'
  elsif File::directory?('source')
    SRCDIR = 'source'
    DSTDIR = 'dest'
  else
    raise 'source directory not found.'
  end

  def test_parser
    allok = true
    Dir.foreach(SRCDIR) do |f|
      next if f !~ /log$/
      next if ENV['SOURCE'] != nil and ENV['SOURCE'] != f
      puts "Checking #{f}"
      log = CollabQA::Log::new(SRCDIR + '/' + f)
      log.guess_failed
      log.extract_log
      str = log.to_s
      if File::exist?(DSTDIR + '/' + f.gsub(/log$/, 'output'))
        output = File::read(DSTDIR + '/' + f.gsub(/log$/, 'output'))
        if output != str
          File::open(DSTDIR + '/' + f.gsub(/log$/, 'output.new'), "w") do |fd|
            fd.print(str)
          end
          puts "Test failed for #{f}."
          puts "  Check: diff -u #{DSTDIR + '/' + f.gsub(/log$/, 'output')}{,.new}"
          puts "  Commit: mv -f #{DSTDIR + '/' + f.gsub(/log$/, 'output')}{.new,}"
          allok = false
        end
      else
        puts "Missing #{DSTDIR + '/' + f.gsub(/log$/, 'output')}. Writing it, but check manually!"
        File::open(DSTDIR + '/' + f.gsub(/log$/, 'output'), "w") do |fd|
          fd.print(str)
        end
        allok = false
      end
    end
    assert(allok)
  end
end