Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Production code imports `testing` package (`internal/config/config.go`, `internal/cmdparser/test.go`)

Đang mở
#780 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
go
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách đọc internal/config/config.go và internal/cmdparser/test.go, sau đó kiểm tra các caller của test helper giữa các package của chúng. Refactor các helper để các file được compile cho production không còn import package testing của Go, lựa chọn giữa input dựa trên string và các test subpackage chuyên biệt. Hoàn thành khi các import đó được loại bỏ và các test hiện có vẫn pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

internal/config/config.go and internal/cmdparser/test.go are non-_test.go files that import the standard library testing package, which is a Go anti-pattern — it pulls test-only code (and its transitive deps) into production builds.

Noted by @shueybubbles in https://github.com/microsoft/go-sqlcmd/pull/747#discussion_r3443879059.

Details

  • internal/config/config.go imports testing solely for SetFileNameForTest(t *testing.T), which only ever calls t.Name().
  • internal/cmdparser/test.go imports testing for TestSetup(t *testing.T) and related helpers.

Both files exist to provide test helpers callable from _test.go files in other packages, which is why they couldn't simply be renamed _test.go. However, the dependency on testing from production-compiled files is still undesirable.

Introduced in commit 10ee238 ("Modern CLI - Part 2"), long predating PR #747.

Suggested fix

Minimal-impact option:

  • Change config.SetFileNameForTest to accept a string (the test name) instead of *testing.T. Callers pass t.Name(). Drops the testing import from config.go.
  • Apply a similar refactor to cmdparser/test.go, or move its helpers into a dedicated cmdparsertest subpackage.

Larger option:

  • Move all cross-package test helpers into dedicated *test subpackages (e.g. internal/config/configtest, internal/cmdparser/cmdparsertest).
Ngôn ngữ chính
Go
Star
595
Fork
91
Merge trung bình
9 giờ 35 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/go-sqlcmd

Tất cả issue của microsoft/go-sqlcmd

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.