shad-go/tools/testtool/commands/test_submission_test.go

70 lines
1.5 KiB
Go
Raw Normal View History

package commands
import (
2020-02-12 22:54:25 +00:00
"errors"
"io/ioutil"
"path"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
// listDirs lists directories in given directory.
func listDirs(dir string) ([]string, error) {
files, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
var dirs []string
for _, f := range files {
if f.IsDir() {
dirs = append(dirs, path.Join(dir, f.Name()))
}
}
return dirs, nil
}
func Test_testSubmission_correct(t *testing.T) {
testDirs, err := listDirs("../testdata/submissions/correct")
2020-02-16 14:18:51 +00:00
require.NoError(t, err)
for _, dir := range testDirs {
2020-02-14 12:39:06 +00:00
absDir, err := filepath.Abs(dir)
2020-02-16 14:18:51 +00:00
require.NoError(t, err)
2020-02-14 12:39:06 +00:00
problem := path.Base(absDir)
t.Run(problem, func(t *testing.T) {
2020-02-14 12:39:06 +00:00
studentRepo := path.Join(absDir, "student")
privateRepo := path.Join(absDir, "private")
2020-02-12 22:54:25 +00:00
require.NoError(t, testSubmission(studentRepo, privateRepo, problem))
})
}
}
func Test_testSubmission_incorrect(t *testing.T) {
testDirs, err := listDirs("../testdata/submissions/incorrect")
2020-02-16 14:18:51 +00:00
require.NoError(t, err)
for _, dir := range testDirs {
2020-02-14 12:39:06 +00:00
absDir, err := filepath.Abs(dir)
2020-02-16 14:18:51 +00:00
require.NoError(t, err)
2020-02-14 12:39:06 +00:00
problem := path.Base(absDir)
t.Run(problem, func(t *testing.T) {
2020-02-14 12:39:06 +00:00
studentRepo := path.Join(absDir, "student")
privateRepo := path.Join(absDir, "private")
2020-02-12 22:54:25 +00:00
err := testSubmission(studentRepo, privateRepo, problem)
require.Error(t, err)
2020-02-12 22:54:25 +00:00
if problem == "brokentest" {
var testFailedErr *TestFailedError
require.True(t, errors.As(err, &testFailedErr))
}
})
}
}