moonunit.lua revision cb1e20df951447249fd1344ae04a790219a16be5
af84459fbf938e508fd10b01cb8d699c79083813takashi-- Licensed to the Apache Software Foundation (ASF) under one or more
af84459fbf938e508fd10b01cb8d699c79083813takashi-- contributor license agreements. See the NOTICE file distributed with
af84459fbf938e508fd10b01cb8d699c79083813takashi-- this work for additional information regarding copyright ownership.
af84459fbf938e508fd10b01cb8d699c79083813takashi-- The ASF licenses this file to You under the Apache License, Version 2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi-- (the "License"); you may not use this file except in compliance with
af84459fbf938e508fd10b01cb8d699c79083813takashi-- the License. You may obtain a copy of the License at
af84459fbf938e508fd10b01cb8d699c79083813takashi--
af84459fbf938e508fd10b01cb8d699c79083813takashi-- http://www.apache.org/licenses/LICENSE-2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi--
af84459fbf938e508fd10b01cb8d699c79083813takashi-- Unless required by applicable law or agreed to in writing, software
af84459fbf938e508fd10b01cb8d699c79083813takashi-- distributed under the License is distributed on an "AS IS" BASIS,
af84459fbf938e508fd10b01cb8d699c79083813takashi-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
af84459fbf938e508fd10b01cb8d699c79083813takashi-- See the License for the specific language governing permissions and
af84459fbf938e508fd10b01cb8d699c79083813takashi-- limitations under the License.
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashimodule("moonunit", package.seeall)
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashiTestCase = {}
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashifunction TestCase:new(it)
af84459fbf938e508fd10b01cb8d699c79083813takashi it = it or {}
af84459fbf938e508fd10b01cb8d699c79083813takashi setmetatable(it, self)
af84459fbf938e508fd10b01cb8d699c79083813takashi self.__index = self
af84459fbf938e508fd10b01cb8d699c79083813takashi return it
af84459fbf938e508fd10b01cb8d699c79083813takashiend
af84459fbf938e508fd10b01cb8d699c79083813takashi
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrinfunction TestCase:run(args)
af84459fbf938e508fd10b01cb8d699c79083813takashi args = args or arg
3c13a815670b54d1c17bf02954f7d2b066cde95cnd local function run_test(t, name)
3c13a815670b54d1c17bf02954f7d2b066cde95cnd local status, err = pcall(t, self)
af84459fbf938e508fd10b01cb8d699c79083813takashi if status then
af84459fbf938e508fd10b01cb8d699c79083813takashi print(("%-39s \27[32mpass\27[39m"):format("[" .. name .. "]"))
af84459fbf938e508fd10b01cb8d699c79083813takashi else
af84459fbf938e508fd10b01cb8d699c79083813takashi print(("%-39s \27[31mFAIL\27[39m %s"):format("[" .. name .. "]", err))
af84459fbf938e508fd10b01cb8d699c79083813takashi end
af84459fbf938e508fd10b01cb8d699c79083813takashi end
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi if (args and #args > 0) then
af84459fbf938e508fd10b01cb8d699c79083813takashi for _, v in ipairs(args) do
af84459fbf938e508fd10b01cb8d699c79083813takashi if type(self[v]) == "function" then
af84459fbf938e508fd10b01cb8d699c79083813takashi run_test(self[v], v)
af84459fbf938e508fd10b01cb8d699c79083813takashi else
af84459fbf938e508fd10b01cb8d699c79083813takashi print(("%-39s FAIL %s"):format("[" .. v .. "]",
af84459fbf938e508fd10b01cb8d699c79083813takashi "'" .. v .. "' doesn't appear to be a test function"))
af84459fbf938e508fd10b01cb8d699c79083813takashi end
af84459fbf938e508fd10b01cb8d699c79083813takashi end
af84459fbf938e508fd10b01cb8d699c79083813takashi else
af84459fbf938e508fd10b01cb8d699c79083813takashi for k, v in pairs(self) do
af84459fbf938e508fd10b01cb8d699c79083813takashi run_test(v, k)
af84459fbf938e508fd10b01cb8d699c79083813takashi end
af84459fbf938e508fd10b01cb8d699c79083813takashi end
af84459fbf938e508fd10b01cb8d699c79083813takashiend
af84459fbf938e508fd10b01cb8d699c79083813takashi