diff options
author | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
commit | 9621add2918cc4943e6693b74ae85d51dd264fcf (patch) | |
tree | fff1edf2c69d7a08a0e12885eecc9b96ed847a6a /LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/test/test_lparser2.lua | |
parent | LuaSL_test's window doesn't need to be so huge. (diff) | |
download | SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.zip SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.gz SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.bz2 SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.xz |
We don't need the testlua directory any more.
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/test/test_lparser2.lua')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/test/test_lparser2.lua | 202 |
1 files changed, 0 insertions, 202 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/test/test_lparser2.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/test/test_lparser2.lua deleted file mode 100644 index e9fa188..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/test/test_lparser2.lua +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_lparser2.lua | ||
4 | Test for lparser.lua, using the test case file | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net> | ||
8 | The COPYRIGHT file describes the conditions | ||
9 | under which this software may be distributed. | ||
10 | |||
11 | See the ChangeLog for more information. | ||
12 | |||
13 | ----------------------------------------------------------------------]] | ||
14 | |||
15 | --[[-------------------------------------------------------------------- | ||
16 | -- Notes: | ||
17 | -- * the test cases are in the test_lua directory (test_parser-5.1.lua) | ||
18 | ----------------------------------------------------------------------]] | ||
19 | |||
20 | -- * true if you want an output of all failure cases in native Lua, | ||
21 | -- for checking whether test cases fail where you intend them to | ||
22 | local DEBUG_FAILS = false | ||
23 | |||
24 | ------------------------------------------------------------------------ | ||
25 | -- test the whole kaboodle | ||
26 | ------------------------------------------------------------------------ | ||
27 | |||
28 | dofile("../lzio.lua") | ||
29 | dofile("../llex.lua") | ||
30 | dofile("../lopcodes.lua") | ||
31 | dofile("../ldump.lua") | ||
32 | dofile("../lcode.lua") | ||
33 | dofile("../lparser.lua") | ||
34 | |||
35 | function lua_assert(test) | ||
36 | if not test then error("assertion failed!") end | ||
37 | end | ||
38 | |||
39 | luaX:init() | ||
40 | |||
41 | ------------------------------------------------------------------------ | ||
42 | -- load test cases | ||
43 | ------------------------------------------------------------------------ | ||
44 | |||
45 | dofile("../../test_lua/test_parser-5.1.lua") | ||
46 | |||
47 | local test, expect, heading = {}, {}, {} | ||
48 | local total, total_pass, total_fail = 0, 0, 0 | ||
49 | |||
50 | for ln in string.gmatch(tests_source, "([^\n]*)\n") do | ||
51 | if string.find(ln, "^%s*%-%-") then | ||
52 | -- comment, ignore | ||
53 | else | ||
54 | local m, _, head = string.find(ln, "^%s*(TESTS:%s*.*)$") | ||
55 | if m then | ||
56 | heading[total + 1] = head -- informational heading | ||
57 | else | ||
58 | total = total + 1 | ||
59 | local n, _, flag = string.find(ln, "%s*%-%-%s*FAIL%s*$") | ||
60 | if n then -- FAIL test case | ||
61 | ln = string.sub(ln, 1, n - 1) -- remove comment | ||
62 | expect[total] = "FAIL" | ||
63 | total_fail = total_fail + 1 | ||
64 | else -- PASS test case | ||
65 | expect[total] = "PASS" | ||
66 | total_pass = total_pass + 1 | ||
67 | end--n | ||
68 | test[total] = ln | ||
69 | end--m | ||
70 | end--ln | ||
71 | end--for | ||
72 | |||
73 | print("Tests loaded: "..total.." (total), " | ||
74 | ..total_pass.." (passes), " | ||
75 | ..total_fail.." (fails)") | ||
76 | |||
77 | ------------------------------------------------------------------------ | ||
78 | -- verify test cases using native Lua | ||
79 | ------------------------------------------------------------------------ | ||
80 | |||
81 | local last_head = "TESTS: no heading yet" | ||
82 | for i = 1, total do | ||
83 | local test_case, expected, head = test[i], expect[i], heading[i] | ||
84 | -- show progress | ||
85 | if head then | ||
86 | last_head = head | ||
87 | if DEBUG_FAILS then print("\n"..head.."\n") end | ||
88 | end | ||
89 | ------------------------------------------------------------------ | ||
90 | -- perform test | ||
91 | local f, err = loadstring(test_case) | ||
92 | -- look at outcome | ||
93 | ------------------------------------------------------------------ | ||
94 | if f then-- actual PASS | ||
95 | if expected == "FAIL" then | ||
96 | print("\nVerified as PASS but expected to FAIL".. | ||
97 | "\n-------------------------------------") | ||
98 | print("Lastest heading: "..last_head) | ||
99 | print("TEST: "..test_case) | ||
100 | os.exit() | ||
101 | end | ||
102 | ------------------------------------------------------------------ | ||
103 | else-- actual FAIL | ||
104 | if expected == "PASS" then | ||
105 | print("\nVerified as FAIL but expected to PASS".. | ||
106 | "\n-------------------------------------") | ||
107 | print("Lastest heading: "..last_head) | ||
108 | print("TEST: "..test_case) | ||
109 | print("ERROR: "..err) | ||
110 | os.exit() | ||
111 | end | ||
112 | if DEBUG_FAILS then | ||
113 | print("TEST: "..test_case) | ||
114 | print("ERROR: "..err.."\n") | ||
115 | end | ||
116 | ------------------------------------------------------------------ | ||
117 | end--f | ||
118 | end--for | ||
119 | |||
120 | print("Test cases verified using native Lua, no anomalies.") | ||
121 | |||
122 | ------------------------------------------------------------------------ | ||
123 | -- dump binary chunks to a file if something goes wrong | ||
124 | ------------------------------------------------------------------------ | ||
125 | local function Dump(data, filename) | ||
126 | h = io.open(filename, "wb") | ||
127 | if not h then error("failed to open "..filename.." for writing") end | ||
128 | h:write(data) | ||
129 | h:close() | ||
130 | end | ||
131 | |||
132 | ------------------------------------------------------------------------ | ||
133 | -- test using Yueliang front end | ||
134 | ------------------------------------------------------------------------ | ||
135 | |||
136 | local last_head = "TESTS: no heading yet" | ||
137 | for i = 1, total do | ||
138 | local test_case, expected, head = test[i], expect[i], heading[i] | ||
139 | -- show progress | ||
140 | if head then last_head = head end | ||
141 | ------------------------------------------------------------------ | ||
142 | -- perform test | ||
143 | local LuaState = {} | ||
144 | local zio = luaZ:init(luaZ:make_getS(test_case), nil) | ||
145 | local status, func = pcall(luaY.parser, luaY, LuaState, zio, nil, "test") | ||
146 | -- look at outcome | ||
147 | ------------------------------------------------------------------ | ||
148 | if status then-- actual PASS | ||
149 | if expected == "PASS" then | ||
150 | -- actual PASS and expected PASS, so check binary chunks | ||
151 | local writer, buff = luaU:make_setS() | ||
152 | luaU:dump(LuaState, func, writer, buff) | ||
153 | local bc1 = buff.data -- Yueliang's output | ||
154 | local f = loadstring(test_case, "test") | ||
155 | local bc2 = string.dump(f) -- Lua's output | ||
156 | local die | ||
157 | -- compare outputs | ||
158 | if #bc1 ~= #bc2 then | ||
159 | Dump(bc1, "bc1.out") | ||
160 | Dump(bc2, "bc2.out") | ||
161 | die = "binary chunk sizes different" | ||
162 | elseif bc1 ~= bc2 then | ||
163 | Dump(bc1, "bc1.out") | ||
164 | Dump(bc2, "bc2.out") | ||
165 | die = "binary chunks different" | ||
166 | else | ||
167 | -- everything checks out! | ||
168 | end | ||
169 | if die then | ||
170 | print("\nTested PASS and expected to PASS, but chunks different".. | ||
171 | "\n------------------------------------------------------") | ||
172 | print("Reason: "..die) | ||
173 | print("Lastest heading: "..last_head) | ||
174 | print("TEST: "..test_case) | ||
175 | os.exit() | ||
176 | end | ||
177 | else-- expected FAIL | ||
178 | print("\nTested as PASS but expected to FAIL".. | ||
179 | "\n-----------------------------------") | ||
180 | print("Lastest heading: "..last_head) | ||
181 | print("TEST: "..test_case) | ||
182 | os.exit() | ||
183 | end | ||
184 | ------------------------------------------------------------------ | ||
185 | else-- actual FAIL | ||
186 | if expected == "PASS" then | ||
187 | print("\nTested as FAIL but expected to PASS".. | ||
188 | "\n-----------------------------------") | ||
189 | print("Lastest heading: "..last_head) | ||
190 | print("TEST: "..test_case) | ||
191 | print("ERROR: "..err) | ||
192 | os.exit() | ||
193 | end | ||
194 | ------------------------------------------------------------------ | ||
195 | end--status | ||
196 | io.stdout:write("\rTesting ["..i.."]...") | ||
197 | end--for | ||
198 | print(" done.") | ||
199 | |||
200 | print("Test cases run on Yueliang, no anomalies.") | ||
201 | |||
202 | -- end | ||