main: Add support for including/excluding tests based on tag

Wed, 12 Sep 2018 11:37:55 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 12 Sep 2018 11:37:55 +0100
changeset 150
cf2b2fcd0bc1
parent 149
b2e397594cbd
child 151
8191f165b9dd

main: Add support for including/excluding tests based on tag

main.lua file | annotate | diff | comparison | revisions
--- a/main.lua	Wed Sep 12 11:37:33 2018 +0100
+++ b/main.lua	Wed Sep 12 11:37:55 2018 +0100
@@ -17,6 +17,7 @@
 local quiet = false;
 local force_summary = false;
 local serve_mode = false;
+local only_tags, skip_tags;
 
 local property_rules = {};
 
@@ -71,14 +72,28 @@
 			skip_server_startup_log = true;
 		elseif opt == "--step-timeout" then
 			action_timeout = assert(tonumber(get_value()), "number expected for --step-timeout");
-		elseif opt == "--tag" then
+		elseif opt == "--meta" then
 			local tag = get_value();
 			local key, value = tag:match("^([^=]+):(.+)$");
 			if key and value then
 				test_metadata[key] = value;
 			else
-				error("Unable to parse tag: "..tag);
+				error("Unable to parse metadata: "..tag);
+			end
+		elseif opt == "--with-tag" then
+			if not only_tags then
+				only_tags = {};
 			end
+			local tag = get_value();
+			local key, value = tag:match("^([^=]+):(.+)$");
+			table.insert(only_tags, { key or tag, value });
+		elseif opt == "--skip-tag" then
+			if not skip_tags then
+				skip_tags = {};
+			end
+			local tag = get_value();
+			local key, value = tag:match("^([^=]+):(.+)$");
+			table.insert(skip_tags, { key or tag, value });
 		elseif opt == "--verbose" or opt == "-v" then
 			verse_log_levels = { "debug", "info", "warn", "error" };
 			quiet = false;
@@ -283,6 +298,26 @@
 local function run_test_script(script_name, script_text)
 	local script = parse_script(script_text)
 	local script_data = { title = script.title, summary = script.summary, tags = script.tags, filename = script_name };
+
+	local tags = script.tags or {};
+	if skip_tags then
+		for _, skip in ipairs(skip_tags) do
+			local k, v = skip[1], skip[2];
+			if tags[k] and (not(v) or tags[k] == v) then
+				return { name = script.title or script.name, status = "skipped", reason = "skipping tag "..k };
+			end
+		end
+	end
+	if only_tags then
+		for _, only in ipairs(only_tags) do
+			local k, v = only[1], only[2];
+			if not tags[k] or (v and tags[k] ~= v) then
+				print(k, v, tags[k])
+				return { name = script.title or script.name, status = "skipped", reason = "not tagged "..k };
+			end
+		end
+	end
+
 	log_data("script", script_data);
 
 	local ok, result, err = pcall(main, log_data, script);

mercurial