Fix failure when student added new package with tests
This commit is contained in:
parent
8eccf2d194
commit
b39f28cd3d
2 changed files with 46 additions and 8 deletions
|
@ -243,8 +243,18 @@ func runTests(testDir, privateRepo, problem string) error {
|
|||
raceBinaries = make(map[string]string)
|
||||
)
|
||||
|
||||
coverageReq := getCoverageRequirements(path.Join(privateRepo, problem))
|
||||
if coverageReq.Enabled {
|
||||
log.Printf("required coverage: %.2f%%", coverageReq.Percent)
|
||||
}
|
||||
|
||||
testListDir := testDir
|
||||
if !coverageReq.Enabled {
|
||||
testListDir = privateRepo
|
||||
}
|
||||
|
||||
//binPkgs, testPkgs := listTestsAndBinaries(filepath.Join(testDir, problem), []string{"-tags", "private", "-mod", "readonly"}) // todo return readonly
|
||||
binPkgs, testPkgs := listTestsAndBinaries(filepath.Join(testDir, problem), []string{"-tags", "private"})
|
||||
binPkgs, testPkgs := listTestsAndBinaries(filepath.Join(testListDir, problem), []string{"-tags", "private"})
|
||||
for binaryPkg := range binPkgs {
|
||||
binPath := filepath.Join(binCache, randomName())
|
||||
binaries[binaryPkg] = binPath
|
||||
|
@ -254,11 +264,6 @@ func runTests(testDir, privateRepo, problem string) error {
|
|||
}
|
||||
}
|
||||
|
||||
coverageReq := getCoverageRequirements(path.Join(privateRepo, problem))
|
||||
if coverageReq.Enabled {
|
||||
log.Printf("required coverage: %.2f%%", coverageReq.Percent)
|
||||
}
|
||||
|
||||
binariesJSON, _ := json.Marshal(binaries)
|
||||
|
||||
for testPkg := range testPkgs {
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -27,6 +31,35 @@ func listDirs(dir string) ([]string, error) {
|
|||
return dirs, nil
|
||||
}
|
||||
|
||||
func doTestSubmission(t *testing.T, studentRepo, privateRepo, problem string) error {
|
||||
annotate := func(prefix string, f **os.File) func() {
|
||||
pr, pw, err := os.Pipe()
|
||||
require.NoError(t, err)
|
||||
|
||||
oldF := *f
|
||||
*f = pw
|
||||
|
||||
go func() {
|
||||
s := bufio.NewScanner(pr)
|
||||
for s.Scan() {
|
||||
io.WriteString(oldF, fmt.Sprintf("%s%s\n", prefix, s.Text()))
|
||||
}
|
||||
}()
|
||||
|
||||
return func() {
|
||||
pw.Close()
|
||||
*f = oldF
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("=== testing started ===")
|
||||
defer annotate(">>> STDOUT >>>", &os.Stdout)()
|
||||
defer annotate(">>> STDERR >>>", &os.Stderr)()
|
||||
defer t.Logf("=== testing finished ===")
|
||||
|
||||
return testSubmission(studentRepo, privateRepo, problem)
|
||||
}
|
||||
|
||||
func Test_testSubmission_correct(t *testing.T) {
|
||||
testDirs, err := listDirs("../testdata/submissions/correct")
|
||||
require.NoError(t, err)
|
||||
|
@ -39,7 +72,7 @@ func Test_testSubmission_correct(t *testing.T) {
|
|||
studentRepo := path.Join(absDir, "student")
|
||||
privateRepo := path.Join(absDir, "private")
|
||||
|
||||
require.NoError(t, testSubmission(studentRepo, privateRepo, problem))
|
||||
require.NoError(t, doTestSubmission(t, studentRepo, privateRepo, problem))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +90,7 @@ func Test_testSubmission_incorrect(t *testing.T) {
|
|||
studentRepo := path.Join(absDir, "student")
|
||||
privateRepo := path.Join(absDir, "private")
|
||||
|
||||
err := testSubmission(studentRepo, privateRepo, problem)
|
||||
err := doTestSubmission(t, studentRepo, privateRepo, problem)
|
||||
require.Error(t, err)
|
||||
|
||||
if problem == "brokentest" {
|
||||
|
|
Loading…
Reference in a new issue