File: test-util.rb

package info (click to toggle)
gonzui 1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,824 kB
  • ctags: 1,448
  • sloc: ruby: 9,570; sh: 5,684; ansic: 1,334; lex: 1,140; makefile: 466; perl: 205; ml: 131
file content (104 lines) | stat: -rw-r--r-- 2,464 bytes parent folder | download | duplicates (4)
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
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
100
101
102
103
104
require 'gonzui'
require 'fileutils'
include FileUtils

def gnu_make?
  message = IO.popen("make --version").read
  /^GNU/.match(message)
end

module TestUtil
  FOO_FILES   = ["bar.c", "bar.h", "foo.c", "Makefile" ].sort
  FOO_C_FILES = FOO_FILES.find_all {|x| /\.[ch]$/.match(x) }
  FOO_SYMBOLS = ["bar", "foo", "main", "printf"]
  FOO_PACKAGE = "foo-0.1"
  FOO_TGZ     = File.join("foo", FOO_PACKAGE + ".tar.gz")

  @@make_options = if gnu_make?
                     "--quiet --no-print-directory"
                   else
                     ""
                   end

  def add_package(config)
    importer = Importer.new(config)
    url = URI.from_path(FOO_TGZ)
    importer.import(url)
    importer.finish
  end

  def make_db(config)
    remove_db(config)
    make_archives
    importer = Gonzui::Importer.new(config)
    url = URI.from_path(FOO_TGZ)
    importer.import(url)
    importer.finish
  end

  def remove_db(config)
    rm_rf(config.db_directory)
  end

  def make_dist_tree
    system("cd foo; make #{@@make_options} -f Makefile.foo dist-tree")
  end

  def make_clean
    system("cd foo; make #{@@make_options} -f Makefile.foo clean")
  end

  def make_archives
    Util.require_command("zip")
    Util.require_command("tar")
    Util.require_command("gzip")
    Util.require_command("bzip2")
    system("cd foo; make #{@@make_options} -f Makefile.foo dist")
    system("cd foo; make #{@@make_options} -f Makefile.foo dist-poor")
  end

  def cvsroot
    File.expand_path("tmp.cvsroot")
  end

  def make_cvs
    remove_cvs
    make_dist_tree
    assert(Util.command_exist?("cvs"))
    Dir.mkdir(cvsroot)
    system("cvs -d #{cvsroot} init")
    command_line = "cd foo/#{FOO_PACKAGE};"
    command_line << "cvs -Qd #{cvsroot} import -m '' foo gonzui-test test"
    system(command_line)
  end

  def remove_cvs
    FileUtils.rm_rf(cvsroot)
  end

  def svnroot
    File.expand_path("tmp.svnroot")
  end

  def make_svn
    remove_svn
    make_dist_tree
    assert(Util.command_exist?("svn"))
    assert(Util.command_exist?("svnadmin"))
    svnroot_uri = sprintf("file://%s", svnroot)
    Dir.mkdir(svnroot)
    system("svnadmin create #{svnroot}")
    command_line = "cd foo/#{FOO_PACKAGE};"
    command_line << "svn -q import -m '' #{svnroot_uri}"
    system(command_line)
    return svnroot_uri
  end

  def remove_svn
    FileUtils.rm_rf(svnroot)
  end
end

if ENV['MAKEFLAGS'] # be quiet in a make process.
  ARGV.unshift("--verbose=s")
end