Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stevedonovan/Penlight.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsteve donovan <steve.j.donovan@gmail.com>2013-06-21 14:52:24 +0400
committersteve donovan <steve.j.donovan@gmail.com>2013-06-21 14:52:24 +0400
commit08d2ea440d8de74408e50af978648105decad09b (patch)
tree1455d2d109df89ea068d4ae19ce11b0dc1f76978
parent8442d020d7b73e7026b051a9c6badd4beb9f4ada (diff)
test script; test-func no longer so verbose1.2.1
-rw-r--r--lua/pl/platf/luajava.lua101
-rw-r--r--tests/test-func.lua20
-rw-r--r--tests/tests.run33
3 files changed, 46 insertions, 108 deletions
diff --git a/lua/pl/platf/luajava.lua b/lua/pl/platf/luajava.lua
deleted file mode 100644
index 4fb82e6..0000000
--- a/lua/pl/platf/luajava.lua
+++ /dev/null
@@ -1,101 +0,0 @@
--- experimental support for LuaJava
---
-local path = {}
-
-
-path.link_attrib = nil
-
-local File = luajava.bindClass("java.io.File")
-local Array = luajava.bindClass('java.lang.reflect.Array')
-
-local function file(s)
- return luajava.new(File,s)
-end
-
-function path.dir(P)
- local ls = file(P):list()
- print(ls)
- local idx,n = -1,Array:getLength(ls)
- return function ()
- idx = idx + 1
- if idx == n then return nil
- else
- return Array:get(ls,idx)
- end
- end
-end
-
-function path.mkdir(P)
- return file(P):mkdir()
-end
-
-function path.rmdir(P)
- return file(P):delete()
-end
-
---- is this a directory?
--- @param P A file path
-function path.isdir(P)
- if P:match("\\$") then
- P = P:sub(1,-2)
- end
- return file(P):isDirectory()
-end
-
---- is this a file?.
--- @param P A file path
-function path.isfile(P)
- return file(P):isFile()
-end
-
--- is this a symbolic link?
--- Direct support for symbolic links is not provided.
--- see http://stackoverflow.com/questions/813710/java-1-6-determine-symbolic-links
--- and the caveats therein.
--- @param P A file path
-function path.islink(P)
- local f = file(P)
- local canon
- local parent = f:getParent()
- if not parent then
- canon = f
- else
- parent = f.getParentFile():getCanonicalFile()
- canon = luajava.new(File,parent,f:getName())
- end
- return canon:getCanonicalFile() ~= canon:getAbsoluteFile()
-end
-
---- return size of a file.
--- @param P A file path
-function path.getsize(P)
- return file(P):length()
-end
-
---- does a path exist?.
--- @param P A file path
--- @return the file path if it exists, nil otherwise
-function path.exists(P)
- return file(P):exists() and P
-end
-
---- Return the time of last access as the number of seconds since the epoch.
--- @param P A file path
-function path.getatime(P)
- return path.getmtime(P)
-end
-
---- Return the time of last modification
--- @param P A file path
-function path.getmtime(P)
- -- Java time is no. of millisec since the epoch
- return file(P):lastModified()/1000
-end
-
----Return the system's ctime.
--- @param P A file path
-function path.getctime(P)
- return path.getmtime(P)
-end
-
-return path
diff --git a/tests/test-func.lua b/tests/test-func.lua
index 3861bce..7f112cc 100644
--- a/tests/test-func.lua
+++ b/tests/test-func.lua
@@ -16,20 +16,26 @@ function test (e)
print(rep)
end
+function teste (e,rs,ve)
+ local v = {}
+ collect_values(e,v)
+ if #v > 0 then asserteq(v,ve,nil,2) end
+ local rep = repr(e)
+ asserteq(rep,rs)
+end
+
import ('math')
-test(_1+_2('hello'))
-test(sin(_1))
-test(_1:method())
-test(Not(_1))
+teste(_1+_2('hello'),'_1 + _2(_C1)',{"hello"})
+teste(_1:method(),'_1[_C1](_1)',{"method"})
+teste(Not(_1),'not _1')
asserteq(instantiate(_1+_2)(10,20),30)
asserteq(instantiate(_1+20)(10),30)
asserteq(instantiate(Or(Not(_1),_2))(true,true),true)
-test(_1() + _2() + _3())
-print(I(_1+_2)(10,20))
-test(sin(_1)+cos(_2))
+teste(_1() + _2() + _3(),'_1() + _2() + _3()',30)
+asserteq(I(_1+_2)(10,20),30)
asserteq(instantiate(_1+_2)(10,20),30)
diff --git a/tests/tests.run b/tests/tests.run
new file mode 100644
index 0000000..268cca7
--- /dev/null
+++ b/tests/tests.run
@@ -0,0 +1,33 @@
+-- running the tests and examples
+require 'pl'
+local lfs = require 'lfs'
+
+local function quote_if_needed (s)
+ if s:match '%s' then
+ s = '"'..s..'"'
+ end
+ return s
+end
+
+-- get the Lua command-line used to invoke this script
+local cmd = app.lua()
+
+local D = path.dirname(arg[0])
+print('Running tests in',D)
+
+function do_lua_files ()
+ for _,f in ipairs(dir.getfiles('.','*.lua')) do
+ print(cmd..' '..f)
+ local res = utils.execute(cmd..' '..f)
+ if not res then
+ print ('process failed with non-zero result: '..f)
+ os.exit(1)
+ end
+ end
+end
+
+lfs.chdir(D)
+do_lua_files()
+
+
+