Skip to content

Commit

Permalink
Allow intermediate directories in tests/
Browse files Browse the repository at this point in the history
This change lets problem authors add intermediate directories in tests/
(e.g. tests/solutions/AC.py). This still disallows relative paths,
though.
  • Loading branch information
lhchavez committed Jun 25, 2019
1 parent 2fa530c commit ddff938
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
7 changes: 4 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var (
{
ReferenceName: "refs/heads/protected",
PathRegexps: []*regexp.Regexp{
regexp.MustCompile("^solutions(/[^/]+\\.(markdown|gif|jpe?g|png))?$"),
regexp.MustCompile("^solutions(/[^/]+\\.(markdown|gif|jpe?g|png|py|cpp|c|java|kp|kj))?$"),
regexp.MustCompile("^tests(/.*)?$"),
},
},
Expand Down Expand Up @@ -615,10 +615,11 @@ func validateUpdateMaster(
}

for _, solutionSettings := range testsSettings.Solutions {
if solutionEntry := testsTree.EntryByName(solutionSettings.Filename); solutionEntry == nil {
if _, err := testsTree.EntryByPath(solutionSettings.Filename); err != nil {
return base.ErrorWithCategory(
ErrTestsBadLayout,
errors.Errorf(
errors.Wrapf(
err,
"tests/%s is missing",
solutionSettings.Filename,
),
Expand Down
46 changes: 43 additions & 3 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,47 @@ func TestTests(t *testing.T) {
packContents,
[]githttp.PktLineResponse{
{Line: "unpack ok\n", Err: nil},
{Line: "ng refs/heads/master tests-bad-layout: tests/foo.py is missing\n", Err: nil},
{Line: "ng refs/heads/master tests-bad-layout: tests/foo.py is missing: the path 'foo.py' does not exist in the given tree\n", Err: nil},
},
ts,
)
}

// Relative paths.
{
newOid, packContents := createCommit(
t,
tmpDir,
problemAlias,
&git.Oid{},
map[string]io.Reader{
"settings.json": strings.NewReader(gitservertest.DefaultSettingsJSON),
"cases/0.in": strings.NewReader("1 2"),
"cases/0.out": strings.NewReader("3"),
"statements/es.markdown": strings.NewReader("Sumas"),
"solutions/foo.py": strings.NewReader(""),
"tests/tests.json": strings.NewReader(`{
"solutions": [
{
"filename": "../solutions/foo.py"
}
]
}`),
},
"Initial commit",
log,
)
push(
t,
tmpDir,
adminAuthorization,
problemAlias,
"refs/heads/master",
&git.Oid{}, newOid,
packContents,
[]githttp.PktLineResponse{
{Line: "unpack ok\n", Err: nil},
{Line: "ng refs/heads/master tests-bad-layout: tests/../solutions/foo.py is missing: the path '..' does not exist in the given tree\n", Err: nil},
},
ts,
)
Expand Down Expand Up @@ -2495,13 +2535,13 @@ func TestTests(t *testing.T) {
"tests/tests.json": strings.NewReader(`{
"solutions": [
{
"filename": "foo.py",
"filename": "solutions/foo.py",
"score_range": [1, 1],
"verdict": "AC"
}
]
}`),
"tests/foo.py": strings.NewReader("print 1"),
"tests/solutions/foo.py": strings.NewReader("print 1"),
},
"Initial commit",
log,
Expand Down

0 comments on commit ddff938

Please sign in to comment.