librazor/test.lua
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Oct 04 18:12:58 2014 +0100 (2014-10-04)
changeset 454 56ff755c268c
permissions -rw-r--r--
Only export symbols starting with razor_ in dynamic library.

Apart from being good practice to avoid clashes with higher-level
libraries and the application, this also fixes an obscure bug: The
gnulib library is used both by librazor (the dynamic library) and
by razor (the executable). In doing so, we want to have two separate
copies of the library despite the code duplication this involves.
Without the explicit limit to export only razor_ symbols, the razor
executable under mingw64 was picking up the getopt_long function
from librazor and the optind variable from libgnu which meant that
it did not see optind changing. Hiding librazor's copy of getopt
causes the linker to find libgnu's copy and everything works.

Note that under mingw librazor-#.dll still contains undocumented
(private) razor_ symbols but these will do no harm as long as nobody
tries to use them.
ali@352
     1
dofile("/testfile")
ali@352
     2
assert(loadfile("/testfile"))
ali@352
     3
assert(io.input("/testfile"))
ali@352
     4
assert(io.output("/file1"))
ali@352
     5
file = assert(io.open("/file1", "w"))
ali@352
     6
assert(io.input(file))
ali@352
     7
assert(io.output(file))
ali@352
     8
file:write("Hello world\n")
ali@352
     9
file:close()
ali@352
    10
assert(io.input())
ali@352
    11
assert(io.output())
ali@352
    12
for line in assert(io.lines("/file1")) do
ali@352
    13
	assert(line == "Hello world")
ali@352
    14
end
ali@352
    15
file, err = io.popen("/testfile", "r")
ali@352
    16
if file == nil then
ali@352
    17
	assert(string.find(err, " not supported") == 1)
ali@352
    18
else
ali@352
    19
	assert(file:read() == "Abracadabra!")
ali@352
    20
	file:close();
ali@352
    21
end
ali@352
    22
assert(os.rename("/file1","/file2"))
ali@352
    23
assert(os.remove("/file2"))
ali@352
    24
assert(posix.mkdir("/testdir"))
ali@352
    25
assert(posix.stat("/testdir"))
ali@352
    26
assert(posix.chdir("/testdir"))
ali@352
    27
assert(posix.getcwd() == "/testdir")
ali@352
    28
assert(posix.mkdir("dir1"))
ali@352
    29
assert(posix.link("/testdir/dir1", "/testdir/link", true))
ali@352
    30
assert(posix.readlink("/testdir/link") == "/testdir/dir1")
ali@352
    31
assert(posix.unlink("/testdir/link"))
ali@352
    32
assert(posix.link("/testfile", "/testdir/magic", false))
ali@352
    33
assert(posix.chmod("/testfile","a+x"))
ali@352
    34
assert(posix.access("/testfile","x"))
ali@352
    35
pid = posix.fork()
ali@352
    36
if pid == 0 then
ali@352
    37
	assert(posix.exec("/testfile"))
ali@352
    38
else
ali@352
    39
	posix.wait(pid)
ali@352
    40
end
ali@352
    41
assert(posix.chdir("/"))
ali@352
    42
posix.setenv("PATH","/bin:/usr/bin:/testdir",true)
ali@352
    43
pid = posix.fork()
ali@352
    44
if pid == 0 then
ali@352
    45
	assert(posix.execp("magic"))
ali@352
    46
else
ali@352
    47
	posix.wait(pid)
ali@352
    48
end
ali@352
    49
assert(posix.utime("/testfile"))
ali@352
    50
assert(posix.pathconf("/testdir/magic"))
ali@352
    51
assert(posix.mkfifo("/testdir/fifo"))
ali@352
    52
assert(posix.dir())
ali@352
    53
assert(posix.dir("/testdir"))
ali@352
    54
assert(posix.files())
ali@352
    55
assert(posix.files("/testdir"))
ali@352
    56
for _,f in pairs(posix.glob("/testdir/*")) do
ali@352
    57
	assert(string.find(f, "/testdir/") == 1)
ali@352
    58
end
ali@352
    59
assert(posix.rmdir("/testdir/dir1"))
ali@352
    60
assert(posix.chown("/testfile",-1,-1))