File: helper.rb

package info (click to toggle)
ruby-mini-portile2 2.8.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: ruby: 1,834; ansic: 38; sh: 8; makefile: 4
file content (87 lines) | stat: -rw-r--r-- 1,736 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
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
require 'minitest/autorun'
require 'minitest/unit'
require 'minitest/spec'
require 'minitest/hooks/test'
require 'webrick'
require 'fileutils'
require 'zlib'
require 'minitar'
require 'fileutils'
require 'erb'
require 'mini_portile2'
require 'logger'

puts "#{__FILE__}:#{__LINE__}: relevant RbConfig::CONFIG values:"
%w[target_os target_cpu CC CXX].each do |key|
  puts "- #{key}: #{RbConfig::CONFIG[key].inspect}"
end

class TestCase < Minitest::Test
  include Minitest::Hooks

  HTTP_PORT = 23523

  attr_accessor :webrick

  def start_webrick(path)
    @webrick = WEBrick::HTTPServer.new(
      :Port => HTTP_PORT,
      :DocumentRoot => path,
      :Logger => Logger.new(File::NULL),
      :AccessLog => [],
    ).tap do |w|
      Thread.new do
        w.start
      end
      until w.status==:Running
        sleep 0.1
      end
    end
  end

  def stop_webrick
    if w=@webrick
      w.shutdown
      until w.status==:Stop
        sleep 0.1
      end
    end
  end

  def create_tar(tar_path, assets_path, directory)
    FileUtils.mkdir_p(File.dirname(tar_path))
    Zlib::GzipWriter.open(tar_path) do |fdtgz|
      Dir.chdir(assets_path) do
        Minitar.pack(directory, fdtgz)
      end
    end
  end

  def work_dir(r=recipe)
    "tmp/#{r.host}/ports/#{r.name}/#{r.version}/#{r.name}-#{r.version}"
  end

  def with_custom_git_dir(dir)
    old = ENV['GIT_DIR']
    ENV['GIT_DIR'] = dir
    yield
  ensure
    ENV['GIT_DIR'] = old
  end

  def with_env(env)
    before = ENV.to_h.dup
    env.each { |k, v| ENV[k] = v }
    yield
  ensure
    ENV.replace(before)
  end

  def without_env(*keys, &blk)
    before = ENV.to_h.dup
    keys.flatten.each { |k| ENV.delete(k) }
    yield
  ensure
    ENV.replace(before)
  end
end