• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 18822648545

26 Oct 2025 07:24PM UTC coverage: 79.831% (-0.4%) from 80.28%
18822648545

Pull #22809

github

web-flow
Merge 9401c4830 into 170094e99
Pull Request #22809: golang: fix Go SDK version check for coverage experiment

0 of 1 new or added line in 1 file covered. (0.0%)

439 existing lines in 25 files now uncovered.

77436 of 97000 relevant lines covered (79.83%)

3.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/python/pants/backend/go/goals/run_binary_integration_test.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
import os
1✔
7
from textwrap import dedent
1✔
8
from typing import cast
1✔
9

10
from pants.backend.go.testutil import gen_module_gomodproxy
1✔
11
from pants.testutil.pants_integration_test import run_pants, setup_tmpdir
1✔
12

13

14
def test_run_binary() -> None:
1✔
15
    sources = {
1✔
16
        "go.mod": dedent(
17
            """\
18
                module foo.example.com
19
                go 1.17
20
                """
21
        ),
22
        "main.go": dedent(
23
            """\
24
                package main
25

26
                import (
27
                    "fmt"
28
                    "os"
29
                )
30

31
                func main() {{
32
                    fmt.Println("Hello world!")
33
                    fmt.Fprintln(os.Stderr, "Hola mundo!")
34
                    os.Exit(23)
35
                }}
36
                """
37
        ),
38
        "BUILD": dedent(
39
            """\
40
                go_mod(name='mod')
41
                go_package(name='pkg')
42
                go_binary(name='bin')
43
                """
44
        ),
45
    }
46

47
    with setup_tmpdir(sources) as tmpdir:
1✔
48
        result = run_pants(
1✔
49
            [
50
                "--backend-packages=pants.backend.experimental.go",
51
                "--pants-ignore=__pycache__",
52
                "run",
53
                f"{tmpdir}:bin",
54
            ]
55
        )
56

57
    assert "Hola mundo!\n" in result.stderr
1✔
UNCOV
58
    assert result.stdout == "Hello world!\n"
×
UNCOV
59
    assert result.exit_code == 23
×
60

61

62
def test_run_binary_third_party() -> None:
1✔
63
    import_path = "pantsbuild.org/go-sample-for-test"
1✔
64
    version = "v0.0.1"
1✔
65

66
    fake_gomod = gen_module_gomodproxy(
1✔
67
        version,
68
        import_path,
69
        (
70
            (
71
                "pkg/hello/hello.go",
72
                dedent(
73
                    """\
74
        package hello
75
        import "fmt"
76

77

78
        func Hello() {
79
            fmt.Println("Hello world!")
80
        }
81
        """
82
                ),
83
            ),
84
            (
85
                "cmd/hello/main.go",
86
                dedent(
87
                    """\
88
        package main
89
        import "pantsbuild.org/go-sample-for-test/pkg/hello"
90

91

92
        func main() {
93
            hello.Hello()
94
        }
95
        """
96
                ),
97
            ),
98
        ),
99
    )
100

101
    fake_gomod.update(
1✔
102
        {
103
            "BUILD": dedent(
104
                f"""\
105
                go_mod(name='mod')
106
                go_binary(name="bin", main=':mod#{import_path}/cmd/hello')
107
                """
108
            ),
109
            "go.mod": dedent(
110
                f"""\
111
                module go.example.com/foo
112
                go 1.16
113

114
                require (
115
                \t{import_path} {version}
116
                )
117
                """
118
            ),
119
        }
120
    )
121

122
    raw_files = {
1✔
123
        f"go-mod-proxy/{import_path}/@v/{version}.zip": fake_gomod.pop(
124
            f"go-mod-proxy/{import_path}/@v/{version}.zip"
125
        ),
126
        f"go-mod-proxy/{import_path}/@v/{version}.info": cast(
127
            str, fake_gomod.pop(f"go-mod-proxy/{import_path}/@v/{version}.info")
128
        ).encode("utf-8"),
129
    }
130

131
    with setup_tmpdir(
1✔
132
        cast("dict[str, str]", fake_gomod), cast("dict[str, bytes]", raw_files)
133
    ) as tmpdir:
134
        # required for GOPROXY to work correctly when the go-mod-proxy
135
        # is in a subdir of the cwd.
136
        abspath = os.path.abspath(tmpdir)
1✔
137
        result = run_pants(
1✔
138
            [
139
                "--backend-packages=pants.backend.experimental.go",
140
                "--pants-ignore=__pycache__",
141
                "--golang-subprocess-env-vars=GOSUMDB=off",
142
                f"--golang-subprocess-env-vars=GOPROXY=file://{abspath}/go-mod-proxy",
143
                "run",
144
                f"//{tmpdir}:bin",
145
            ]
146
        )
147

148
    assert result.stdout == "Hello world!\n"
1✔
UNCOV
149
    assert result.exit_code == 0
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc