aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-04-21 20:59:39 +1000
committerDavid Walter Seikel2014-04-21 20:59:39 +1000
commit9621add2918cc4943e6693b74ae85d51dd264fcf (patch)
treefff1edf2c69d7a08a0e12885eecc9b96ed847a6a /LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua
parentLuaSL_test's window doesn't need to be so huge. (diff)
downloadSledjHamr-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 '')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua158
1 files changed, 0 insertions, 158 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua
deleted file mode 100644
index 4d84055..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua
+++ /dev/null
@@ -1,158 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 test_scripts-5.1.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
25local 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.match(d, "^%s*$") or string.match(d, "^#") then
32 -- comments and empty lines are ignored
33 else
34 flist[#flist+1] = d
35 end
36 end
37 inf:close()
38end
39
40------------------------------------------------------------------------
41-- read in list of files to test
42------------------------------------------------------------------------
43
44local files = {}
45
46loadlist("files-lua-5.1.txt", files)
47loadlist("files-yueliang-5.1.txt", files)
48
49-- pull in personal scripts to test if user specifies "ALL"
50if arg[1] == "ALL" then
51 loadlist("files-other-5.1.txt", files)
52end
53
54-- if you want to specify files in this script itself (not recommended)
55-- you can add them using the following
56--[=[
57for v in string.gmatch([[
58]], "[^%s]+") do
59 table.insert(files, v)
60end
61--]=]
62
63total = 0 -- sum of sizes
64fsize = 0 -- current file size
65
66------------------------------------------------------------------------
67-- initialize
68------------------------------------------------------------------------
69
70dofile("../orig-5.1.2/lzio.lua")
71dofile("../orig-5.1.2/llex.lua")
72dofile("../orig-5.1.2/lopcodes.lua")
73dofile("../orig-5.1.2/ldump.lua")
74dofile("../orig-5.1.2/lcode.lua")
75dofile("../orig-5.1.2/lparser.lua")
76
77function lua_assert(test)
78 if not test then error("assertion failed!") end
79end
80
81luaX:init()
82
83io.stdout:write("\n\n")
84
85------------------------------------------------------------------------
86-- * basic comparison for now; do it properly later
87------------------------------------------------------------------------
88
89local LuaState = {}
90
91------------------------------------------------------------------------
92-- dump binary chunks to a file if something goes wrong
93------------------------------------------------------------------------
94local 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()
99end
100
101------------------------------------------------------------------------
102-- create custom chunk reader (sums up file sizes)
103------------------------------------------------------------------------
104function 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
116end
117
118------------------------------------------------------------------------
119-- attempt to compile Lua source files
120------------------------------------------------------------------------
121for i, filename in ipairs(files) do
122 -- compile a source file
123 local zio = luaZ:init(make_getF(filename), nil)
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, "@"..filename)
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 #bc1 ~= #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 = collectgarbage("count")
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("collectgarbage: "..x.."\n")
153end
154
155-- summaries here
156io.stdout:write("\nTotal file sizes: "..total.."\n")
157
158-- end