test

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package test provides the command to run project tests.

Index

Constants

This section is empty.

Variables

View Source
var TestCmd = &cobra.Command{
	DisableFlagParsing: true,
	Use:                "test [args...]",
	Example: `  contextvibes product test
  contextvibes product test -v  # Passes '-v' to 'go test' or 'pytest'
  contextvibes product test tests/my_specific_test.py # Passes path to pytest`,
	RunE: func(cmd *cobra.Command, args []string) error {
		presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr())
		ctx := cmd.Context()

		presenter.Summary("Running project tests.")

		cwd, err := os.Getwd()
		if err != nil {
			presenter.Error("Failed to get current working directory: %v", err)

			return fmt.Errorf("failed to get working directory: %w", err)
		}

		projType, err := project.Detect(cwd)
		if err != nil {
			presenter.Error("Failed to detect project type: %v", err)

			return fmt.Errorf("failed to detect project type: %w", err)
		}
		presenter.Info("Detected project type: %s", presenter.Highlight(string(projType)))

		var testErr error
		testExecuted := false

		switch projType {
		case project.Go:
			presenter.Header("Go Project Tests")
			testErr = executeGoTests(ctx, presenter, globals.ExecClient, cwd, args)
			testExecuted = true
		case project.Python:
			presenter.Header("Python Project Tests")
			testErr = executePythonTests(ctx, presenter, globals.ExecClient, cwd, args)
			testExecuted = true
		case project.Terraform, project.Pulumi, project.Unknown:
			fallthrough
		default:
			presenter.Info("No specific test execution logic for project type: %s", projType)
		}

		presenter.Newline()
		if !testExecuted && testErr == nil {
			presenter.Info("No tests were executed.")

			return nil
		}

		if testErr != nil {
			presenter.Error("Project tests failed.")

			return testErr
		}

		presenter.Success("Project tests completed successfully.")

		return nil
	},
}

TestCmd represents the test command.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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