summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShmuel Zeigerman <solomuz0@gmail.com>2014-08-06 18:26:58 +0300
committerShmuel Zeigerman <solomuz0@gmail.com>2014-08-06 18:26:58 +0300
commit21b5b1b3ba1069f95e446552a2dccdc3943211a7 (patch)
treee3ad4fa829a82536df8dfcf5d2f571392358f825
parent0ef80eeb34fd4d1ce6ee46b881b6074be39ebb92 (diff)
downloadlrexlib-21b5b1b3ba1069f95e446552a2dccdc3943211a7.tar.gz
Add _newmembuffer function for testing buffer subjects.
-rw-r--r--src/algo.h4
-rw-r--r--src/common.c29
-rw-r--r--src/common.h5
-rw-r--r--test/README4
-rw-r--r--test/luatest.lua17
-rw-r--r--test/runtest.lua41
-rw-r--r--windows/mingw/_mingw.mak19
-rw-r--r--windows/mingw/rex_onig.mak2
-rw-r--r--windows/mingw/rex_pcre.mak2
9 files changed, 86 insertions, 37 deletions
diff --git a/src/algo.h b/src/algo.h
index 80391bf..e5ac525 100644
--- a/src/algo.h
+++ b/src/algo.h
@@ -736,4 +736,8 @@ static void alg_register (lua_State *L, const luaL_Reg *r_methods,
#endif
lua_pushfstring (L, REX_VERSION" (for %s)", name);
lua_setfield (L, -2, "_VERSION");
+#ifndef REX_NOEMBEDDEDTEST
+ lua_pushcfunction (L, newmembuffer);
+ lua_setfield (L, -2, "_newmembuffer");
+#endif
}
diff --git a/src/common.c b/src/common.c
index 1b1323e..3dd543a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -264,3 +264,32 @@ int luaL_typerror (lua_State *L, int narg, const char *tname) {
return luaL_argerror(L, narg, msg);
}
#endif
+
+#ifndef REX_NOEMBEDDEDTEST
+static int ud_topointer (lua_State *L) {
+ lua_pushlightuserdata (L, lua_touserdata (L, 1));
+ return 1;
+}
+
+static int ud_len (lua_State *L) {
+ lua_pushinteger (L, lua_objlen (L, 1));
+ return 1;
+}
+
+/* for testing purposes only */
+int newmembuffer (lua_State *L) {
+ size_t len;
+ const char* s = luaL_checklstring (L, 1, &len);
+ void *ud = lua_newuserdata (L, len);
+ memcpy (ud, s, len);
+ lua_newtable (L); /* metatable */
+ lua_pushvalue (L, -1);
+ lua_setfield (L, -2, "__index"); /* metatable.__index = metatable */
+ lua_pushcfunction (L, ud_topointer);
+ lua_setfield (L, -2, "topointer");
+ lua_pushcfunction (L, ud_len);
+ lua_setfield (L, -2, "__len");
+ lua_setmetatable (L, -2);
+ return 1;
+}
+#endif /* #ifndef REX_NOEMBEDDEDTEST */
diff --git a/src/common.h b/src/common.h
index e457754..41d968e 100644
--- a/src/common.h
+++ b/src/common.h
@@ -7,6 +7,7 @@
#include "lua.h"
#if LUA_VERSION_NUM > 501
+# define lua_objlen lua_rawlen
int luaL_typerror (lua_State *L, int narg, const char *tname);
#endif
@@ -95,4 +96,8 @@ void *Lmalloc (lua_State *L, size_t size);
void *Lrealloc (lua_State *L, void *p, size_t osize, size_t nsize);
void Lfree (lua_State *L, void *p, size_t size);
+#ifndef REX_NOEMBEDDEDTEST
+int newmembuffer (lua_State *L);
+#endif
+
#endif
diff --git a/test/README b/test/README
index 693ef93..100a276 100644
--- a/test/README
+++ b/test/README
@@ -1,5 +1,7 @@
To test Lrexlib, execute the following command line:
- lua ./runtest.lua [-v] LIBRARY...
+ lua ./runtest.lua [-a] [-v] LIBRARY...
+-a use the external "Alien" library for "buffer subject" tests,
+ rather than the internal function
-v gives verbose output
diff --git a/test/luatest.lua b/test/luatest.lua
index 3949d90..53d967d 100644
--- a/test/luatest.lua
+++ b/test/luatest.lua
@@ -67,25 +67,20 @@ end
-- returns:
-- 1) true, if success; false, if failure
-- 2) test results table or error_message
-local function test_function (test, func)
+local function test_function (test, func, newmembuffer)
local res
local t = packNT (pcall (func, unpackNT (test[1])))
if t[1] then
table.remove (t, 1)
res = t
- if alien then
- local subject = test[1][1]
- local buf = alien.buffer (#subject)
- if #subject > 0 then
- alien.memmove (buf:topointer (), subject, #subject)
- end
- test[1][1] = buf
+ if newmembuffer then
+ test[1][1] = newmembuffer (test[1][1])
local t = packNT (pcall (func, unpackNT (test[1])))
if t[1] then
table.remove (t, 1)
res = t
else
- print "alien test failed"
+ print "buffer subjects test failed"
res = t[2] --> error_message
end
end
@@ -120,13 +115,13 @@ local function test_method (test, constructor, name)
end
-- returns: a list of failed tests
-local function test_set (set, lib)
+local function test_set (set, lib, newmembuffer)
local list = {}
if type (set.Func) == "function" then
local func = set.Func
for i,test in ipairs (set) do
- local ok, res = test_function (test, func)
+ local ok, res = test_function (test, func, newmembuffer)
if not ok then
table.insert (list, {i=i, res})
end
diff --git a/test/runtest.lua b/test/runtest.lua
index 88b581b..e1f1a40 100644
--- a/test/runtest.lua
+++ b/test/runtest.lua
@@ -1,13 +1,5 @@
-- See Copyright Notice in the file LICENSE
--- See if we have alien, so we can do tests with buffer subjects
-local ok
-ok, alien = pcall (require, "alien")
-if not ok then
- io.stderr:write ("Warning: alien not found, so cannot run tests with buffer subjects\n")
- alien = nil
-end
-
do
local path = "./?.lua;"
if package.path:sub(1, #path) ~= path then
@@ -16,8 +8,17 @@ do
end
local luatest = require "luatest"
+local function newalienbuffer (str)
+ local alien = require "alien"
+ local buf = alien.buffer (#str)
+ if #str > 0 then
+ alien.memmove (buf:topointer (), str, #str)
+ end
+ return buf
+end
+
-- returns: number of failures
-local function test_library (libname, setfile, verbose)
+local function test_library (libname, setfile, verbose, use_alien)
if verbose then
print (("[lib: %s; file: %s]"):format (libname, setfile))
end
@@ -25,10 +26,14 @@ local function test_library (libname, setfile, verbose)
local f = require (setfile)
local sets = f (libname)
- local realalien = alien
- if libname == "rex_posix" and not lib.flags ().STARTEND and alien then
- alien = nil
- io.stderr:write ("Cannot run posix tests with alien without REG_STARTEND\n")
+ local newmembuffer = use_alien and newalienbuffer or lib._newmembuffer
+ if newmembuffer then
+ if libname == "rex_posix" and not lib.flags ().STARTEND then
+ newmembuffer = nil
+ io.stderr:write ("Cannot run posix tests with buffer subjects without REG_STARTEND\n")
+ end
+ else
+ io.stderr:write ("Warning: cannot run tests with buffer subjects\n")
end
local n = 0 -- number of failures
@@ -36,7 +41,7 @@ local function test_library (libname, setfile, verbose)
if verbose then
print (set.Name or "Unnamed set")
end
- local err = luatest.test_set (set, lib)
+ local err = luatest.test_set (set, lib, newmembuffer)
if verbose then
for _,v in ipairs (err) do
print (" Test " .. v.i)
@@ -48,7 +53,6 @@ local function test_library (libname, setfile, verbose)
if verbose then
print ""
end
- alien = realalien
return n
end
@@ -64,14 +68,19 @@ local avail_tests = {
do
local verbose, tests, nerr = false, {}, 0
local dir
+ local use_alien
-- check arguments
for i = 1, select ("#", ...) do
local arg = select (i, ...)
if arg:sub(1,1) == "-" then
if arg == "-v" then
verbose = true
+ elseif arg == "-a" then
+ use_alien = true
elseif arg:sub(1,2) == "-d" then
dir = arg:sub(3)
+ else
+ error ("invalid argument: [" .. arg .. "]")
end
else
if avail_tests[arg] then
@@ -99,7 +108,7 @@ do
for _, test in ipairs (tests) do
package.loaded[test.lib] = nil -- to force-reload the tested library
for _, setfile in ipairs (test) do
- nerr = nerr + test_library (test.lib, setfile, verbose)
+ nerr = nerr + test_library (test.lib, setfile, verbose, use_alien)
end
end
print ("Total number of failures: " .. nerr)
diff --git a/windows/mingw/_mingw.mak b/windows/mingw/_mingw.mak
index 9d56927..224c7fa 100644
--- a/windows/mingw/_mingw.mak
+++ b/windows/mingw/_mingw.mak
@@ -1,5 +1,7 @@
# Use with GNU Make.
+VERSION = 2.7.2
+
# User Settings ------------------------------------------------------------
# Target Lua version (51 for Lua 5.1; 52 for Lua 5.2).
@@ -9,18 +11,21 @@ LUAVERSION = 51
# LUADLL : Name of Lua DLL to link to (.dll should be omitted).
# LUAEXE : Name of Lua interpreter.
# LUAINC : Path of Lua include files.
+# LIBPATH : Path of lua5.1.dll, lua52.dll, pcre.dll, etc.
+
+LIBPATH = c:\exe32
ifeq ($(LUAVERSION),51)
- INSTALLPATH = s:\exe\lib32\lua51
+ INSTALLPATH = s:\exe\lib32\lua\5.1
LUADLL = lua5.1
LUAEXE = lua.exe
- LUAINC = s:\progr\work\system\include\lua51
+ LUAINC = s:\progr\work\system\include\lua\5.1
MYCFLAGS += -DREX_CREATEGLOBALVAR
else
- INSTALLPATH = s:\exe\lib32\lua52
+ INSTALLPATH = s:\exe\lib32\lua\5.2
LUADLL = lua52
LUAEXE = lua52.exe
- LUAINC = s:\progr\work\system\include\lua52
+ LUAINC = s:\progr\work\system\include\lua\5.2
# MYCFLAGS += -DREX_CREATEGLOBALVAR
endif
@@ -28,9 +33,9 @@ endif
BIN = $(PROJECT).dll
BININSTALL = $(INSTALLPATH)\$(BIN)
-CC = gcc
+CC = mingw32-gcc
CFLAGS = -W -Wall -O2 $(INCS) -DREX_OPENLIB=luaopen_$(PROJECT) \
- -DREX_LIBNAME=\"$(PROJECT)\" $(MYCFLAGS)
+ -DREX_LIBNAME=\"$(PROJECT)\" -DVERSION=\"$(VERSION)\" $(MYCFLAGS)
DEFFILE = $(PROJECT).def
EXPORTED = luaopen_$(PROJECT)
INCS = -I$(LUAINC) $(MYINCS)
@@ -54,7 +59,7 @@ test:
cd $(TESTPATH) && $(LUAEXE) runtest.lua $(TESTNAME) -d$(CURDIR)
$(BIN): $(OBJ) $(DEFFILE)
- $(CC) $(DEFFILE) $(OBJ) $(LIBS) -o $@ -shared
+ $(CC) $(DEFFILE) $(OBJ) -L$(LIBPATH) $(LIBS) -o $@ -shared
$(DEFFILE):
echo EXPORTS > $@
diff --git a/windows/mingw/rex_onig.mak b/windows/mingw/rex_onig.mak
index 4e9f5f7..deaeb40 100644
--- a/windows/mingw/rex_onig.mak
+++ b/windows/mingw/rex_onig.mak
@@ -2,7 +2,7 @@
# User Settings ------------------------------------------------------------
# path of Oniguruma include files
-REGEXINC = s:\progr\work\system\include
+REGEXINC = s:\progr\work\system\include\oniguruma
# --------------------------------------------------------------------------
PROJECT = rex_onig
diff --git a/windows/mingw/rex_pcre.mak b/windows/mingw/rex_pcre.mak
index b6d34ce..1f3dd76 100644
--- a/windows/mingw/rex_pcre.mak
+++ b/windows/mingw/rex_pcre.mak
@@ -2,7 +2,7 @@
# User Settings ------------------------------------------------------------
# path of PCRE include files
-REGEXINC = s:\progr\work\system\include
+REGEXINC = s:\progr\work\system\include\pcre
# --------------------------------------------------------------------------
PROJECT = rex_pcre