Module: Inferno::Utils::ExecutionScriptRunner

Defined in:
lib/inferno/utils/execution_script_runner.rb

Class Method Summary collapse

Class Method Details

.determine_known_error_result(config, output) ⇒ Object



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

def self.determine_known_error_result(config, output)
  expected_file = File.join(File.dirname(config), "#{File.basename(config, '.yaml')}_expected.json")
  if (output.include?('"errors"') || output.include?('skipping comparison')) && !File.exist?(expected_file)
    puts '=> PASS (known-error script exited with 3 due to expected error before comparison)'
    :pass
  elsif output.include?('Actual results matched expected results? true')
    puts '=> PASS (known-error script exited with 3 and results matched expected)'
    :pass
  else
    puts '=> FAIL (exited with 3 but results did not match expected)'
    :fail
  end
end

.determine_result(config, return_code, output, allow_known_errors) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/inferno/utils/execution_script_runner.rb', line 49

def self.determine_result(config, return_code, output, allow_known_errors)
  known_error = allow_known_errors && File.basename(config, '.yaml').end_with?('_error')
  return determine_known_error_result(config, output) if known_error && !return_code.zero?
  return (:pass.tap { puts '=> PASS' }) if return_code.zero?

  puts "=> FAIL (exit code #{return_code})"
  :fail
end


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/inferno/utils/execution_script_runner.rb', line 72

def self.print_summary(passed, failed)
  puts '=' * 60
  puts "Results: #{passed.length} passed, #{failed.length} failed"
  puts '=' * 60

  if passed.any?
    puts 'Passed:'
    passed.each { |s| puts "  #{s}" }
  end

  return unless failed.any?

  puts 'Failed:'
  failed.each { |s| puts "  #{s}" }
  exit 1
end

.run_all(pattern: 'execution_scripts/**/*.yaml', inferno_base_url: nil, allow_known_errors: false) ⇒ Object



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
# File 'lib/inferno/utils/execution_script_runner.rb', line 6

def self.run_all(pattern: 'execution_scripts/**/*.yaml', inferno_base_url: nil, allow_known_errors: false)
  scripts = Dir.glob(pattern)

  if scripts.empty?
    warn "No scripts found matching: #{pattern}"
    exit 1
  end

  puts "Found #{scripts.length} script(s) to run.\n\n"

  passed = []
  failed = []

  scripts.each do |config|
    unless config.end_with?('.yaml', '.yml')
      warn "Skipping non-YAML file: #{config}"
      next
    end

    result = run_script(config, inferno_base_url:, allow_known_errors:)
    (result == :pass ? passed : failed) << config

    puts
  end

  print_summary(passed, failed)
end

.run_script(config, inferno_base_url:, allow_known_errors:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/inferno/utils/execution_script_runner.rb', line 34

def self.run_script(config, inferno_base_url:, allow_known_errors:)
  puts '=' * 60
  puts "Running: #{config}"
  puts '=' * 60

  allow_commands = File.basename(config, '.yaml').include?('_with_commands')
  cmd = ['bundle', 'exec', 'inferno', 'execute_script', config]
  cmd += ['--inferno-base-url', inferno_base_url] if inferno_base_url
  cmd += ['--allow-commands'] if allow_commands
  output, status = Open3.capture2e(*cmd)
  puts output

  determine_result(config, status.exitstatus, output, allow_known_errors)
end