diff --git a/tools/testtool/commands/test_submission.go b/tools/testtool/commands/test_submission.go index c608511..42d7020 100644 --- a/tools/testtool/commands/test_submission.go +++ b/tools/testtool/commands/test_submission.go @@ -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 { diff --git a/tools/testtool/commands/test_submission_test.go b/tools/testtool/commands/test_submission_test.go index 8a64296..36b7340 100644 --- a/tools/testtool/commands/test_submission_test.go +++ b/tools/testtool/commands/test_submission_test.go @@ -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" {