editorfake

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package editorfake provides a means of building a configurable fake editor executable.

It works by hooking into the entry point of the current test executable with TryMain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(t test.T, ops ...Option) string

New builds a new fake editor that runs the provided operations.

It returns a shell command that, when invoked, acts like a valid editor.

func TryMain

func TryMain()

TryMain is the entry point for the fake editor. It runs the editor behavior if inside a fake editor environment.

Use this in TestMain before calling m.Run().

func TestMain(m *testing.M) {
  editortest.TryMain()

  os.Exit(m.Run())
}

This is a no-op if not inside a fake editor environment.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the behavior of a fake editor.

func AddPrefix

func AddPrefix(prefix string) Option

AddPrefix makes the editor add a prefix to the contents of the file.

func DeleteFile

func DeleteFile() Option

DeleteFile informs the editor to delete the file instead of writing to it.

func ExitCode

func ExitCode(code int) Option

ExitCode configures the exit code of the editor. This is ignored if any of the prior operations failed.

func GiveContents

func GiveContents(c string) Option

GiveContents tells the editor to replace the contents of the file with the given string.

func WantContents

func WantContents(c string) Option

WantContents indicates that the editor should expect exactly the provided contents as input. The editor will fail with a non-zero exit code if this condition is not met.

Jump to

Keyboard shortcuts

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