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:



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

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

Instance Attribute Details

#testTest (readonly)

Returns:



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

def test
  @test
end

Class Method Details

.build(test) ⇒ Object

Parameters:



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

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

Instance Method Details

#[](key) ⇒ Object



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

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

#buildObject



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

def build
  FileUtils.mkdir_p('result/tests')
  ref = ".#tests.#{nix_system}.\"#{nix_quote_attr(test.path)}\""

  cmd = [
    'nix', 'build',
    '--impure',
    '--out-link', config_path,
    ref
  ]

  pid = spawn(*cmd)
  Process.wait(pid)
  raise 'nix build failed' if $?.exitstatus != 0

  @config = JSON.parse(File.read(config_path))
end

#config_pathObject (protected)



67
68
69
# File 'lib/test-runner/test_config.rb', line 67

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

#nix_quote_attr(s) ⇒ Object (protected)



63
64
65
# File 'lib/test-runner/test_config.rb', line 63

def nix_quote_attr(s)
  s.to_s.gsub('\\', '\\\\').gsub('"', '\\"')
end

#nix_systemObject (protected)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/test-runner/test_config.rb', line 47

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