testutil

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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.

View Source
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).

View Source
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

func AssertCount(t *testing.T, got, want int, what string)

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

func AssertCountf(t *testing.T, got, want int, format string, args ...any)

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

func AssertEqualFn[T any](t *testing.T, got, want T, compareFn func(a, b T) bool, what string)

AssertEqualFn asserts that got equals want using a custom comparison function. The compareFn should return true if values are equal.

func AssertError

func AssertError(t *testing.T, err error, what string)

AssertError asserts that an error occurred.

func AssertErrorIs

func AssertErrorIs(t *testing.T, err, want error, what string)

AssertErrorIs asserts that err wraps the expected error.

func AssertErrorIsFatal added in v0.2.0

func AssertErrorIsFatal(t *testing.T, err, target error, what string)

AssertErrorIsFatal asserts that err wraps the target error, calling t.Fatalf on mismatch.

func AssertErrorMatches

func AssertErrorMatches(t *testing.T, err error, wantErr bool, msg string)

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

func AssertExpectedGot[T any](t *testing.T, got T, wantDescription string, wantValue T)

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

func AssertFatalLen[T any](t *testing.T, got []T, want int, what string)

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

func AssertFatalNoError(t *testing.T, err error, what string)

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

func AssertInt(t *testing.T, got, want int, description string)

AssertInt asserts that got equals want with an "Expected X, got Y" format. This helper eliminates AST clone patterns from inline assertions.

func AssertIntFormatted

func AssertIntFormatted(t *testing.T, got, want int, format string)

AssertIntFormatted asserts that got equals want with a custom format string. The format should include %d for both expected and actual values.

func AssertIntInRange

func AssertIntInRange(t *testing.T, got, minVal, maxVal int, what string)

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

func AssertJSONRoundTrip[T any](t *testing.T, obj T) T

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

func AssertLen[T any](t *testing.T, got []T, want int, what string)

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 AssertNil

func AssertNil(t *testing.T, got any, what string)

AssertNil asserts that a value is nil.

func AssertNoError

func AssertNoError(t *testing.T, err error, what string)

AssertNoError asserts that no error occurred.

func AssertNotNil

func AssertNotNil(t *testing.T, got any, what string)

AssertNotNil asserts that a value is not nil.

func AssertString

func AssertString(t *testing.T, got, want, description string)

AssertString asserts that got equals want. This helper eliminates AST clone patterns from inline string assertions.

func AssertStringContains

func AssertStringContains(t *testing.T, got, substr, what string)

AssertStringContains asserts that a string contains a substring.

func AssertStringNotContains

func AssertStringNotContains(t *testing.T, got, substr, what string)

AssertStringNotContains asserts that a string does not contain a substring.

func AssertStringPrefix

func AssertStringPrefix(t *testing.T, got, prefix, what string)

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

func BuildArgsFromFlags(baseArgs []string, flags map[string]string) []string

BuildArgsFromFlags converts a map of flags to command line arguments.

func CollectMatches

func CollectMatches(matchesChan <-chan syntax.Match) []syntax.Match

CollectMatches collects all matches from a channel into a slice.

func ContainsString

func ContainsString(slice []string, item string) bool

ContainsString checks if a string slice contains a specific string.

func ContainsSubstring

func ContainsSubstring(str string, substrings []string) bool

ContainsSubstring checks if a string contains any of the given substrings.

func CopyToBuffer added in v0.2.0

func CopyToBuffer(dst io.Writer, src io.Reader, done chan<- struct{})

CopyToBuffer reads from src into dst in a goroutine, signaling completion on done.

func CreateMatch

func CreateMatch(hash string, filenames ...string) syntax.Match

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

func CreateMatchWithNodes(hash string, fragments [][]*syntax.Node) syntax.Match

CreateMatchWithNodes creates a syntax.Match with explicit node fragments.

func CreateMockCloneGroup

func CreateMockCloneGroup(hash string, size int, filenames []string) []*syntax.Node

CreateMockCloneGroup creates a mock clone group with given files.

func CreateMockNode

func CreateMockNode(nodeType int, filename string, pos, end int) *syntax.Node

CreateMockNode creates a simple mock AST node for testing.

func CreateMockNodes

func CreateMockNodes(count int, filename string) []*syntax.Node

CreateMockNodes creates multiple mock nodes for testing.

func CreateNodePair added in v0.2.0

func CreateNodePair(filename string, pos1, end1, pos2, end2 int32) []*syntax.Node

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

func CreateNodeWithPos(nodeType int32, filename string, pos, end int32) *syntax.Node

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

func CreateSingleNode(filename string, pos, end int32) []*syntax.Node

CreateSingleNode creates a slice containing a single node with type=0.

func ExpectFalse

func ExpectFalse(t *testing.T, cond bool, what string)

ExpectFalse asserts that the condition is false.

func ExpectTrue

func ExpectTrue(t *testing.T, cond bool, what string)

ExpectTrue asserts that the condition is true.

func FormatGotWant

func FormatGotWant(got, want any) string

FormatGotWant formats got and want for error messages.

func GetFilesInMatch

func GetFilesInMatch(match syntax.Match) []string

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 ParseFile

func ParseFile(t *testing.T, filePath string) *syntax.Node

ParseFile parses a Go file and returns the AST node.

func ParseFiles

func ParseFiles(t *testing.T, filePaths []string) []*syntax.Node

ParseFiles parses multiple Go files and returns AST nodes.

func RequireGolden

func RequireGolden(tb testing.TB, output []byte)

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

func RequireGoldenString(tb testing.TB, output string)

RequireGoldenString is like RequireGolden but takes a string.

func RunNamedTest

func RunNamedTest(t *testing.T, name string, testFunc func(t *testing.T))

RunNamedTest executes a subtest with the given name and test function. This is a thin wrapper around t.Run for consistency.

func RunTableTest

func RunTableTest[T any](t *testing.T, tests []T, assertion func(t *testing.T, tt T))

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

func SimpleCodeTemplate(funcName string) string

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

func WriteAndParseFile(t *testing.T, filename, content string) *syntax.Node

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

func WriteFile(t *testing.T, path string, content []byte)

WriteFile writes byte content to a file with 0o600 permissions. Fails the test if writing fails.

func WriteTestFile

func WriteTestFile(t *testing.T, filename, content string)

WriteTestFile writes content to a file and fails the test if it fails. Uses 0o600 permissions for secure default.

func WriteTestFileWithPerm added in v0.2.0

func WriteTestFileWithPerm(t *testing.T, filename, content string, perm os.FileMode)

WriteTestFileWithPerm writes content to a file with specified permissions and fails the test if it fails.

Types

type BDDError

type BDDError struct {
	Operation string
	Cause     error
	Output    string
}

BDDError represents an error that occurred during BDD test setup or execution.

func NewBDDError

func NewBDDError(operation string, cause error) *BDDError

NewBDDError creates a new BDDError with the given operation and cause.

func (*BDDError) Error

func (e *BDDError) Error() string

Error implements the error interface.

func (*BDDError) Unwrap

func (e *BDDError) Unwrap() error

Unwrap returns the underlying cause.

func (*BDDError) WithOutput

func (e *BDDError) WithOutput(output string) *BDDError

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

type CommandResult struct {
	Stdout []byte
	Stderr []byte
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL