]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests/config: added basic assert support (compatible with busted)
authorMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 24 Nov 2017 04:30:00 +0000 (20:30 -0800)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 24 Nov 2017 06:24:42 +0000 (22:24 -0800)
There is no dependency on a testing library yet, so I added a
basic interface for mocking and asserting test values to get
something to start with. I'll probably replace it with busted
or telescope later on to get nicer testing output.

.luacheckrc
tests/config/test_utils.lua

index 2e2f2775e791dec68557f6e41b0fdbd936952840..72f12770c60bd8fe31f936550075167853ee7a45 100644 (file)
@@ -73,4 +73,5 @@ ignore = {
 files['daemon/lua'].ignore = {'111', '121', '122'}
 -- Tests and scripts can use global variables
 files['scripts'].ignore = {'111', '112', '113'}
-files['tests'].ignore = {'111', '112', '113'}
\ No newline at end of file
+files['tests'].ignore = {'111', '112', '113'}
+files['tests/config/test_utils.lua'].ignore = {'121'}
\ No newline at end of file
index b96a96788fa0c1ca96e4e79152fac95e0453142e..33e81edbd8e8cd77c04deaa053628719d3dd63db 100644 (file)
@@ -28,3 +28,24 @@ function contains(table, value)
        end
        return false
 end
+
+-- Emulate busted testing interface
+local assert_builtin = assert
+assert = setmetatable({}, {
+       __call = function (_, ...)
+               return assert_builtin(...)
+       end,
+       __index = {
+               truthy = function (expr)
+                       assert_builtin(expr)
+               end,
+               falsy = function (expr)
+                       assert_builtin(not expr)
+               end,
+               same = function (a, b)
+                       if a ~= b then
+                               assert_builtin(false, string.format('expected: %s got: %s', a, b))
+                       end
+               end,
+       }
+})
\ No newline at end of file