Class: TestRunner::TestConfig

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test) ⇒ TestConfig

Returns a new instance of TestConfig.

Parameters:



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

def initialize(test)
  @test = test
  @config = {}
end

Instance Attribute Details

#testObject (readonly)

Returns the value of attribute test.



13
14
15
# File 'lib/test-runner/test_config.rb', line 13

def test
  @test
end

Class Method Details

.build(test) ⇒ Object

Parameters:



7
8
9
10
11
# File 'lib/test-runner/test_config.rb', line 7

def self.build(test)
  tc = new(test)
  tc.build
  tc
end

Instance Method Details

#[](key) ⇒ Object



42
43
44
# File 'lib/test-runner/test_config.rb', line 42

def [](key)
  @config[key]
end

#buildObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/test-runner/test_config.rb', line 21

def build
  cmd = [
    'nix-build',
    '--attr', 'json',
    '--out-link', config_path
  ]

  if test.template?
    cmd << '--argstr' << 'templateArgsInJson' << test.args.to_json
  end

  cmd << "./tests/suite/#{test.file_path}"

  FileUtils.mkdir_p('result/tests')
  pid = spawn(*cmd)
  Process.wait(pid)
  raise 'nix-build failed' if $?.exitstatus != 0

  @config = JSON.parse(File.read(config_path), symbolize_names: true)
end

#config_pathObject (protected)



48
49
50
# File 'lib/test-runner/test_config.rb', line 48

def config_path
  "result/tests/#{test.name}-config.json"
end