aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua159
1 files changed, 0 insertions, 159 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua
deleted file mode 100644
index c135a8c..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua
+++ /dev/null
@@ -1,159 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 test_lparser_mk2_2.lua
4 Test for lparser_mk2.lua, using the test case file
5 This file is part of Yueliang.
6
7 Copyright (c) 2006-2008 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-- * unlike the equivalent in the orig-5.1.3/ directory, this version
18-- tests only parsing, lparser_mk3 cannot generate binary chunks
19-- * the test cases are in the test_lua directory (test_parser-5.1.lua)
20----------------------------------------------------------------------]]
21
22-- * true if you want an output of all failure cases in native Lua,
23-- for checking whether test cases fail where you intend them to
24local DEBUG_FAILS = false
25
26------------------------------------------------------------------------
27-- test the whole kaboodle
28------------------------------------------------------------------------
29
30package.path = "../?.lua;"..package.path
31local llex = require "llex_mk2"
32local lparser = require "lparser_mk2"
33
34------------------------------------------------------------------------
35-- load test cases
36------------------------------------------------------------------------
37
38dofile("../../test_lua/test_parser-5.1.lua")
39
40local test, expect, heading = {}, {}, {}
41local total, total_pass, total_fail = 0, 0, 0
42
43for ln in string.gfind(tests_source, "([^\n]*)\n") do
44 if string.find(ln, "^%s*%-%-") then
45 -- comment, ignore
46 else
47 local m, _, head = string.find(ln, "^%s*(TESTS:%s*.*)$")
48 if m then
49 heading[total + 1] = head -- informational heading
50 else
51 total = total + 1
52 local n, _, flag = string.find(ln, "%s*%-%-%s*FAIL%s*$")
53 if n then -- FAIL test case
54 ln = string.sub(ln, 1, n - 1) -- remove comment
55 expect[total] = "FAIL"
56 total_fail = total_fail + 1
57 else -- PASS test case
58 expect[total] = "PASS"
59 total_pass = total_pass + 1
60 end--n
61 test[total] = ln
62 end--m
63 end--ln
64end--for
65
66print("Tests loaded: "..total.." (total), "
67 ..total_pass.." (passes), "
68 ..total_fail.." (fails)")
69
70------------------------------------------------------------------------
71-- verify test cases using native Lua
72------------------------------------------------------------------------
73
74local last_head = "TESTS: no heading yet"
75for i = 1, total do
76 local test_case, expected, head = test[i], expect[i], heading[i]
77 -- show progress
78 if head then
79 last_head = head
80 if DEBUG_FAILS then print("\n"..head.."\n") end
81 end
82 ------------------------------------------------------------------
83 -- perform test
84 local f, err = loadstring(test_case)
85 -- look at outcome
86 ------------------------------------------------------------------
87 if f then-- actual PASS
88 if expected == "FAIL" then
89 print("\nVerified as PASS but expected to FAIL"..
90 "\n-------------------------------------")
91 print("Lastest heading: "..last_head)
92 print("TEST: "..test_case)
93 os.exit()
94 end
95 ------------------------------------------------------------------
96 else-- actual FAIL
97 if expected == "PASS" then
98 print("\nVerified as FAIL but expected to PASS"..
99 "\n-------------------------------------")
100 print("Lastest heading: "..last_head)
101 print("TEST: "..test_case)
102 print("ERROR: "..err)
103 os.exit()
104 end
105 if DEBUG_FAILS then
106 print("TEST: "..test_case)
107 print("ERROR: "..err.."\n")
108 end
109 ------------------------------------------------------------------
110 end--f
111end--for
112
113print("Test cases verified using native Lua, no anomalies.")
114
115------------------------------------------------------------------------
116-- test using Yueliang front end
117------------------------------------------------------------------------
118
119local last_head = "TESTS: no heading yet"
120for i = 1, total do
121 local test_case, expected, head = test[i], expect[i], heading[i]
122 -- show progress
123 if head then last_head = head end
124 ------------------------------------------------------------------
125 -- perform test
126 llex.init(test_case, "=test_sample")
127 lparser.init(llex)
128
129 local status, func = pcall(lparser.parser)
130 -- look at outcome
131 ------------------------------------------------------------------
132 if status then-- actual PASS
133 if expected == "FAIL" then
134 print("\nTested as PASS but expected to FAIL"..
135 "\n-----------------------------------")
136 print("Lastest heading: "..last_head)
137 print("TEST: "..test_case)
138 os.exit()
139 end
140 ------------------------------------------------------------------
141 else-- actual FAIL
142 if expected == "PASS" then
143 print("\nTested as FAIL but expected to PASS"..
144 "\n-----------------------------------")
145 print("Lastest heading: "..last_head)
146 print("TEST: "..test_case)
147 os.exit()
148 else
149 io.stdout:write("-")
150 end
151 ------------------------------------------------------------------
152 end--status
153 io.stdout:write("\rTesting ["..i.."]...")
154end--for
155print(" done.")
156
157print("Test cases run on Yueliang, no anomalies.")
158
159-- end