coverage_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package integration_test
  2. import (
  3. "os"
  4. "os/exec"
  5. . "github.com/onsi/ginkgo"
  6. . "github.com/onsi/gomega"
  7. "github.com/onsi/gomega/gexec"
  8. )
  9. var _ = Describe("Coverage Specs", func() {
  10. AfterEach(func() {
  11. os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile")
  12. })
  13. It("runs coverage analysis in series and in parallel", func() {
  14. session := startGinkgo("./_fixtures/coverage_fixture", "-cover")
  15. Eventually(session).Should(gexec.Exit(0))
  16. output := session.Out.Contents()
  17. Ω(output).Should(ContainSubstring("coverage: 80.0% of statements"))
  18. serialCoverProfileOutput, err := exec.Command("go", "tool", "cover", "-func=./_fixtures/coverage_fixture/coverage_fixture.coverprofile").CombinedOutput()
  19. Ω(err).ShouldNot(HaveOccurred())
  20. os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile")
  21. Eventually(startGinkgo("./_fixtures/coverage_fixture", "-cover", "-nodes=4")).Should(gexec.Exit(0))
  22. parallelCoverProfileOutput, err := exec.Command("go", "tool", "cover", "-func=./_fixtures/coverage_fixture/coverage_fixture.coverprofile").CombinedOutput()
  23. Ω(err).ShouldNot(HaveOccurred())
  24. Ω(parallelCoverProfileOutput).Should(Equal(serialCoverProfileOutput))
  25. })
  26. It("runs coverage analysis on external packages in series and in parallel", func() {
  27. session := startGinkgo("./_fixtures/coverage_fixture", "-coverpkg=github.com/onsi/ginkgo/integration/_fixtures/coverage_fixture,github.com/onsi/ginkgo/integration/_fixtures/coverage_fixture/external_coverage_fixture")
  28. Eventually(session).Should(gexec.Exit(0))
  29. output := session.Out.Contents()
  30. Ω(output).Should(ContainSubstring("coverage: 71.4% of statements in github.com/onsi/ginkgo/integration/_fixtures/coverage_fixture, github.com/onsi/ginkgo/integration/_fixtures/coverage_fixture/external_coverage_fixture"))
  31. serialCoverProfileOutput, err := exec.Command("go", "tool", "cover", "-func=./_fixtures/coverage_fixture/coverage_fixture.coverprofile").CombinedOutput()
  32. Ω(err).ShouldNot(HaveOccurred())
  33. os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile")
  34. Eventually(startGinkgo("./_fixtures/coverage_fixture", "-coverpkg=github.com/onsi/ginkgo/integration/_fixtures/coverage_fixture,github.com/onsi/ginkgo/integration/_fixtures/coverage_fixture/external_coverage_fixture", "-nodes=4")).Should(gexec.Exit(0))
  35. parallelCoverProfileOutput, err := exec.Command("go", "tool", "cover", "-func=./_fixtures/coverage_fixture/coverage_fixture.coverprofile").CombinedOutput()
  36. Ω(err).ShouldNot(HaveOccurred())
  37. Ω(parallelCoverProfileOutput).Should(Equal(serialCoverProfileOutput))
  38. })
  39. })