Module: WWTD

Defined in:
lib/wwtd.rb,
lib/wwtd/cli.rb,
lib/wwtd/run.rb,
lib/wwtd/ruby.rb,
lib/wwtd/version.rb

Defined Under Namespace

Modules: CLI, Ruby Classes: Run

Constant Summary collapse

CONFIG =
".travis.yml"
DEFAULT_GEMFILE =
"Gemfile"
COMBINATORS =
["rvm", "gemfile", "env"]
UNDERSTOOD =
COMBINATORS + ["matrix", "script", "bundler_args"]
VERSION =
"0.9.0"

Class Method Summary collapse

Class Method Details

.escaped_env(env, options = {}) ⇒ Object

internal api needs the export to work on ruby 1.9 / linux



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/wwtd.rb', line 57

def escaped_env(env, options={})
  return "" if env.empty?

  if options[:rerun] && gemfile = env["BUNDLE_GEMFILE"]
    env["BUNDLE_GEMFILE"] = gemfile.sub("#{Dir.pwd}/", "")
  end

  env = env.map { |k,v| "#{k}=#{Shellwords.escape(v)}" }
  if options[:rerun]
    env.join(" ") + " "
  else
    env.map { |e| "export #{e}" }.join(" && ") + " && "
  end
end

.read_travis_yml(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wwtd.rb', line 18

def read_travis_yml(options={})
  config = (File.exist?(CONFIG) ? YAML.load_file(CONFIG) : {})
  config.delete("source_key") # we don't need that we already have the source
  ignored = (config.keys - UNDERSTOOD) + Array(options[:ignore])

  calculate_local_ruby_matrix = (
    ignored.include?("rvm") &&
    Array(config["rvm"]).include?(RUBY_VERSION) &&
    config["matrix"]
  )

  ignored.each { |i| config.delete(i) unless i == "rvm" && calculate_local_ruby_matrix }
  matrix = matrix(config)

  if calculate_local_ruby_matrix
    matrix.delete_if { |m| m["rvm"] != RUBY_VERSION }
    matrix.each { |m| m.delete("rvm") }
  end

  [matrix, ignored]
end

.run(matrix, options, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wwtd.rb', line 40

def run(matrix, options, &block)
  with_clean_dot_bundle do
    with_clean_env do
      Dir.mktmpdir do |lock|
        in_multiple_threads(matrix.each_with_index, options[:parallel]) do |config, i|
          # set env as parallel_tests does to reuse existing infrastructure
          env = {}
          env["TEST_ENV_NUMBER"] = (i == 0 ? "" : (i + 1).to_s) if options[:parallel]
          Run.new(config, env, lock).execute(&block)
        end
      end
    end
  end
end