test_case_harness

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 4 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DetectedLanguage

type DetectedLanguage struct {
	Language string   // detected language ("java", "python", etc.)
	RunCmd   string   // run command ("java", "python3", etc.)
	RunArgs  []string // run arguments (e.g. ["-cp", ".", "TestE01"])
}

DetectedLanguage holds the runtime info for a language detected by CompileStep Language="auto". Populated by the framework in Phase 2; consumed by TestFunc via harness.DetectedLang.

type TestCaseHarness

type TestCaseHarness struct {
	// Logger is to be used for all logs generated from the test function.
	Logger *logger.Logger

	// SubmissionDir is the directory containing the student's submission.
	// Use this for direct file access without needing your_program.sh.
	SubmissionDir string

	// Executable is the program to be tested (may point to SubmissionDir if no ExecutableFileName).
	Executable *executable.Executable

	// DetectedLang is the auto-detected language info from CompileStep Language="auto".
	// nil when Language is not "auto". TestFunc reads RunCmd/RunArgs to run the test driver.
	DetectedLang *DetectedLanguage
	// contains filtered or unexported fields
}

TestCaseHarness is passed to your TestCase's TestFunc.

For Bootcode courses that don't use your_program.sh, use SubmissionDir directly:

if !harness.FileExists("hello.c") {
    return fmt.Errorf("hello.c does not exist")
}

For long-lived programs (like a Redis server), use Executable:

if err := harness.Executable.Start(); err != nil {
   return err
}
harness.RegisterTeardownFunc(func() { harness.Executable.Kill() })

For scripts that run and exit (like a Git command):

result, err := harness.Executable.Run("cat-file", "-p", "sha")
if err != nil {
    return err
}

func (*TestCaseHarness) FileExists

func (s *TestCaseHarness) FileExists(relativePath string) bool

FileExists checks if a file exists within the submission directory.

func (*TestCaseHarness) FilePath

func (s *TestCaseHarness) FilePath(relativePath string) string

FilePath returns the absolute path to a file within the submission directory.

func (*TestCaseHarness) NewExecutable

func (s *TestCaseHarness) NewExecutable() *executable.Executable

func (*TestCaseHarness) ReadFile

func (s *TestCaseHarness) ReadFile(relativePath string) ([]byte, error)

ReadFile reads the contents of a file within the submission directory.

func (*TestCaseHarness) RegisterTeardownFunc

func (s *TestCaseHarness) RegisterTeardownFunc(teardownFunc func())

func (*TestCaseHarness) RunTeardownFuncs

func (s *TestCaseHarness) RunTeardownFuncs()

Jump to

Keyboard shortcuts

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