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:



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

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

Instance Attribute Details

#testTest (readonly)

Returns:



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

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



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

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

#buildObject



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

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)



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

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