diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua new file mode 100644 index 0000000..53a3ae3 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua | |||
@@ -0,0 +1,158 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_scripts-5.0.lua | ||
4 | Compile and compare Lua files | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2005-2007 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 | -- NOTE | ||
17 | -- * use the argument ALL to pull in additional personal Lua scripts | ||
18 | -- for testing, e.g. lua test_scripts.lua ALL | ||
19 | ----------------------------------------------------------------------]] | ||
20 | |||
21 | ------------------------------------------------------------------------ | ||
22 | -- reads in a list of files to crunch from a text file | ||
23 | ------------------------------------------------------------------------ | ||
24 | |||
25 | local function loadlist(fname, flist) | ||
26 | local inf = io.open(fname, "r") | ||
27 | if not inf then error("cannot open "..fname.." for reading") end | ||
28 | while true do | ||
29 | local d = inf:read("*l") | ||
30 | if not d then break end | ||
31 | if string.find(d, "^%s*$") or string.find(d, "^#") then | ||
32 | -- comments and empty lines are ignored | ||
33 | else | ||
34 | table.insert(flist, d) | ||
35 | end | ||
36 | end | ||
37 | inf:close() | ||
38 | end | ||
39 | |||
40 | ------------------------------------------------------------------------ | ||
41 | -- read in list of files to test | ||
42 | ------------------------------------------------------------------------ | ||
43 | |||
44 | local files = {} | ||
45 | |||
46 | loadlist("files-lua-5.0.txt", files) | ||
47 | loadlist("files-yueliang-5.0.txt", files) | ||
48 | |||
49 | -- pull in personal scripts to test if user specifies "ALL" | ||
50 | if arg[1] == "ALL" then | ||
51 | loadlist("files-other-5.0.txt", files) | ||
52 | end | ||
53 | |||
54 | -- if you want to specify files in this script itself (not recommended) | ||
55 | -- you can add them using the following | ||
56 | --[[ | ||
57 | for v in string.gfind([[ | ||
58 | ]], "[^%s]+") do | ||
59 | table.insert(files, v) | ||
60 | end | ||
61 | --]] | ||
62 | |||
63 | total = 0 -- sum of sizes | ||
64 | fsize = 0 -- current file size | ||
65 | |||
66 | ------------------------------------------------------------------------ | ||
67 | -- initialize | ||
68 | ------------------------------------------------------------------------ | ||
69 | |||
70 | require("../orig-5.0.3/lzio") | ||
71 | require("../orig-5.0.3/llex") | ||
72 | require("../orig-5.0.3/lopcodes") | ||
73 | require("../orig-5.0.3/ldump") | ||
74 | require("../orig-5.0.3/lcode") | ||
75 | require("../orig-5.0.3/lparser") | ||
76 | |||
77 | function lua_assert(test) | ||
78 | if not test then error("assertion failed!") end | ||
79 | end | ||
80 | |||
81 | luaX:init() | ||
82 | |||
83 | io.stdout:write("\n\n") | ||
84 | |||
85 | ------------------------------------------------------------------------ | ||
86 | -- * basic comparison for now; do it properly later | ||
87 | ------------------------------------------------------------------------ | ||
88 | |||
89 | local LuaState = {} | ||
90 | |||
91 | ------------------------------------------------------------------------ | ||
92 | -- dump binary chunks to a file if something goes wrong | ||
93 | ------------------------------------------------------------------------ | ||
94 | local function Dump(data, filename) | ||
95 | h = io.open(filename, "wb") | ||
96 | if not h then error("failed to open "..filename.." for writing") end | ||
97 | h:write(data) | ||
98 | h:close() | ||
99 | end | ||
100 | |||
101 | ------------------------------------------------------------------------ | ||
102 | -- create custom chunk reader (sums up file sizes) | ||
103 | ------------------------------------------------------------------------ | ||
104 | function make_getF(filename) | ||
105 | local h = io.open(filename, "r") | ||
106 | if not h then return nil end | ||
107 | fsize = h:seek("end") | ||
108 | h:seek("set") | ||
109 | total = total + fsize | ||
110 | return function() -- chunk reader anonymous function here | ||
111 | if not h then return nil end | ||
112 | local buff = h:read(512) | ||
113 | if not buff then h:close() end | ||
114 | return buff | ||
115 | end | ||
116 | end | ||
117 | |||
118 | ------------------------------------------------------------------------ | ||
119 | -- attempt to compile Lua source files | ||
120 | ------------------------------------------------------------------------ | ||
121 | for i, filename in ipairs(files) do | ||
122 | -- compile a source file | ||
123 | local zio = luaZ:init(make_getF(filename), nil, "@"..filename) | ||
124 | if not zio then | ||
125 | error("could not initialize zio stream for "..filename) | ||
126 | end | ||
127 | io.stdout:write(filename.."("..fsize.."): ") | ||
128 | local Func = luaY:parser(LuaState, zio, nil) | ||
129 | local Writer, Buff = luaU:make_setS() | ||
130 | luaU:dump(LuaState, Func, Writer, Buff) | ||
131 | local bc1 = Buff.data -- Yueliang's output | ||
132 | |||
133 | local f = loadfile(filename) | ||
134 | local bc2 = string.dump(f) -- Lua's output | ||
135 | |||
136 | -- compare outputs | ||
137 | if string.len(bc1) ~= string.len(bc2) then | ||
138 | Dump(bc1, "bc1.out") | ||
139 | Dump(bc2, "bc2.out") | ||
140 | error("binary chunk sizes different") | ||
141 | elseif bc1 ~= bc2 then | ||
142 | Dump(bc1, "bc1.out") | ||
143 | Dump(bc2, "bc2.out") | ||
144 | error("binary chunks different") | ||
145 | else | ||
146 | io.stdout:write("CORRECT\n") | ||
147 | end | ||
148 | local x, y = gcinfo() | ||
149 | -- memory usage isn't really a problem for the straight port | ||
150 | -- string handling in Lua that follows the original C closely is more | ||
151 | -- of a problem, but this will be fixed elsewhere, not in this tree | ||
152 | --io.stdout:write("gcinfo: "..x.." "..y.."\n") | ||
153 | end | ||
154 | |||
155 | -- summaries here | ||
156 | io.stdout:write("\nTotal file sizes: "..total.."\n") | ||
157 | |||
158 | -- end | ||