diff options
author | Alexey Melnichuk <mimir@newmail.ru> | 2015-04-03 16:50:42 +0400 |
---|---|---|
committer | Alexey Melnichuk <mimir@newmail.ru> | 2015-04-03 16:50:42 +0400 |
commit | 75a319a5e7d251bc18994fad56749017f8fac993 (patch) | |
tree | f005968dcba8488200036db18963e088db67c5c2 /test | |
parent | 0b5ddda597e3cab29d04918319b52673695ee2d2 (diff) | |
download | lua-llthreads2-75a319a5e7d251bc18994fad56749017f8fac993.tar.gz lua-llthreads2-75a319a5e7d251bc18994fad56749017f8fac993.tar.bz2 lua-llthreads2-75a319a5e7d251bc18994fad56749017f8fac993.zip |
Add. Test for multiple prelude.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_threads_ex_opt_2.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/test_threads_ex_opt_2.lua b/test/test_threads_ex_opt_2.lua new file mode 100644 index 0000000..b01eda5 --- /dev/null +++ b/test/test_threads_ex_opt_2.lua | |||
@@ -0,0 +1,38 @@ | |||
1 | local thread_code = function(...) | ||
2 | local function assert_equal(name, a, b, ...) | ||
3 | if a == b then return b, ... end | ||
4 | print(name .. " Fail! Expected `" .. tostring(a) .. "` got `" .. tostring(b) .. "`") | ||
5 | os.exit(1) | ||
6 | end | ||
7 | |||
8 | local a,b,c,d = ... | ||
9 | assert_equal("1:", 1, a ) | ||
10 | assert_equal("2:", 2, b ) | ||
11 | assert_equal("3:", 3, c ) | ||
12 | assert_equal("4:", 4, d ) | ||
13 | assert_equal("#:", 4, select("#", ...)) | ||
14 | end | ||
15 | |||
16 | local llthreads = require"llthreads.ex" | ||
17 | |||
18 | local prelude1 = function(...) return 1, ... end | ||
19 | |||
20 | local prelude2 = function(...) return 2, ... end | ||
21 | |||
22 | local prelude = string.format([[ | ||
23 | local loadstring = loadstring or load | ||
24 | local prelude1 = loadstring(%q) | ||
25 | local prelude2 = loadstring(%q) | ||
26 | return prelude1(prelude2(...)) | ||
27 | ]], string.dump(prelude1), string.dump(prelude2)) | ||
28 | |||
29 | -- pass `prelude` function that change thread arguments | ||
30 | local thread = llthreads.new({thread_code, prelude = prelude}, 3, 4) | ||
31 | |||
32 | local a = assert(thread:start()) | ||
33 | |||
34 | assert(thread:join()) | ||
35 | |||
36 | assert(a == thread) | ||
37 | |||
38 | print("done!") | ||