Module: Homebrew::TestBot::TestRunner Private

Defined in:
test_bot/test_runner.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Constant Summary collapse

TestRunnerTypes =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.type_alias do
  {
    setup:               T.nilable(Setup),
    tap_syntax:          T.nilable(TapSyntax),
    formulae_detect:     T.nilable(FormulaeDetect),
    formulae:            T.nilable(Formulae),
    formulae_dependents: T.nilable(FormulaeDependents),
    cleanup_before:      T.nilable(CleanupBefore),
    cleanup_after:       T.nilable(CleanupAfter),
    bottles_fetch:       T.nilable(BottlesFetch),
  }
end

Class Method Summary collapse

Class Method Details

.run!(tap, git:, args:) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


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
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'test_bot/test_runner.rb', line 35

def run!(tap, git:, args:)
  tests = T.let([], T::Array[Test])
  skip_setup = args.skip_setup?
  skip_cleanup_before = T.let(false, T::Boolean)

  bottle_output_path = Pathname.new("bottle_output.txt")
  linkage_output_path = Pathname.new("linkage_output.txt")
  skipped_or_failed_formulae_output_path = Pathname.new("skipped_or_failed_formulae-#{Utils::Bottles.tag}.txt")
  @skipped_or_failed_formulae_output_path = T.let(skipped_or_failed_formulae_output_path,
                                                  T.nilable(Pathname))

  if no_only_args?(args) || args.only_formulae?
    ensure_blank_file_exists!(bottle_output_path)
    ensure_blank_file_exists!(linkage_output_path)
    ensure_blank_file_exists!(skipped_or_failed_formulae_output_path)
  end

  output_paths = {
    bottle:                     bottle_output_path,
    linkage:                    linkage_output_path,
    skipped_or_failed_formulae: skipped_or_failed_formulae_output_path,
  }

  test_bot_args = args.named.dup

  # With no arguments just build the most recent commit.
  test_bot_args << "HEAD" if test_bot_args.empty?

  test_bot_args.each do |argument|
    skip_cleanup_after = argument != test_bot_args.last
    current_tests = build_tests(argument, tap:,
                                          git:,
                                          output_paths:,
                                          skip_setup:,
                                          skip_cleanup_before:,
                                          skip_cleanup_after:,
                                          args:)
    skip_setup = true
    skip_cleanup_before = true
    tests += current_tests.values.compact
    run_tests(current_tests, args:)
  end

  failed_steps = tests.map(&:failed_steps)
                      .flatten
                      .compact
  ignored_steps = tests.map(&:ignored_steps)
                       .flatten
                       .compact
  steps_output = if failed_steps.blank? && ignored_steps.blank?
    "All steps passed!"
  else
    output_lines = []

    if ignored_steps.present?
      output_lines += [
        "Warning: #{ignored_steps.count} failed step#{"s" if ignored_steps.count > 1} ignored!",
      ]
      output_lines += ignored_steps.map(&:command_trimmed)
    end

    if failed_steps.present?
      output_lines += ["Error: #{failed_steps.count} failed step#{"s" if failed_steps.count > 1}!"]
      output_lines += failed_steps.map(&:command_trimmed)
    end

    output_lines.join("\n")
  end
  puts steps_output

  steps_output_path = Pathname.new("steps_output.txt")
  steps_output_path.unlink if steps_output_path.exist?
  steps_output_path.write(steps_output)

  if args.junit? && (no_only_args?(args) || args.only_formulae? || args.only_formulae_dependents?)
    junit_filters = %w[audit test]
    junit = Junit.new(tests)
    junit.build(filters: junit_filters)
    junit.write("brew-test-bot.xml")
  end

  failed_steps.empty?
end