main: Add support for passing one or more script directories with '-d'

Tue, 11 Sep 2018 21:12:33 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 11 Sep 2018 21:12:33 +0100
changeset 127
df5aa6a12561
parent 126
87ea077acc21
child 128
d241861a36b4

main: Add support for passing one or more script directories with '-d'

main.lua file | annotate | diff | comparison | revisions
--- a/main.lua	Tue Sep 11 21:02:18 2018 +0100
+++ b/main.lua	Tue Sep 11 21:12:33 2018 +0100
@@ -35,6 +35,9 @@
 	local function get_value()
 		return (assert(table.remove(arg, 1), "unexpected end of command-line options"));
 	end
+
+	local files = {};
+
 	while arg[1] and arg[1]:sub(1,1) == "-" do
 		local opt = arg[1];
 		if opt == "--" then
@@ -82,11 +85,26 @@
 		elseif opt == "--quiet" or opt == "-q" then
 			verse_log_levels = { "error" };
 			quiet = true;
+		elseif opt == "-d" then
+			local have_lfs, lfs = pcall(require, "lfs");
+			if not have_lfs then
+				error("The '-d' parameter requires LuaFileSystem (lfs), please make sure this library is available");
+			end
+			local path = assert(get_value(), "path expected for '-d'"):gsub("/*$", "");
+			for f in lfs.dir(path) do
+				if f:sub(1,1) ~= "." then
+					table.insert(files, path.."/"..f);
+				end
+			end
 		else
 			error("Unhandled command-line option: "..opt);
 		end
 	end
-	assert(#arg > 0, "No test script provided");
+	for _, file in ipairs(arg) do
+		table.insert(files, file);
+	end
+	assert(#files > 0, "No test script provided");
+	return files;
 end
 
 local function read_script(script_name)
@@ -228,7 +246,7 @@
 end
 
 -- Process command-line options
-process_options();
+local files = process_options();
 
 local function console_logger(event, data)
 	if not quiet or type == "test-failed" or type == "test-error" then
@@ -262,6 +280,7 @@
 end;
 
 local function run_test_script(script_name)
+	print(script_name)
 	local script = parse_script(read_script(script_name))
 	log_data("script", { title = script.title, summary = script.summary, tags = script.tags, filename = script_name });
 
@@ -284,8 +303,8 @@
 
 local result_tally = { all = {} };
 
-for i = 1, #arg do
-	local ret = run_test_script(arg[i]);
+for i = 1, #files do
+	local ret = run_test_script(files[i]);
 	if not result_tally[ret.status] then
 		result_tally[ret.status] = {};
 	end

mercurial