File: tc_textwrappedoutput.rb

package info (click to toggle)
ruby-feedparser 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 248 kB
  • ctags: 318
  • sloc: ruby: 3,009; sh: 24; makefile: 4
file content (48 lines) | stat: -rwxr-xr-x 1,571 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/ruby -w

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

require 'test/unit'
require 'feedparser'

class TextWrappedOutputTest < Test::Unit::TestCase
  if File::directory?('test/source')
    SRCDIR = 'test/source'
    DSTDIR = 'test/textwrapped_output'
  elsif File::directory?('source')
    SRCDIR = 'source'
    DSTDIR = 'textwrapped_output'
  else
    raise 'source directory not found.'
  end
  Dir.foreach(SRCDIR) do |f|
    next if f !~ /.xml$/
    testname = 'test_' + File.basename(f).gsub(/\W/, '_')
    define_method(testname) do
      str = File::read(SRCDIR + '/' + f)
      chan = FeedParser::Feed::new(str)
      chanstr = chan.to_text(false, 72) # localtime set to false
      if File::exist?(DSTDIR + '/' + f.gsub(/.xml$/, '.output'))
        output = File::read(DSTDIR + '/' + f.gsub(/.xml$/, '.output'))
        if output != chanstr
          File::open(DSTDIR + '/' + f.gsub(/.xml$/, '.output.new'), "w") do |fd|
            fd.print(chanstr)
          end
          assert(
            false,
            [
              "Test failed for #{f}.",
              "  Check: diff -u #{DSTDIR + '/' + f.gsub(/.xml$/, '.output')}{,.new}",
              "  Commit: mv -f #{DSTDIR + '/' + f.gsub(/.xml$/, '.output')}{.new,}",
            ].join("\n")
          )
        end
      else
        File::open(DSTDIR + '/' + f.gsub(/.xml$/, '.output'), "w") do |f|
          f.print(chanstr)
        end
        assert(false, "Missing #{DSTDIR + '/' + f.gsub(/.xml$/, '.output')}. Writing it, but check manually!")
      end
    end
  end
end