Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add documentation comments for package #6

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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