diff options
Diffstat (limited to 'src/granger/test')
-rw-r--r-- | src/granger/test/main.lua | 11 | ||||
-rw-r--r-- | src/granger/test/test-nettle.lua | 33 | ||||
-rw-r--r-- | src/granger/test/test-os-access.lua | 17 |
3 files changed, 61 insertions, 0 deletions
diff --git a/src/granger/test/main.lua b/src/granger/test/main.lua new file mode 100644 index 0000000..a5f9aee --- /dev/null +++ b/src/granger/test/main.lua @@ -0,0 +1,11 @@ +-- +-- main.lua +-- test runner +-- Copyright (c) 2016 Jeff Kent <jeff@jkent.net> +-- + +package.path = package.path .. ";../lua/?.lua;../lua/?/init.lua" + +require "lib" +require "test-os-access" +require "test-nettle" diff --git a/src/granger/test/test-nettle.lua b/src/granger/test/test-nettle.lua new file mode 100644 index 0000000..e453a57 --- /dev/null +++ b/src/granger/test/test-nettle.lua @@ -0,0 +1,33 @@ +-- +-- test-nettle.lua +-- test cases for nettle library +-- Copyright (c) 2016 Jeff Kent <jeff@jkent.net> +-- + +print "nettle tests begin" + +empty_hash = tostring(nettle.sha256()) + +ctx = nettle.sha256() +ctx:update(nil) +assert(empty_hash == tostring(ctx)) + +ctx = nettle.sha256() +ctx:update("Hello World!") +ctx:update("Hello World!") +hash = tostring(ctx) +assert(hash == "95a5a79bf6218dd0938950acb61bca24d5809172fe6cfd7f1af4b059449e52f8") + +ctx = nettle.sha256() +ctx:update("Hello World!Hello World!") +hash = tostring(ctx) +assert(hash == "95a5a79bf6218dd0938950acb61bca24d5809172fe6cfd7f1af4b059449e52f8") + +require "util" +hash = md5_file("../COPYING") +assert(hash == "b234ee4d69f5fce4486a80fdaf4a4263") + +hash = sha256_file("../COPYING") +assert(hash == "8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643") + +print "nettle tests completed" diff --git a/src/granger/test/test-os-access.lua b/src/granger/test/test-os-access.lua new file mode 100644 index 0000000..60740c4 --- /dev/null +++ b/src/granger/test/test-os-access.lua @@ -0,0 +1,17 @@ +-- +-- test-os-access.lua +-- test case for os.access() +-- Copyright (c) 2016 Jeff Kent <jeff@jkent.net> +-- + +print "os.access() test begin" + +if not os.is("windows") then + p = os.tmpname() + os.execute("touch " .. p .. "; chmod 400 " .. p) + assert(os.access(p, "r") == true) + assert(os.access(p, "w") == false) + os.execute("rm -f " .. p) +end + +print "os.access() test end" |