Skip to content

Commit

Permalink
doc: add documentation comments for package (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed Jan 24, 2024
1 parent b74d4aa commit 9f9eba9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions engine.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Package golangspectester provides a test engine to check
// the compliance of several Go compilers and interpreters
// against the Go Specification: https://go.dev/ref/spec.
// The tests are self-contained and implemented in individual
// files.
package golangspectester

import (
Expand All @@ -11,20 +16,25 @@ import (
"strings"
)

// TestFunc is a type describing the user provided test function.
type TestFunc func(path, expected string, isError bool, code io.Reader) bool

// Engine describes a test engine.
type Engine struct {
tfp string
tf TestFunc
tfp string // test folder path
tf TestFunc // test function
}

// NewEngine returns a new test engine.
func NewEngine(testFolderPath string, testFunc TestFunc) *Engine {
return &Engine{
tfp: testFolderPath,
tf: testFunc,
}
}

// Start executes the tests located in the engine test folder path,
// using the provided engine test function. It returns the error encountered.
func (e *Engine) Start() error {
return filepath.WalkDir(e.tfp, func(path string, d fs.DirEntry, err error) error {
if err != nil {
Expand Down Expand Up @@ -57,7 +67,7 @@ func expectedFromComment(p string) (out string, isErr bool) {
}
text := f.Comments[len(f.Comments)-1].Text()

// sometimes the comment ends with a space.
// Sometimes the comment ends with a space.
// We need to use \s to avoid the IDE trimming the comment.
text = strings.Replace(text, "\\s", " ", -1)
if strings.HasPrefix(text, "Output:\n") {
Expand Down
2 changes: 1 addition & 1 deletion engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var runCmd = flag.String("run-cmd", "go run {path}", "command to run and check all results with spec files")
var unsupported = flag.String("unsupported", "", "list of unsipported functionalities. Tests based on these features will be skipped.")
var unsupported = flag.String("unsupported", "", "list of unsupported functionalities. Tests based on these features will be skipped.")

func TestEngine(t *testing.T) {
t.Log("using run command:", *runCmd)
Expand Down

0 comments on commit 9f9eba9

Please sign in to comment.