diff options
Diffstat (limited to 'tests/error.lua')
-rw-r--r-- | tests/error.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/error.lua b/tests/error.lua new file mode 100644 index 0000000..673bcb5 --- /dev/null +++ b/tests/error.lua | |||
@@ -0,0 +1,47 @@ | |||
1 | -- | ||
2 | -- Error reporting | ||
3 | -- | ||
4 | -- Note: this code is supposed to end in errors; not included in 'make test' | ||
5 | -- | ||
6 | |||
7 | require "lanes" | ||
8 | |||
9 | local function lane() | ||
10 | |||
11 | local subf= function() -- this so that we can see the call stack | ||
12 | --error "aa" | ||
13 | error({}) | ||
14 | error(error) | ||
15 | end | ||
16 | local subf2= function() | ||
17 | subf() | ||
18 | end | ||
19 | subf2() | ||
20 | end | ||
21 | |||
22 | local function cleanup(err) | ||
23 | end | ||
24 | |||
25 | local lgen = lanes.gen("*", { --[[finalizer=cleanup]] }, lane) | ||
26 | |||
27 | --- | ||
28 | io.stderr:write( "\n** Error catching **\n" ) | ||
29 | -- | ||
30 | local h= lgen() | ||
31 | local _,err,stack= h:join() -- wait for the lane (no automatic error propagation) | ||
32 | |||
33 | if err then | ||
34 | assert( type(stack)=="table" ) | ||
35 | io.stderr:write( "Lane error: "..tostring(err).."\n" ) | ||
36 | |||
37 | io.stderr:write( "\t", table.concat(stack,"\n\t"), "\n" ); | ||
38 | end | ||
39 | |||
40 | --- | ||
41 | io.stderr:write( "\n** Error propagation **\n" ) | ||
42 | -- | ||
43 | local h2= lgen() | ||
44 | local _= h2[0] | ||
45 | assert(false) -- does NOT get here | ||
46 | |||
47 | --never ends | ||