Documentation ¶
Overview ¶
testutils provides utility functions for compiling, running, and managing code submissions, particularly for Rust, and interacting with the command line.
Index ¶
- Variables
- func AppendStringToFile(source string, destFilePath string) error
- func DeleteStringFromFile(targetString, filePath string) error
- func ExecutablePath(fullTurnInFilePath string, suffix string) string
- func FullTurnInDirectory(codeDirectory string, exercise Exercise.Exercise) string
- func FullTurnInFilesPath(exercise Exercise.Exercise) []string
- func RunCommandLine(workingDirectory string, command string, args []string, ...) (string, error)
- func RunExecutable(executablePath string, options ...RunExecutableOption) (string, error)
- type RunExecutableOption
Constants ¶
This section is empty.
Variables ¶
var ErrTimeout = errors.New("command timed out")
ErrTimeout is an error that indicates a command has timed out.
Functions ¶
func AppendStringToFile ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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