Documentation
¶
Index ¶
- Constants
- func AssertConfigField[T comparable](t *testing.T, fieldName string, actual, expected T)
- func AssertConfigFieldFunc[T comparable](t *testing.T, msg string, actual, expected T)
- func AssertCount(t *testing.T, got, want int, what string)
- func AssertCountf(t *testing.T, got, want int, format string, args ...any)
- func AssertEqual[T comparable](t *testing.T, got, want T, messagePrefix string)
- func AssertEqualFn[T any](t *testing.T, got, want T, compareFn func(a, b T) bool, what string)
- func AssertError(t *testing.T, err error, what string)
- func AssertErrorIs(t *testing.T, err, want error, what string)
- func AssertErrorIsFatal(t *testing.T, err, target error, what string)
- func AssertErrorMatches(t *testing.T, err error, wantErr bool, msg string)
- func AssertExpectedGot[T any](t *testing.T, got T, wantDescription string, wantValue T)
- func AssertFatalLen[T any](t *testing.T, got []T, want int, what string)
- func AssertFatalNoError(t *testing.T, err error, what string)
- func AssertFieldValue[T comparable](t *testing.T, got, want T, fieldName string)
- func AssertIncrementalStats(t *testing.T, ...)
- func AssertInt(t *testing.T, got, want int, description string)
- func AssertIntFormatted(t *testing.T, got, want int, format string)
- func AssertIntInRange(t *testing.T, got, minVal, maxVal int, what string)
- func AssertIsValid[T any](t *testing.T, typeName string, obj T, wantErr bool, getErr func(T) error)
- func AssertJSONRoundTrip[T any](t *testing.T, obj T) T
- func AssertLen[T any](t *testing.T, got []T, want int, what string)
- func AssertMarshalJSONError[T any](t *testing.T, methodName string, obj T, wantError bool, ...)
- func AssertNil(t *testing.T, got any, what string)
- func AssertNoError(t *testing.T, err error, what string)
- func AssertNotNil(t *testing.T, got any, what string)
- func AssertString(t *testing.T, got, want, description string)
- func AssertStringContains(t *testing.T, got, substr, what string)
- func AssertStringNotContains(t *testing.T, got, substr, what string)
- func AssertStringPrefix(t *testing.T, got, prefix, what string)
- func AssertUnmarshalError(t *testing.T, methodName string, data []byte, wantErr bool, ...)
- func AssertUnmarshalJSONError[T any](t *testing.T, methodName string, data []byte, wantError bool, ...)
- func BuildArgsFromFlags(baseArgs []string, flags map[string]string) []string
- func CollectMatches(matchesChan <-chan syntax.Match) []syntax.Match
- func ContainsString(slice []string, item string) bool
- func ContainsSubstring(str string, substrings []string) bool
- func CopyToBuffer(dst io.Writer, src io.Reader, done chan<- struct{})
- func CreateMatch(hash string, filenames ...string) syntax.Match
- func CreateMatchWithNodes(hash string, fragments [][]*syntax.Node) syntax.Match
- func CreateMockCloneGroup(hash string, size int, filenames []string) []*syntax.Node
- func CreateMockNode(nodeType int, filename string, pos, end int) *syntax.Node
- func CreateMockNodes(count int, filename string) []*syntax.Node
- func CreateNodePair(filename string, pos1, end1, pos2, end2 int32) []*syntax.Node
- func CreateNodeSlice(values []struct{ ... }) []*syntax.Node
- func CreateNodeWithPos(nodeType int32, filename string, pos, end int32) *syntax.Node
- func CreateSingleNode(filename string, pos, end int32) []*syntax.Node
- func ExpectFalse(t *testing.T, cond bool, what string)
- func ExpectTrue(t *testing.T, cond bool, what string)
- func FormatGotWant(got, want any) string
- func GetFilesInMatch(match syntax.Match) []string
- func GinkgoRequireGolden(output []byte)
- func GinkgoRequireGoldenString(output string)
- func ParseFile(t *testing.T, filePath string) *syntax.Node
- func ParseFiles(t *testing.T, filePaths []string) []*syntax.Node
- func RequireGolden(tb testing.TB, output []byte)
- func RequireGoldenString(tb testing.TB, output string)
- func RunNamedTest(t *testing.T, name string, testFunc func(t *testing.T))
- func RunTableTest[T any](t *testing.T, tests []T, assertion func(t *testing.T, tt T))
- func RunTableTestWithName[T any](t *testing.T, tests []T, getName func(T) string, ...)
- func SimpleCodeTemplate(funcName string) string
- func TestEmptyDirectory(setup *BDDTestSetup, threshold int) []byte
- func WriteAndParseFile(t *testing.T, filename, content string) *syntax.Node
- func WriteFile(t *testing.T, path string, content []byte)
- func WriteTestFile(t *testing.T, filename, content string)
- func WriteTestFileWithPerm(t *testing.T, filename, content string, perm os.FileMode)
- type BDDError
- type BDDTestSetup
- func (s *BDDTestSetup) Cleanup() error
- func (s *BDDTestSetup) CreateAndRunDuplExpectSuccess(filenames []string, content string, args ...string) []byte
- func (s *BDDTestSetup) CreateDuplicateFiles(filenames []string, content string) error
- func (s *BDDTestSetup) CreateDuplicateFilesAndRun(content string, args ...string) ([]byte, error)
- func (s *BDDTestSetup) CreateFileWithContent(subpath, content string) error
- func (s *BDDTestSetup) CreateNamedDuplicateFilesAndRun(filenames []string, content string, args ...string) ([]byte, error)
- func (s *BDDTestSetup) CreateSubdirectories(paths ...string) error
- func (s *BDDTestSetup) CreateTestFile(filename, content string) error
- func (s *BDDTestSetup) CreateTestFiles(files map[string]string) error
- func (s *BDDTestSetup) CreateVendorDuplicateFiles(vendorPath, code string) error
- func (s *BDDTestSetup) GetFilePath(filename string) string
- func (s *BDDTestSetup) RunArtDupl(args ...string) ([]byte, error)
- func (s *BDDTestSetup) RunArtDuplAllFormat(outputDir, threshold string) ([]byte, error)
- func (s *BDDTestSetup) RunArtDuplAndCapture(args ...string) (stdout, stderr []byte, err error)
- func (s *BDDTestSetup) RunArtDuplAndVerifyOutput(args ...string) string
- func (s *BDDTestSetup) RunArtDuplOnDir(dir string, args ...string) ([]byte, error)
- func (s *BDDTestSetup) RunArtDuplOnDirWithFlags(dir string, flags map[string]string) ([]byte, error)
- func (s *BDDTestSetup) RunArtDuplWithFlags(flags map[string]string) ([]byte, error)
- func (s *BDDTestSetup) RunArtDuplWithFlagsAndVerify(flags map[string]string) string
- func (s *BDDTestSetup) RunArtDuplWithStdin(stdinContent string, flags map[string]string) ([]byte, error)
- func (s *BDDTestSetup) RunStatsSubcommandWithJSON(threshold string) (map[string]any, error)
- func (s *BDDTestSetup) RunSubcommand(args ...string) ([]byte, error)
- func (s *BDDTestSetup) RunSubcommandOutput(args ...string) ([]byte, error)
- func (s *BDDTestSetup) RunVendorTest(includeVendor bool, subcommand string, extraArgs ...string) ([]byte, error)
- func (s *BDDTestSetup) RunVendorTestWithOptions(vendorPath, code string, includeVendor bool, subcommand string, ...) ([]byte, error)
- func (s *BDDTestSetup) RunWithConfigFile(configFileName, configContent, code string, fileNames []string) ([]byte, error)
- type CommandResult
- type TableTestCase
- type TestFileSetup
Constants ¶
const ( // ThresholdSmall is used for tests with minimal code (5 tokens). ThresholdSmall = "5" // ThresholdMedium is used for tests with moderate code (10 tokens). ThresholdMedium = "10" // ThresholdLarge is used for tests with larger code (20 tokens). ThresholdLarge = "20" )
Common test thresholds for BDD tests.
const CommonDuplicateCodeTemplate = `package main
import "fmt"
func %s() {
for i := 0; i < 10; i++ {
fmt.Println(i)
}
}`
CommonDuplicateCodeTemplate is a reusable code template for creating duplicate test files. Use with CreateDuplicateFilesAndRun to reduce test duplication.
const SimpleVendorTestCode = `package main
func vendorFunc() { println(1) }`
SimpleVendorTestCode is a minimal code sample for vendor directory filtering tests. Use when a smaller code sample is sufficient (threshold of 3-5 tokens).
const VendorTestCode = `package main
import "fmt"
func vendorFunc() {
for i := 0; i < 10; i++ {
fmt.Println(i)
}
}`
VendorTestCode is a reusable code sample for vendor directory filtering tests. It contains enough tokens to be detected as a duplicate while being simple and consistent.
Variables ¶
This section is empty.
Functions ¶
func AssertConfigField ¶
func AssertConfigField[T comparable](t *testing.T, fieldName string, actual, expected T)
AssertConfigField asserts that a config field matches the expected value. The fieldName is used in the error message (e.g., "Threshold"). The actual parameter should be the field value, and expected is the expected value.
func AssertConfigFieldFunc ¶
func AssertConfigFieldFunc[T comparable](t *testing.T, msg string, actual, expected T)
AssertConfigFieldFunc asserts that a config field matches the expected value using a custom message. The msg parameter is prepended to the error message. The actual parameter should be the field value, and expected is the expected value.
func AssertCount ¶
AssertCount asserts that the count of items matches the expected value. The what parameter describes what is being counted (e.g., "Clones", "results").
func AssertCountf ¶
AssertCountf asserts that the count of items matches the expected value with a formatted message.
func AssertEqual ¶
func AssertEqual[T comparable](t *testing.T, got, want T, messagePrefix string)
AssertEqual checks if got equals want and reports an error if not. The messagePrefix is used in the error message (e.g., "Format.IsValid()").
func AssertEqualFn ¶
AssertEqualFn asserts that got equals want using a custom comparison function. The compareFn should return true if values are equal.
func AssertError ¶
AssertError asserts that an error occurred.
func AssertErrorIs ¶
AssertErrorIs asserts that err wraps the expected error.
func AssertErrorIsFatal ¶ added in v0.2.0
AssertErrorIsFatal asserts that err wraps the target error, calling t.Fatalf on mismatch.
func AssertErrorMatches ¶
AssertErrorMatches checks that an error matches expected state. The wantErr parameter indicates whether an error is expected. The msg parameter is used in the error message (e.g., "handleWalkEntry()").
func AssertExpectedGot ¶
AssertExpectedGot asserts that got matches the expected value with "Expected X, got Y" format. This helper eliminates AST clone patterns from inline assertions like:
if got != want { t.Errorf("Expected X, got Y", X, got) }
func AssertFatalLen ¶ added in v0.2.0
AssertFatalLen asserts that the length of a slice matches the expected value. On mismatch, calls t.Fatalf to stop the test immediately.
func AssertFatalNoError ¶ added in v0.2.0
AssertFatalNoError asserts that no error occurred, calling t.Fatalf on failure.
func AssertFieldValue ¶
func AssertFieldValue[T comparable](t *testing.T, got, want T, fieldName string)
AssertFieldValue asserts that a field matches the expected value. The fieldName is used in the error message as a description. This helper eliminates AST clone patterns from inline field assertions.
func AssertIncrementalStats ¶
func AssertIncrementalStats( t *testing.T, actualFilesCount, actualCacheMisses, expectedFilesCount, expectedCacheMisses int, )
AssertIncrementalStats asserts that the incremental parser stats have expected values. Use this to verify the results of a first run (filesCount=1, cacheMisses=1) or subsequent runs.
func AssertInt ¶
AssertInt asserts that got equals want with an "Expected X, got Y" format. This helper eliminates AST clone patterns from inline assertions.
func AssertIntFormatted ¶
AssertIntFormatted asserts that got equals want with a custom format string. The format should include %d for both expected and actual values.
func AssertIntInRange ¶
AssertIntInRange asserts that got is within min and max (inclusive).
func AssertIsValid ¶
func AssertIsValid[T any]( t *testing.T, typeName string, obj T, wantErr bool, getErr func(T) error, )
AssertIsValid asserts that the IsValid() method returns the expected error state. The typeName parameter is used in the error message (e.g., "Analysis", "Clone").
func AssertJSONRoundTrip ¶
AssertJSONRoundTrip verifies that a value can be marshaled to JSON and unmarshaled back. The obj parameter is the original object to roundtrip. The t.Helper() should be called before this function. Returns the unmarshaled result for further assertions.
func AssertLen ¶
AssertLen asserts that the length of a slice matches the expected value. If the assertion fails, it reports the actual length.
func AssertMarshalJSONError ¶
func AssertMarshalJSONError[T any]( t *testing.T, methodName string, obj T, wantError bool, marshalFn func(T) ([]byte, error), )
AssertMarshalJSONError checks that a JSON marshal operation returns the expected error state. The methodName parameter is used in the error message (e.g., "MarshalJSON").
func AssertNoError ¶
AssertNoError asserts that no error occurred.
func AssertNotNil ¶
AssertNotNil asserts that a value is not nil.
func AssertString ¶
AssertString asserts that got equals want. This helper eliminates AST clone patterns from inline string assertions.
func AssertStringContains ¶
AssertStringContains asserts that a string contains a substring.
func AssertStringNotContains ¶
AssertStringNotContains asserts that a string does not contain a substring.
func AssertStringPrefix ¶
AssertStringPrefix asserts that a string starts with a prefix.
func AssertUnmarshalError ¶
func AssertUnmarshalError( t *testing.T, methodName string, data []byte, wantErr bool, unmarshalFn func([]byte) error, )
AssertUnmarshalError verifies that unmarshaling from JSON produces the expected error state. The methodName is used in error messages (e.g., "StringID.UnmarshalJSON"). The data parameter is the JSON bytes to unmarshal.
func AssertUnmarshalJSONError ¶
func AssertUnmarshalJSONError[T any]( t *testing.T, methodName string, data []byte, wantError bool, unmarshalFn func([]byte) error, )
AssertUnmarshalJSONError checks that a JSON unmarshal operation returns the expected error state. The methodName parameter is used in the error message (e.g., "UnmarshalJSON").
func BuildArgsFromFlags ¶
BuildArgsFromFlags converts a map of flags to command line arguments.
func CollectMatches ¶
CollectMatches collects all matches from a channel into a slice.
func ContainsString ¶
ContainsString checks if a string slice contains a specific string.
func ContainsSubstring ¶
ContainsSubstring checks if a string contains any of the given substrings.
func CopyToBuffer ¶ added in v0.2.0
CopyToBuffer reads from src into dst in a goroutine, signaling completion on done.
func CreateMatch ¶
CreateMatch creates a syntax.Match with a hash and one or more filenames. Each filename creates a separate fragment containing a single node.
func CreateMatchWithNodes ¶
CreateMatchWithNodes creates a syntax.Match with explicit node fragments.
func CreateMockCloneGroup ¶
CreateMockCloneGroup creates a mock clone group with given files.
func CreateMockNode ¶
CreateMockNode creates a simple mock AST node for testing.
func CreateMockNodes ¶
CreateMockNodes creates multiple mock nodes for testing.
func CreateNodePair ¶ added in v0.2.0
CreateNodePair creates a slice with two nodes at different positions.
func CreateNodeSlice ¶
func CreateNodeSlice(values []struct {
Type int32
Filename string
Pos int32
End int32
},
) []*syntax.Node
CreateNodeSlice creates a slice of syntax.Node pointers with given values.
func CreateNodeWithPos ¶
CreateNodeWithPos creates a syntax.Node with specific field values. This helper reduces duplication when creating similar node literals.
func CreateSingleNode ¶ added in v0.2.0
CreateSingleNode creates a slice containing a single node with type=0.
func ExpectFalse ¶
ExpectFalse asserts that the condition is false.
func ExpectTrue ¶
ExpectTrue asserts that the condition is true.
func FormatGotWant ¶
FormatGotWant formats got and want for error messages.
func GetFilesInMatch ¶
GetFilesInMatch extracts unique filenames from a match.
func GinkgoRequireGolden ¶
func GinkgoRequireGolden(output []byte)
GinkgoRequireGolden is like RequireGolden but uses Ginkgo's test context automatically.
func GinkgoRequireGoldenString ¶
func GinkgoRequireGoldenString(output string)
GinkgoRequireGoldenString is like GinkgoRequireGolden but takes a string.
func ParseFiles ¶
ParseFiles parses multiple Go files and returns AST nodes.
func RequireGolden ¶
RequireGolden compares output against a golden file, printing a diff if they don't match. The golden file is stored in testdata/{testName}.golden relative to the calling file.
To update golden files, run:
go test -update ./...
func RequireGoldenString ¶
RequireGoldenString is like RequireGolden but takes a string.
func RunNamedTest ¶
RunNamedTest executes a subtest with the given name and test function. This is a thin wrapper around t.Run for consistency.
func RunTableTest ¶
RunTableTest executes a table-driven test with the given test cases and assertion function. This helper reduces boilerplate in standard table-driven test patterns.
Example usage:
tests := []struct {
testutil.TableTestCase
format Format
expected bool
}{
{TableTestCase: testutil.TableTestCase{Name: "text is valid"}, format: FormatText, expected: true},
}
testutil.RunTableTest(t, tests, func(t *testing.T, tt struct {
testutil.TableTestCase
format Format
expected bool
}) {
if got := tt.format.IsValid(); got != tt.expected {
t.Errorf("Format.IsValid() = %v, want %v", got, tt.expected)
}
})
func RunTableTestWithName ¶
func RunTableTestWithName[T any]( t *testing.T, tests []T, getName func(T) string, verify func(t *testing.T, tc T), )
RunTableTestWithName executes a table-driven test with a custom name extractor function. This is useful when test structs have a lowercase 'name' field or need custom naming logic.
Example usage:
tests := []struct {
name string
format Format
expected bool
}{
{name: "text is valid", format: FormatText, expected: true},
}
testutil.RunTableTestWithName(t, tests, func(tt struct {
name string
format Format
expected bool
}) string {
return tt.name
}, func(t *testing.T, tt struct {
name string
format Format
expected bool
}) {
testutil.AssertEqual(t, tt.format.IsValid(), tt.expected, "Format.IsValid()")
})
func SimpleCodeTemplate ¶
SimpleCodeTemplate generates a simple Go code template with a unique function name. This is useful for creating test files that need distinct function names to avoid false positives across different test cases.
func TestEmptyDirectory ¶
func TestEmptyDirectory(setup *BDDTestSetup, threshold int) []byte
TestEmptyDirectory verifies art-dupl handles empty directory gracefully.
func WriteAndParseFile ¶
WriteAndParseFile writes a Go file and parses it into an AST node. This is a convenience function that combines os.WriteFile and golang.Parse with proper error handling, commonly used in test files.
func WriteFile ¶ added in v0.2.0
WriteFile writes byte content to a file with 0o600 permissions. Fails the test if writing fails.
func WriteTestFile ¶
WriteTestFile writes content to a file and fails the test if it fails. Uses 0o600 permissions for secure default.
Types ¶
type BDDError ¶
BDDError represents an error that occurred during BDD test setup or execution.
func NewBDDError ¶
NewBDDError creates a new BDDError with the given operation and cause.
func (*BDDError) WithOutput ¶
WithOutput adds output to the BDDError.
type BDDTestSetup ¶
type BDDTestSetup struct {
T *testing.T
TmpDir string
FileProcessor *utils.FileProcessor
// Executor runs art-dupl in-process and returns combined stdout+stderr output.
// Set by the bdd package.
Executor func(args ...string) ([]byte, error)
// ExecutorResult runs art-dupl in-process and returns separated stdout/stderr.
// Set by the bdd package. Used by RunSubcommandOutput for JSON parsing.
ExecutorResult func(args ...string) (*CommandResult, error)
}
BDDTestSetup provides complete BDD test infrastructure with temporary directory.
Execution is done in-process via the Executor field (set by the bdd package) instead of building and running a separate binary. This is faster and avoids race conditions like "text file busy".
func NewBDDTestSetup ¶
func NewBDDTestSetup(t *testing.T) *BDDTestSetup
NewBDDTestSetup creates a new BDD test setup with temporary directory. The caller is responsible for cleaning up using Cleanup() or manually.
Note: The Executor field must be set before calling Run* methods.
func NewBDDTestSetupForGinkgo ¶
func NewBDDTestSetupForGinkgo() (*BDDTestSetup, error)
NewBDDTestSetupForGinkgo creates a new BDD test setup without requiring *testing.T. Designed for use with Ginkgo's BeforeEach/AfterEach pattern. The caller must call Cleanup() in an AfterEach block.
Note: The Executor field must be set before calling Run* methods.
func (*BDDTestSetup) Cleanup ¶
func (s *BDDTestSetup) Cleanup() error
Cleanup removes the temporary directory and all its contents.
func (*BDDTestSetup) CreateAndRunDuplExpectSuccess ¶
func (s *BDDTestSetup) CreateAndRunDuplExpectSuccess( filenames []string, content string, args ...string, ) []byte
CreateAndRunDuplExpectSuccess creates duplicate files, runs art-dupl, and asserts success. This helper reduces boilerplate by combining CreateAndRunDupl with common assertions. Returns the output for further assertions. Panics on error (suitable for Ginkgo tests).
func (*BDDTestSetup) CreateDuplicateFiles ¶
func (s *BDDTestSetup) CreateDuplicateFiles(filenames []string, content string) error
CreateDuplicateFiles creates multiple files with identical content.
func (*BDDTestSetup) CreateDuplicateFilesAndRun ¶
func (s *BDDTestSetup) CreateDuplicateFilesAndRun(content string, args ...string) ([]byte, error)
CreateDuplicateFilesAndRun creates duplicate files with the given content and runs art-dupl. Returns the command output for assertions. This helper reduces boilerplate in BDD tests.
func (*BDDTestSetup) CreateFileWithContent ¶
func (s *BDDTestSetup) CreateFileWithContent(subpath, content string) error
CreateFileWithContent creates a file with specific content at a given subpath. The subpath is relative to the test temporary directory.
func (*BDDTestSetup) CreateNamedDuplicateFilesAndRun ¶
func (s *BDDTestSetup) CreateNamedDuplicateFilesAndRun( filenames []string, content string, args ...string, ) ([]byte, error)
CreateNamedDuplicateFilesAndRun creates duplicate files with specific names and content, then runs art-dupl. Returns the command output for assertions. This helper reduces boilerplate in BDD tests.
func (*BDDTestSetup) CreateSubdirectories ¶
func (s *BDDTestSetup) CreateSubdirectories(paths ...string) error
CreateSubdirectories creates multiple directories in test temporary directory. Each directory name is a relative path that will be created under the temp directory.
func (*BDDTestSetup) CreateTestFile ¶
func (s *BDDTestSetup) CreateTestFile(filename, content string) error
CreateTestFile creates a single test file with given content.
func (*BDDTestSetup) CreateTestFiles ¶
func (s *BDDTestSetup) CreateTestFiles(files map[string]string) error
CreateTestFiles creates multiple test files from a map.
func (*BDDTestSetup) CreateVendorDuplicateFiles ¶
func (s *BDDTestSetup) CreateVendorDuplicateFiles(vendorPath, code string) error
CreateVendorDuplicateFiles creates duplicate files in a vendor directory with the given vendor path and code content. This is a convenience helper for testing vendor directory filtering behavior. Returns an error if directory creation or file writing fails.
func (*BDDTestSetup) GetFilePath ¶
func (s *BDDTestSetup) GetFilePath(filename string) string
GetFilePath returns full path for a file in test directory.
func (*BDDTestSetup) RunArtDupl ¶
func (s *BDDTestSetup) RunArtDupl(args ...string) ([]byte, error)
RunArtDupl executes art-dupl with given arguments and returns combined stdout/stderr.
func (*BDDTestSetup) RunArtDuplAllFormat ¶
func (s *BDDTestSetup) RunArtDuplAllFormat(outputDir, threshold string) ([]byte, error)
RunArtDuplAllFormat runs art-dupl with --all flag to generate all output formats.
func (*BDDTestSetup) RunArtDuplAndCapture ¶
func (s *BDDTestSetup) RunArtDuplAndCapture(args ...string) (stdout, stderr []byte, err error)
RunArtDuplAndCapture executes art-dupl and captures stdout and stderr separately.
func (*BDDTestSetup) RunArtDuplAndVerifyOutput ¶
func (s *BDDTestSetup) RunArtDuplAndVerifyOutput(args ...string) string
RunArtDuplAndVerifyOutput executes art-dupl and verifies it completes successfully.
func (*BDDTestSetup) RunArtDuplOnDir ¶
func (s *BDDTestSetup) RunArtDuplOnDir(dir string, args ...string) ([]byte, error)
RunArtDuplOnDir executes art-dupl on a specific directory with given arguments.
func (*BDDTestSetup) RunArtDuplOnDirWithFlags ¶
func (s *BDDTestSetup) RunArtDuplOnDirWithFlags( dir string, flags map[string]string, ) ([]byte, error)
RunArtDuplOnDirWithFlags executes art-dupl on directory with flag map.
func (*BDDTestSetup) RunArtDuplWithFlags ¶
func (s *BDDTestSetup) RunArtDuplWithFlags(flags map[string]string) ([]byte, error)
RunArtDuplWithFlags executes art-dupl with flag map and returns combined output.
func (*BDDTestSetup) RunArtDuplWithFlagsAndVerify ¶
func (s *BDDTestSetup) RunArtDuplWithFlagsAndVerify(flags map[string]string) string
RunArtDuplWithFlagsAndVerify executes art-dupl with flags and verifies success.
func (*BDDTestSetup) RunArtDuplWithStdin ¶
func (s *BDDTestSetup) RunArtDuplWithStdin( stdinContent string, flags map[string]string, ) ([]byte, error)
RunArtDuplWithStdin executes art-dupl with stdin input. For in-process execution, stdin content (file paths) is parsed and passed as positional arguments directly, since we can't pipe to os.Stdin.
func (*BDDTestSetup) RunStatsSubcommandWithJSON ¶
func (s *BDDTestSetup) RunStatsSubcommandWithJSON(threshold string) (map[string]any, error)
RunStatsSubcommandWithJSON runs the stats subcommand with JSON format and parses the result.
func (*BDDTestSetup) RunSubcommand ¶
func (s *BDDTestSetup) RunSubcommand(args ...string) ([]byte, error)
RunSubcommand executes an art-dupl subcommand (e.g., "stats") with given arguments.
func (*BDDTestSetup) RunSubcommandOutput ¶
func (s *BDDTestSetup) RunSubcommandOutput(args ...string) ([]byte, error)
RunSubcommandOutput executes an art-dupl subcommand and returns stdout only. Use this for JSON or other structured output where stderr contamination is undesirable.
func (*BDDTestSetup) RunVendorTest ¶
func (s *BDDTestSetup) RunVendorTest( includeVendor bool, subcommand string, extraArgs ...string, ) ([]byte, error)
RunVendorTest runs a vendor directory exclusion/inclusion test with the given configuration. This helper reduces duplication across BDD tests that verify vendor filtering behavior. Parameters:
- includeVendor: if true, runs with --vendor flag to include vendor directory
- subcommand: optional subcommand to run (e.g., "stats", "" for default)
- extraArgs: additional arguments to pass to art-dupl
Returns the command output and any error that occurred.
func (*BDDTestSetup) RunVendorTestWithOptions ¶
func (s *BDDTestSetup) RunVendorTestWithOptions( vendorPath, code string, includeVendor bool, subcommand string, extraArgs ...string, ) ([]byte, error)
RunVendorTestWithOptions runs a vendor directory test with full customization. This helper reduces duplication across BDD tests that verify vendor filtering behavior. Parameters:
- vendorPath: path to vendor directory (e.g., "vendor/example")
- code: the code content to use for duplicate files
- includeVendor: if true, runs with --vendor flag to include vendor directory
- subcommand: optional subcommand to run (e.g., "stats", "" for default)
- extraArgs: additional arguments to pass to art-dupl
Returns the command output and any error that occurred.
func (*BDDTestSetup) RunWithConfigFile ¶
func (s *BDDTestSetup) RunWithConfigFile( configFileName, configContent, code string, fileNames []string, ) ([]byte, error)
RunWithConfigFile creates a config file with custom filename, test files, and runs art-dupl. This is a convenience helper for config file tests that combines file creation and execution. Returns the command output and any error that occurred.
type CommandResult ¶ added in v0.2.0
CommandResult holds the captured stdout and stderr from command execution.
func (*CommandResult) Combined ¶ added in v0.2.0
func (r *CommandResult) Combined() []byte
Combined returns stdout + stderr concatenated.
type TableTestCase ¶
type TableTestCase struct {
Name string
}
TableTestCase represents a single test case in a table-driven test.
type TestFileSetup ¶
type TestFileSetup struct {
TmpDir string
FileProcessor *utils.FileProcessor
}
TestFileSetup provides a complete test file setup with temporary directory.
func NewTestFileSetup ¶
func NewTestFileSetup(t *testing.T) *TestFileSetup
NewTestFileSetup creates a new test file setup with a temporary directory.
func (*TestFileSetup) CreateDuplicateFiles ¶
func (s *TestFileSetup) CreateDuplicateFiles(filenames []string, content string) error
CreateDuplicateFiles creates files with identical content.
func (*TestFileSetup) CreateTestFile ¶
func (s *TestFileSetup) CreateTestFile(filename, content string) error
CreateTestFile creates a single test Go file with given content.
func (*TestFileSetup) CreateTestFiles ¶
func (s *TestFileSetup) CreateTestFiles(files map[string]string) error
CreateTestFiles creates multiple test Go files from a map.
func (*TestFileSetup) GetFilePath ¶
func (s *TestFileSetup) GetFilePath(filename string) string
GetFilePath returns the full path for a file in the test directory.