testutils

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

testutils provides utility functions for compiling, running, and managing code submissions, particularly for Rust, and interacting with the command line.

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("command timed out")

ErrTimeout is an error that indicates a command has timed out.

Functions

func AppendStringToFile

func AppendStringToFile(source string, destFilePath string) error

AppendStringToFile appends a source string to a destination file.

  • source: the string to append to the file
  • destFilePath: the path to the file to which the string will be appended

Returns an error if the file cannot be opened or the string cannot be written.

func DeleteStringFromFile

func DeleteStringFromFile(targetString, filePath string) error

DeleteStringFromFile deletes the first occurrence of a target string from a specified file.

  • targetString: the string to delete from the file
  • filePath: the path to the file from which the string will be deleted

Returns an error if the file cannot be read or written.

func ExecutablePath

func ExecutablePath(fullTurnInFilePath string, suffix string) string

ExecutablePath constructs the path to an executable by removing a specified suffix from the full file path.

  • fullTurnInFilePath: the full file path to the turned-in file
  • suffix: the suffix to remove (e.g., ".rs" for Rust files)

Returns a string representing the path to the executable.

func FullTurnInDirectory

func FullTurnInDirectory(codeDirectory string, exercise Exercise.Exercise) string

FullTurnInDirectory constructs the full path to the TurnInDirectory of an exercise.

  • codeDirectory: the root directory for code submissions
  • exercise: the Exercise struct containing the necessary directory information

Returns a string representing the full path to the TurnInDirectory.

func FullTurnInFilesPath

func FullTurnInFilesPath(exercise Exercise.Exercise) []string

FullTurnInFilesPath constructs the full file paths for all files in an exercise's TurnInFiles.

  • exercise: the Exercise struct containing the necessary directory information

Returns a slice of strings representing the full file paths.

func RunCommandLine

func RunCommandLine(workingDirectory string, command string, args []string, options ...RunExecutableOption) (string, error)

RunCommandLine runs a command line command with the provided options.

  • workingDirectory: the directory in which to run the command
  • command: the command to run
  • args: the arguments for the command
  • options: a variadic list of RunExecutableOptions that modify the command behavior

Returns the stdout output as a string and an error if the command execution fails.

func RunExecutable

func RunExecutable(executablePath string, options ...RunExecutableOption) (string, error)

RunExecutable runs an executable file at the given path with the provided options.

  • executablePath: the path to the executable file
  • options: a variadic list of RunExecutableOptions that modify the command behavior

Returns the stdout output as a string and an error if the execution fails.

Types

type RunExecutableOption

type RunExecutableOption func(*exec.Cmd)

RunExecutableOption is a type for options that modify the behavior of RunExecutable.

func WithRealTimeOutput

func WithRealTimeOutput() RunExecutableOption

WithRealTimeOutput is a RunExecutableOption that allows the command to show output in real-time.

func WithTimeout

func WithTimeout(d time.Duration) RunExecutableOption

WithTimeout is a RunExecutableOption that sets a timeout for the code execution.

  • d: the duration before the command times out

Jump to

Keyboard shortcuts

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