Class: Go::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/scripts/go/test.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



6
7
8
9
10
# File 'lib/scripts/go/test.rb', line 6

def description
  "    Run all test from all packages. Creates coverage.txt which concats all coverprofiles from go test.\n  MARKDOWN\nend\n"

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scripts/go/test.rb', line 13

def run
  go_test_package = env_fetch("GO_TEST_PACKAGE", ".")
  go_coverage_output = env_fetch("GO_COVERAGE_OUTPUT", "./coverage.txt")

  output = capture_command("sh", "-c", "go list #{go_test_package}/... | grep -v vendor")
  packages = output.split("\n")

  cover_output = ""

  packages.each do |package|
    output_file = Tempfile.new('go test')

    command("go", "test", "-v", "-race", "-coverprofile=#{output_file.path}", "-covermode=atomic", package)

    cover_output += output_file.read
    output_file.close
    output_file.unlink
  end

  File.write(go_coverage_output, cover_output)
end