Diff

spec/util_envload_spec.lua @ 11489:37f49d0ad22c

util.envload: Add basic test of envload()
author Kim Alvefur <zash@zash.se>
date Fri, 26 Mar 2021 13:03:22 +0100
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec/util_envload_spec.lua	Fri Mar 26 13:03:22 2021 +0100
@@ -0,0 +1,22 @@
+describe("util.envload", function()
+	local envload = require "util.envload";
+	describe("envload()", function()
+		it("works", function()
+			local f, err = envload.envload("return 'hello'", "@test", {});
+			assert.is_function(f, err);
+			local ok, ret = pcall(f);
+			assert.truthy(ok);
+			assert.equal("hello", ret);
+		end);
+		it("lets you pass values in and out", function ()
+			local f, err = envload.envload("return thisglobal", "@test", { thisglobal = "yes, this one" });
+			assert.is_function(f, err);
+			local ok, ret = pcall(f);
+			assert.truthy(ok);
+			assert.equal("yes, this one", ret);
+
+		end);
+
+	end)
+	-- TODO envloadfile()
+end)