From a25ad236ae5368950bdb133aab64169724ebdd28 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 31 Jan 2018 15:29:04 -0800 Subject: [PATCH] Start implementing tests, add lemur and testez dependencies --- .gitmodules | 6 ++++ .luacheckrc | 19 +----------- lib/Promise.spec.lua | 42 ++++++++++++++++++++++++++- modules/lemur | 1 + modules/testez | 1 + spec.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 .gitmodules create mode 160000 modules/lemur create mode 160000 modules/testez create mode 100644 spec.lua diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c0f3e66 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "modules/testez"] + path = modules/testez + url = https://github.com/Roblox/testez.git +[submodule "modules/lemur"] + path = modules/lemur + url = https://github.com/LPGhatguy/lemur.git diff --git a/.luacheckrc b/.luacheckrc index 582953d..6b52813 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,23 +1,6 @@ stds.roblox = { - globals = { - "game" - }, read_globals = { - -- Roblox globals - "script", - - -- Extra functions - "tick", "warn", "spawn", - "wait", "settings", "typeof", - - -- Types - "Vector2", "Vector3", - "Color3", - "UDim", "UDim2", - "Rect", - "CFrame", - "Enum", - "Instance", + "script", "spawn", "warn", "Instance", } } diff --git a/lib/Promise.spec.lua b/lib/Promise.spec.lua index 25f1353..2240c5e 100644 --- a/lib/Promise.spec.lua +++ b/lib/Promise.spec.lua @@ -1 +1,41 @@ -local Promise = require(script.Parent.Promise) \ No newline at end of file +return function() + local Promise = require(script.Parent.Promise) + + describe("Promise.new", function() + it("should pass resolve and reject to the callback", function() + local promiseResolve + local promiseReject + local callCount = 0 + + local promise = Promise.new(function(resolve, reject) + callCount = callCount + 1 + promiseResolve = resolve + promiseReject = reject + end) + + expect(promise).to.be.ok() + expect(promiseResolve).to.be.a("function") + expect(promiseReject).to.be.a("function") + expect(callCount).to.equal(1) + end) + + it("should resolve synchronously", function() + local promiseResolve + local callCount = 0 + + local promise = Promise.new(function(resolve) + callCount = callCount + 1 + promiseResolve = resolve + end) + + expect(promise._status).to.equal(Promise.Status.Started) + + promiseResolve(6) + + expect(promise._status).to.equal(Promise.Status.Resolved) + expect(promise._value).to.be.a("table") + expect(#promise._value).to.equal(1) + expect(promise._value[1]).to.equal(6) + end) + end) +end \ No newline at end of file diff --git a/modules/lemur b/modules/lemur new file mode 160000 index 0000000..3b29542 --- /dev/null +++ b/modules/lemur @@ -0,0 +1 @@ +Subproject commit 3b295421315081168db63c00bbb4e6c070ac7634 diff --git a/modules/testez b/modules/testez new file mode 160000 index 0000000..3c42175 --- /dev/null +++ b/modules/testez @@ -0,0 +1 @@ +Subproject commit 3c42175897f7133d10fdc269c040df98a55906d6 diff --git a/spec.lua b/spec.lua new file mode 100644 index 0000000..975fcd7 --- /dev/null +++ b/spec.lua @@ -0,0 +1,69 @@ +--[[ + Loads our library and all of its dependencies, then runs tests using TestEZ. +]] + +-- If you add any dependencies, add them to this table so they'll be loaded! +local LOAD_MODULES = { + {"lib", "Library"}, + {"modules/testez/lib", "TestEZ"}, +} + +-- This makes sure we can load Lemur and other libraries that depend on init.lua +package.path = package.path .. ";?/init.lua" + +-- If this fails, make sure you've run `lua bin/install-dependencies.lua` first! +local lemur = require("modules.lemur") + +--[[ + Collapses ModuleScripts named 'init' into their parent folders. + + This is the same result as the collapsing mechanism from Rojo. +]] +local function collapse(root) + local init = root:FindFirstChild("init") + if init then + init.Name = root.Name + init.Parent = root.Parent + + for _, child in ipairs(root:GetChildren()) do + child.Parent = init + end + + root:Destroy() + root = init + end + + for _, child in ipairs(root:GetChildren()) do + if child:IsA("Folder") then + collapse(child) + end + end + + return root +end + +-- Create a virtual Roblox tree +local habitat = lemur.Habitat.new() + +-- We'll put all of our library code and dependencies here +local Root = lemur.Instance.new("Folder") +Root.Name = "Root" + +-- Load all of the modules specified above +for _, module in ipairs(LOAD_MODULES) do + local container = lemur.Instance.new("Folder", Root) + container.Name = module[2] + habitat:loadFromFs(module[1], container) +end + +collapse(Root) + +-- Load TestEZ and run our tests +local TestEZ = habitat:require(Root.TestEZ) + +local results = TestEZ.TestBootstrap:run(Root.Library, TestEZ.Reporters.TextReporter) + +-- Did something go wrong? +if results.failureCount > 0 then + os.exit(1) +end