Class: TestRunner::TestScriptList

Inherits:
Object
  • Object
show all
Defined in:
lib/test-runner/test_script_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) ⇒ TestScriptList

Returns a new instance of TestScriptList.



3
4
5
# File 'lib/test-runner/test_script_list.rb', line 3

def initialize(system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil)
  @test_list = TestList.new(system:, test_config_path:, repo_root:)
end

Instance Method Details

#all ⇒ Array<TestScript>

Return a list of all known test scripts

Returns:



9
10
11
# File 'lib/test-runner/test_script_list.rb', line 9

def all
  expand_scripts(@test_list.all)
end

#by_path(path) ⇒ TestScript

Return one test script specified by path

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/test-runner/test_script_list.rb', line 41

def by_path(path)
  test_path, script_name = path.split('#')

  test = @test_list.by_path(test_path)

  if script_name
    script = test.test_scripts[script_name]
    raise "Test #{test_path} does not have script ##{script_name}" if script.nil?

    script
  elsif test.test_scripts.length == 1
    test.test_scripts.first[1]
  else
    raise "Test #{test_path} has scripts #{test.test_scripts.each_key.map { |v| "##{v}" }.join(', ')}, choose one"
  end
end

#exact_path_pattern?(pattern) ⇒ Boolean (protected)

Returns:

  • (Boolean)


60
61
62
# File 'lib/test-runner/test_script_list.rb', line 60

def exact_path_pattern?(pattern)
  !pattern.nil? && !pattern.match?(/[*?\[{\]]/)
end

#expand_scripts(test_list) ⇒ Object (protected)



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/test-runner/test_script_list.rb', line 64

def expand_scripts(test_list)
  ret = []

  test_list.each do |test|
    test.test_scripts.each_value do |ts|
      ret << ts
    end
  end

  ret
end

#filter {|| ... } ⇒ Array<TestScript>

Filter through all test scripts, return those that the filter matched

Yield Parameters:

Returns:



16
17
18
# File 'lib/test-runner/test_script_list.rb', line 16

def filter(&)
  all.select(&)
end

#matching(pattern) ⇒ Array<TestScript>

Return scripts matching path pattern.

Exact paths can be resolved without evaluating metadata for the whole suite.

Parameters:

  • pattern (String, nil)

Returns:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/test-runner/test_script_list.rb', line 27

def matching(pattern)
  if exact_path_pattern?(pattern)
    begin
      [by_path(pattern)]
    rescue KeyError
      []
    end
  else
    filter { |ts| pattern.nil? || ts.path_matches?(pattern) }
  end
end