Skip to content

Commit 917578d

Browse files
committed
fix(well-formed): properly fmt not-wf
closes #27
1 parent 4222d74 commit 917578d

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

src/graders/well-formed.arr

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ data WFBlock:
4242
| path-doesnt-exist(path :: String)
4343
| path-isnt-file(path :: String)
4444
| cannot-parse(inner :: CA.InternalParseError, content :: String)
45-
| not-wf(x :: Any)
45+
| not-wf(problems :: List<CS.CompileError>)
4646
end
4747

4848
fun check-well-formed(filepath :: String) -> Option<WFBlock>:
@@ -94,7 +94,7 @@ fun fmt-well-formed(reason :: WFBlock) -> GB.ComboAggregate:
9494
"sure you submit a file, not a directory."
9595
| cannot-parse(inner, content) =>
9696
src-available = lam(x):
97-
false # would be nice to embed with src-available
97+
false # TODO: would be nice to embed with src-available
9898
end
9999
exn = inner.exn
100100
msg = inner.message
@@ -104,7 +104,14 @@ fun fmt-well-formed(reason :: WFBlock) -> GB.ComboAggregate:
104104
RED.display-to-string(exn.render-fancy-reason(src-available), to-repr, empty) # TODO: escape
105105
+ "\n\n" + msg + "\n```"
106106

107-
| not-wf(_) => "TODO: not wf"
107+
| not-wf(problems) =>
108+
suf = if problems.length() == 1: "" else: "s" end
109+
"The submitted file has problems. Please make sure that your file can run. " +
110+
"Pyret reported the following problem" + suf + " about your submitted file." +
111+
"\n```" +
112+
for map(problem from problems):
113+
RED.display-to-string(problem.render-fancy-reason(), to-repr, empty)
114+
end.join-str("\n\n--------------------\n")
108115
end ^ G.output-markdown
109116
staff = none
110117
{student; staff}

tests/files/dir/.gitkeep

Whitespace-only changes.

tests/graders/well-formed.arr

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,39 @@ import file("../meta/path-utils.arr") as P
2525
import filesystem as FS
2626

2727
check-well-formed = _check-well-formed
28+
fmt-well-formed = _fmt-well-formed
2829

2930
# TODO: test for file not existing
3031

31-
check "well-formed: unparsable":
32-
path = P.file("unparsable.arr")
33-
34-
# FIXME: how to make this relative to current file
35-
check-well-formed(path)
36-
is
37-
some(cannot-parse(
38-
{
39-
exn: ERR.parse-error-eof(
40-
S.srcloc(path, 3, 1, 13, 3, 1, 13)),
41-
message: "There were 0 potential parses.\n" +
42-
"Parse failed, next token is <end of file> at " + path + ", 3:1-3:1"
43-
},
44-
FS.read-file-string(path)
45-
))
32+
check "well-formed: path-doesnt-exist":
33+
path = P.file("this/file-doesnt/exist/i/hope.arr")
34+
check-well-formed(path) is some(path-doesnt-exist(path))
35+
end
36+
37+
check "well-formed: path-isnt-file":
38+
check-well-formed(P.file("dir")) is some(path-isnt-file(P.file("dir")))
39+
end
40+
41+
expected-unparsable =
42+
let path = P.file("unparsable.arr"):
43+
cannot-parse(
44+
{
45+
exn: ERR.parse-error-eof(
46+
S.srcloc(path, 3, 1, 13, 3, 1, 13)),
47+
message: "There were 0 potential parses.\n" +
48+
"Parse failed, next token is <end of file> at " + path + ", 3:1-3:1"
49+
},
50+
FS.read-file-string(path)
51+
)
52+
end
53+
54+
check "well-formed: cannot-parse":
55+
check-well-formed(P.file("unparsable.arr")) is some(expected-unparsable)
4656
end
4757

4858
check "well-formed: wf":
49-
check-well-formed(P.file("not-wf.arr"))
50-
satisfies
59+
res = check-well-formed(P.file("not-wf.arr"))
60+
res satisfies
5161
{(x): cases(Option) x:
5262
| some(shadow x) =>
5363
cases(WFBlock) x:
@@ -56,4 +66,14 @@ check "well-formed: wf":
5666
| else => false
5767
end
5868
| else => false end}
69+
print(to-repr(fmt-well-formed(res.value)) + "\n")
70+
end
71+
72+
check "fmt-well-formed: smoke":
73+
fmt-well-formed(path-doesnt-exist(
74+
P.file("this/file-doesnt/exist/i/hope.arr"))) does-not-raise
75+
fmt-well-formed(path-doesnt-exist(
76+
P.file("this-file-doesnt-exist-i-hope.arr"))) does-not-raise
77+
fmt-well-formed(path-isnt-file(P.file("dir"))) does-not-raise
78+
fmt-well-formed(expected-unparsable) does-not-raise
5979
end

0 commit comments

Comments
 (0)