diff options
Diffstat (limited to '')
-rw-r--r-- | spec/util/quick.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index c313f575..5c49fff9 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -159,6 +159,16 @@ local function parse(filename) | |||
159 | cur_block = cur_op | 159 | cur_block = cur_op |
160 | cur_block_name = "FILE" | 160 | cur_block_name = "FILE" |
161 | table.insert(stack, "block start") | 161 | table.insert(stack, "block start") |
162 | elseif cmd == "FILE_CONTENTS" then | ||
163 | cur_op = { | ||
164 | op = "FILE_CONTENTS", | ||
165 | name = arg, | ||
166 | data = {}, | ||
167 | } | ||
168 | table.insert(cur_test.ops, cur_op) | ||
169 | cur_block = cur_op | ||
170 | cur_block_name = "FILE_CONTENTS" | ||
171 | table.insert(stack, "block start") | ||
162 | elseif cmd == "RUN" then | 172 | elseif cmd == "RUN" then |
163 | local program, args = arg:match("([^ ]+)%s*(.*)$") | 173 | local program, args = arg:match("([^ ]+)%s*(.*)$") |
164 | if not program then | 174 | if not program then |
@@ -195,6 +205,20 @@ local function parse(filename) | |||
195 | line = cur_line, | 205 | line = cur_line, |
196 | } | 206 | } |
197 | table.insert(cur_test.ops, cur_op) | 207 | table.insert(cur_test.ops, cur_op) |
208 | elseif cmd == "RMDIR" then | ||
209 | cur_op = { | ||
210 | op = "RMDIR", | ||
211 | file = dir.normalize(arg), | ||
212 | line = cur_line, | ||
213 | } | ||
214 | table.insert(cur_test.ops, cur_op) | ||
215 | elseif cmd == "RM" then | ||
216 | cur_op = { | ||
217 | op = "RM", | ||
218 | file = dir.normalize(arg), | ||
219 | line = cur_line, | ||
220 | } | ||
221 | table.insert(cur_test.ops, cur_op) | ||
198 | elseif cmd == "EXIT" then | 222 | elseif cmd == "EXIT" then |
199 | if not cur_op or cur_op.op ~= "RUN" then | 223 | if not cur_op or cur_op.op ~= "RUN" then |
200 | fail("EXIT must be given in the context of a RUN") | 224 | fail("EXIT must be given in the context of a RUN") |
@@ -346,6 +370,28 @@ function quick.compile(filename, env) | |||
346 | op.file = native_slash(op.file) | 370 | op.file = native_slash(op.file) |
347 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) | 371 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) |
348 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | 372 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) |
373 | elseif op.op == "RMDIR" then | ||
374 | op.file = native_slash(op.file) | ||
375 | write(([=[ ok, err = test_env.remove_dir(%q) ]=]):format(op.file)) | ||
376 | write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
377 | elseif op.op == "RM" then | ||
378 | op.file = native_slash(op.file) | ||
379 | write(([=[ ok, err = os.remove(%q) ]=]):format(op.file)) | ||
380 | write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "file", error_message(%d, "RM failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
381 | elseif op.op == "FILE_CONTENTS" then | ||
382 | write(([=[ do ]=])) | ||
383 | write(([=[ local fd_file = assert(io.open(%q, "rb")) ]=]):format(op.name)) | ||
384 | write(([=[ local file_data = fd_file:read("*a") ]=])) | ||
385 | write(([=[ fd_file:close() ]=])) | ||
386 | write([=[ local block_at = 1 ]=]) | ||
387 | write([=[ local s, e, line ]=]) | ||
388 | for i, line in ipairs(op.data) do | ||
389 | write(([=[ line = %q ]=]):format(line)) | ||
390 | write(([=[ s, e = string.find(file_data, line, 1, true) ]=])) | ||
391 | write(([=[ assert(s, error_message(%d, "FILE_CONTENTS %s did not match: " .. line, file_data)) ]=]):format(op.start + i, op.name)) | ||
392 | write(([=[ block_at = e + 1 ]=]):format(i)) | ||
393 | end | ||
394 | write([=[ end ]=]) | ||
349 | elseif op.op == "RUN" then | 395 | elseif op.op == "RUN" then |
350 | local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) | 396 | local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) |
351 | local redirs = " 1>stdout.txt 2>stderr.txt " | 397 | local redirs = " 1>stdout.txt 2>stderr.txt " |