Class: TestRunner::TestList
- Inherits:
-
Object
- Object
- TestRunner::TestList
- Defined in:
- lib/test-runner/test_list.rb
Instance Method Summary collapse
-
#all ⇒ Array<Test>
Return a list of all known tests.
-
#by_path(path) ⇒ Test
Return one test specified by path.
- #create_test(path, data) ⇒ Object protected
- #extract_all ⇒ Object protected
- #extract_one(path) ⇒ Object protected
-
#filter {|| ... } ⇒ Array<Test>
Filter through all tests, return those that the filter matched.
- #nix_quote_attr(s) ⇒ Object protected
- #nix_system ⇒ Object protected
- #parse_many(json) ⇒ Object protected
- #parse_one(path, json) ⇒ Object protected
Instance Method Details
#all ⇒ Array<Test>
Return a list of all known tests
8 9 10 |
# File 'lib/test-runner/test_list.rb', line 8 def all parse_many(extract_all) end |
#by_path(path) ⇒ Test
Return one test specified by path
21 22 23 |
# File 'lib/test-runner/test_list.rb', line 21 def by_path(path) parse_one(path, extract_one(path)) end |
#create_test(path, data) ⇒ Object (protected)
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/test-runner/test_list.rb', line 74 def create_test(path, data) Test.new( path: path, type: data['type'], template: data['template'], template_args: data['templateArgs'], test_args: data.fetch('testArgs', {}), name: data['name'], description: data['description'], attempts: data['attempts'], expect_failure: data['expectFailure'], tags: data['tags'], labels: data['labels'], test_scripts: data['testScripts'] ) end |
#extract_all ⇒ Object (protected)
47 48 49 50 51 52 53 |
# File 'lib/test-runner/test_list.rb', line 47 def extract_all cmd = ['nix', 'eval', '--json', '--impure', ".#testsMeta.#{nix_system}"] out, status = Open3.capture2(*cmd) raise "nix eval testsMeta failed (#{status.exitstatus})" unless status.success? out end |
#extract_one(path) ⇒ Object (protected)
55 56 57 58 59 60 61 62 |
# File 'lib/test-runner/test_list.rb', line 55 def extract_one(path) ref = ".#testsMeta.#{nix_system}.\"#{nix_quote_attr(path)}\"" cmd = ['nix', 'eval', '--json', '--impure', ref] out, status = Open3.capture2(*cmd) raise "nix eval testsMeta[#{path}] failed (#{status.exitstatus})" unless status.success? out end |
#filter {|| ... } ⇒ Array<Test>
Filter through all tests, return those that the filter matched
15 16 17 |
# File 'lib/test-runner/test_list.rb', line 15 def filter(&) all.select(&) end |
#nix_quote_attr(s) ⇒ Object (protected)
43 44 45 |
# File 'lib/test-runner/test_list.rb', line 43 def nix_quote_attr(s) s.to_s.gsub('\\', '\\\\').gsub('"', '\\"') end |
#nix_system ⇒ Object (protected)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/test-runner/test_list.rb', line 27 def nix_system @nix_system ||= begin out, status = Open3.capture2( 'nix', 'eval', '--raw', '--impure', '--expr', 'builtins.currentSystem' ) raise "nix eval builtins.currentSystem failed (#{status.exitstatus})" unless status.success? out.strip end end |
#parse_many(json) ⇒ Object (protected)
64 65 66 67 68 |
# File 'lib/test-runner/test_list.rb', line 64 def parse_many(json) JSON.parse(json).map do |name, opts| create_test(name, opts) end end |
#parse_one(path, json) ⇒ Object (protected)
70 71 72 |
# File 'lib/test-runner/test_list.rb', line 70 def parse_one(path, json) create_test(path, JSON.parse(json)) end |