clone url: git://git.m455.casa/fa
esperbuild/espersrc/fennel-0.7.0/test/failures.fnl
1 | (local l (require :test.luaunit)) |
2 | (local fennel (require :fennel)) |
3 |
|
4 | (local failures { |
5 | "\n\n(+))" "unknown:3: unexpected closing delimiter )" |
6 | "\n\n(let [f (lambda []\n(local))] (f))" "4: expected name and value" |
7 | "\n\n(let [x.y 9] nil)" "unknown:3: unexpected multi" |
8 | "\n(when)" "Compile error in 'when' unknown:2" |
9 | "((fn [] (require-macros \"test.macros\") (global x1 (->1 99 (+ 31))))) |
10 | (->1 23 (+ 1))" "unknown global in strict mode" |
11 | "()" "expected a function, macro, or special" |
12 | "(789)" "cannot call literal value" |
13 | "(do\n\n\n(each \n[x (pairs {})] (when)))" "when' unknown:5:" |
14 | "(do\n\n\n(each \n[x 34 (pairs {})] 21))" "5: unable to bind number 34" |
15 | "(each [k v (pairs {})] (BAD k v))" "BAD" |
16 | "(f" "unknown:1: expected closing delimiter )" |
17 | "(fn [12])" "expected symbol for function parameter" |
18 | "(fn [:huh] 4)" "expected symbol for function parameter" |
19 | "(fn []\n(for [32 34 32] 21))" "2: unable to bind number" |
20 | "(fn [] [...])" "unexpected vararg" |
21 | "(fn [false] 4)" "expected symbol for function parameter" |
22 | "(fn [nil] 4)" "expected symbol for function parameter" |
23 | "(fn global [] 1)" "overshadowed" |
24 | "(fn global-caller [] (hey))" "unknown global" |
25 | "(fn)" "expected parameters" |
26 | "(global + 1)" "overshadowed" |
27 | "(global - 1)" "overshadowed" |
28 | "(global // 1)" "overshadowed" |
29 | "(global 48 :forty-eight)" "unable to bind number 48" |
30 | "(global good (fn [] nil)) (good) (BAD)" "BAD" |
31 | "(global let 1)" "overshadowed" |
32 | "(hey)" "unknown global" |
33 | "(lambda x)" "expected arg list" |
34 | "(let [:x 1] 1)" "unable to bind" |
35 | "(let [[a & c d] [1 2]] c)" "rest argument before last parameter" |
36 | "(let [b 9\nq (.)] q)" "2: expected table argument" |
37 | "(let [bl 8 a bcd] nil)" "unknown global" |
38 | "(let [false 1] 9)" "unable to bind boolean false" |
39 | "(let [global 1] 1)" "overshadowed" |
40 | "(let [next #(next $)] print)" "aliased by a local" |
41 | "(let [nil 1] 9)" "unable to bind" |
42 | "(let [pairs #(pairs $)] pairs)" "aliased by a local" |
43 | "(let [t []] (set t.47 :forty-seven))" "can't start multisym segment with a digit: t.47" |
44 | "(let [t []] (set t.:x :y))" "malformed multisym: t.:x" |
45 | "(let [t []] (set t:.x :y))" "malformed multisym: t:.x" |
46 | "(let [t []] (set t::x :y))" "malformed multisym: t::x" |
47 | "(let [t {:a 1}] (+ t.a BAD))" "BAD" |
48 | "(let [x 1 y] 8)" "expected even number of name/value bindings" |
49 | "(let [x 1] (set-forcibly! x 2) (set x 3) x)" "expected var" |
50 | "(let [x 1])" "expected body" |
51 | "(let [x {:foo (fn [self] self.bar) :bar :baz}] x:foo)" "multisym method calls may only be in call position" |
52 | "(let [x {:y {:foo (fn [self] self.bar) :bar :baz}}] x:y:foo)" "method must be last component of multisym: x:y:foo" |
53 | "(local 47 :forty-seven)" "unable to bind number 47" |
54 | "(local a-b 1) (global [a_b] [2])" "global a_b conflicts with local" |
55 | "(local a-b 1) (global a_b 2)" "global a_b conflicts with local" |
56 | "(local a~b 3)" "illegal character: ~" |
57 | "(local ipairs #(ipairs $))" "aliased by a local" |
58 | "(macros {:m (fn [t] `(each [mykey (pairs ,t)] (print mykey)))}) (m [])" "tried to bind mykey without gensym" |
59 | "(macros {:m (fn [t] `(fn [xabc] (+ xabc 9)))}) ((m 4))" "tried to bind xabc without gensym" |
60 | "(macros {:m (fn [y] `(let [x 1] (+ x ,y)))}) (m 4)" "tried to bind x without gensym" |
61 | "(match [1 2 3] [a & b c] nil)" "rest argument before last parameter" |
62 | "(not true false)" "expected one argument" |
63 | "(print @)" "illegal character: @" |
64 | "(set [a b c] [1 2 3]) (+ a b c)" "expected local" |
65 | "(set a 19)" "error in 'a' unknown:1: expected local" |
66 | "(set)" "Compile error in 'set' unknown:1: expected name and value" |
67 | "(x(y))" "expected whitespace before opening delimiter (" |
68 | "(x[1 2])" "expected whitespace before opening delimiter [" |
69 | "(fn abc:def [x] (+ x 2))" "unexpected multi symbol abc:def" |
70 | "(macros {:foo {:bar (fn [] `(print :test))}})" "expected each macro to be function" |
71 | "(import-macros test :test.macros) (test.asdf)" "macro not found in imported macro module" |
72 | "(import-macros {: asdf} :test.macros)" "macro asdf not found in module test.macros" |
73 | "(with-open [(x y z) (values 1 2 3)])" "with-open only allows symbols in bindings" |
74 | "#[$ $...] 1 2 3" "$ and $... in hashfn are mutually exclusive" |
75 | }) |
76 |
|
77 | (fn test-failures [] |
78 | (each [code expected-msg (pairs failures)] |
79 | (let [(ok? msg) (pcall fennel.compileString code |
80 | {:allowedGlobals ["pairs" "next" "ipairs"] |
81 | :unfriendly true})] |
82 | (l.assertFalse ok? (.. "Expected compiling " code " to fail.")) |
83 | (l.assertStrContains msg expected-msg)))) |
84 |
|
85 | ;; automated tests for suggestions are rudimentary because the usefulness of the |
86 | ;; output is so subjective. to see a full catalog of suggestions, run the script |
87 | ;; test/bad/friendly.sh and review that output. |
88 | (fn test-suggestions [] |
89 | (let [(_ msg) (pcall fennel.dofile "test/bad/set-local.fnl") |
90 | (_ parse-msg) (pcall fennel.dofile "test/bad/odd-table.fnl")] |
91 | ;; show the raw error message |
92 | (l.assertStrContains msg "expected var x") |
93 | ;; offer suggestions |
94 | (l.assertStrContains msg "Try declaring x using var") |
95 | ;; show the code and point out the identifier at fault |
96 | (l.assertStrContains msg "(set x 3)") |
97 | (l.assertStrContains msg "\n ^") |
98 | ;; parse error |
99 | (l.assertStrContains parse-msg "{:a 1 :b 2 :c}"))) |
100 |
|
101 | {: test-failures : test-suggestions} |