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

feat: add flag to execute filetests with prefix #2837

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 15 additions & 7 deletions gnovm/tests/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,29 @@ func TestFileStr(t *testing.T) {
// to native go standard library.
func TestFilesNative(t *testing.T) {
baseDir := filepath.Join(".", "files")
runFileTests(t, baseDir, []string{"*_stdlibs*"}, WithNativeLibs())
runFileTests(t, baseDir, []string{"*_stdlibs*"}, "", WithNativeLibs())
}

// Test files using standard library in stdlibs/.
func TestFiles(t *testing.T) {
baseDir := filepath.Join(".", "files")
runFileTests(t, baseDir, []string{"*_native*"})
runFileTests(t, baseDir, []string{"*_native*"}, "")
}

func TestChallenges(t *testing.T) {
t.Skip("Challenge tests, skipping.")
baseDir := filepath.Join(".", "challenges")
runFileTests(t, baseDir, nil)
runFileTests(t, baseDir, nil, "")
}

type testFile struct {
path string
fs.DirEntry
}

// ignore are glob patterns to ignore
func runFileTests(t *testing.T, baseDir string, ignore []string, opts ...RunFileTestOption) {
// ignore are glob patterns to ignore. If includePrefix is a non-empty string,
// only test names with the prefix will be executed.
func runFileTests(t *testing.T, baseDir string, ignore []string, includePrefix string, opts ...RunFileTestOption) {
t.Helper()

opts = append([]RunFileTestOption{WithSyncWanted(*withSync)}, opts...)
Expand All @@ -54,7 +55,7 @@ func runFileTests(t *testing.T, baseDir string, ignore []string, opts ...RunFile
t.Fatal(err)
}

files = filterFileTests(t, files, ignore)
files = filterFileTests(t, files, ignore, includePrefix)
var path string
var name string
for _, file := range files {
Expand Down Expand Up @@ -86,7 +87,7 @@ func readFiles(t *testing.T, dir string) ([]testFile, error) {
return files, err
}

func filterFileTests(t *testing.T, files []testFile, ignore []string) []testFile {
func filterFileTests(t *testing.T, files []testFile, ignore []string, includePrefix string) []testFile {
t.Helper()
filtered := make([]testFile, 0, 1000)
var name string
Expand All @@ -97,10 +98,17 @@ func filterFileTests(t *testing.T, files []testFile, ignore []string) []testFile
if filepath.Ext(name) != ".gno" {
continue
}

// Skip if a prefix is specified and this file does not have the prefix.
if includePrefix != "" && !strings.HasPrefix(name, includePrefix) {
continue
}

// skip ignored files
if isIgnored(t, name, ignore) {
continue
}

// skip _long file if we only want to test regular file.
if testing.Short() && strings.Contains(name, "_long") {
t.Logf("skipping test %s in short mode.", name)
Expand Down
Loading