2020-01-28 22:41:27 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2020-02-12 22:54:25 +00:00
|
|
|
"errors"
|
2020-01-28 22:41:27 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-02-01 22:14:20 +00:00
|
|
|
// listDirs lists directories in given directory.
|
2020-01-28 22:41:27 +00:00
|
|
|
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")
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
for _, dir := range testDirs {
|
|
|
|
dir, err := filepath.Abs(dir)
|
|
|
|
require.Nil(t, err)
|
|
|
|
problem := path.Base(dir)
|
|
|
|
t.Run(problem, func(t *testing.T) {
|
|
|
|
studentRepo := path.Join(dir, "student")
|
|
|
|
privateRepo := path.Join(dir, "private")
|
2020-02-12 22:54:25 +00:00
|
|
|
|
|
|
|
require.NoError(t, testSubmission(studentRepo, privateRepo, problem))
|
2020-01-28 22:41:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_testSubmission_incorrect(t *testing.T) {
|
|
|
|
testDirs, err := listDirs("../testdata/submissions/incorrect")
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
for _, dir := range testDirs {
|
|
|
|
dir, err := filepath.Abs(dir)
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
problem := path.Base(dir)
|
|
|
|
t.Run(problem, func(t *testing.T) {
|
2020-02-12 22:54:25 +00:00
|
|
|
studentRepo := path.Join(dir, "student")
|
|
|
|
privateRepo := path.Join(dir, "private")
|
2020-01-28 22:41:27 +00:00
|
|
|
|
2020-02-12 22:54:25 +00:00
|
|
|
err := testSubmission(studentRepo, privateRepo, problem)
|
|
|
|
require.Error(t, err)
|
2020-01-28 22:41:27 +00:00
|
|
|
|
2020-02-12 22:54:25 +00:00
|
|
|
if problem == "brokentest" {
|
|
|
|
var testFailedErr *TestFailedError
|
|
|
|
require.True(t, errors.As(err, &testFailedErr))
|
2020-01-28 22:41:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|