Class: TestRunner::TestList

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

Instance Method Summary collapse

Instance Method Details

#allArray<Test>

Return a list of all known tests

Returns:



7
8
9
# File 'lib/test-runner/test_list.rb', line 7

def all
  parse_many(extract)
end

#by_path(path) ⇒ Test

Return one test specified by path

Returns:



20
21
22
# File 'lib/test-runner/test_list.rb', line 20

def by_path(path)
  parse_one(path, extract(path: path))
end

#create_test(path, data) ⇒ Object (protected)



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/test-runner/test_list.rb', line 56

def create_test(path, data)
  Test.new(
    path: path.to_s,
    type: data[:type],
    template: data[:template],
    args: data[:args],
    name: data[:name],
    description: data[:description],
    expect_failure: data[:expectFailure],
  )
end

#extract(path: nil) ⇒ Object (protected)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/test-runner/test_list.rb', line 25

def extract(path: nil)
  cmd = [
    'nix-instantiate',
    '--eval',
    '--json',
    '--strict',
    '--read-write-mode',
  ]

  cmd << '--attr' << "\\\"#{path}\\\"" if path
  cmd << 'tests/list-tests.nix'

  json = `#{cmd.join(' ')}`

  if $?.exitstatus != 0
    fail "nix-instantiate failed with exit status #{$?.exitstatus}"
  end

  json
end

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

Filter through all tests, return those that the filter matched

Yield Parameters:

Returns:



14
15
16
# File 'lib/test-runner/test_list.rb', line 14

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

#parse_many(json) ⇒ Object (protected)



46
47
48
49
50
# File 'lib/test-runner/test_list.rb', line 46

def parse_many(json)
  JSON.parse(json, symbolize_names: true).map do |name, opts|
    create_test(name, opts)
  end
end

#parse_one(path, json) ⇒ Object (protected)



52
53
54
# File 'lib/test-runner/test_list.rb', line 52

def parse_one(path, json)
  create_test(path, JSON.parse(json, symbolize_names: true))
end