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:))
end

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



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

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)



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

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
    raise "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(&)
  all.select(&)
end

#parse_many(json) ⇒ Object (protected)



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

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)



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

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