This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
/
lfs.t
executable file
·104 lines (74 loc) · 2.37 KB
/
lfs.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/lua
-- Copyright (C) 2009, Parrot Fondation.
--[[
=head1 Lua File System Library
=head2 Synopsis
% prove t/lfs.t
=head2 Description
Tests Lua File System Library
=cut
--]]
require 'Test.More'
plan(28)
if not require_ok 'lfs' then
skip_rest "no lib"
os.exit()
end
is( lfs._VERSION, "LuaFileSystem 1.4.0", "version" )
local cwd = lfs.currentdir()
type_ok( cwd, 'string', "lfs.currentdir" )
diag(cwd)
is( lfs.chdir('t'), true, "lfs.chdir" )
is( lfs.chdir('..'), true )
local r, msg = lfs.chdir("bad_dir")
is( r, nil, "lfs.chdir (bad)" )
is( msg, "Unable to change working directory to 'bad_dir'\nchdir failed: No such file or directory\n" )
lfs.rmdir('xpto')
is( lfs.mkdir('xpto'), true, "lfs.mkdir" )
ok( lfs.chdir('xpto') )
diag( lfs.currentdir() )
ok( lfs.chdir('..') )
is( lfs.mkdir('xpto'), nil, "lfs.mkdir (exists)" )
local str = ''
for file in lfs.dir('xpto') do
str = str .. file
end
is( str, '...', "lfs.dir" )
error_like(function () lfs.dir('bad_dir') end,
"No such file or directory",
"lfs.dir (bad)")
is( lfs.rmdir('xpto'), true, "lfs.rmdir" )
is( lfs.chdir('xpto'), nil )
local r, msg = lfs.rmdir('xpto')
is( r, nil, "lfs.rmdir (not exists)" )
like( msg, "No such file or directory" )
os.remove('file.txt')
f = io.open('file.txt', 'w')
f:write("file with text")
f:close()
local attr = lfs.attributes('file.txt')
type_ok( attr, 'table', "lfs.attributes" )
is( attr.mode, 'file' )
is( attr.size, 14 )
is( lfs.attributes('file.txt', 'mode'), 'file', "lfs.attributes 'mode'" )
is( lfs.attributes('file.txt', 'size'), 14, "lfs.attributes 'size'" )
error_like(function () lfs.attributes('file.txt', 'bad') end,
"bad argument #2 to 'attributes' %(invalid option 'bad'%)",
"lfs.attributes (bad)")
local r, msg = lfs.attributes("no_file.txt")
is( r, nil, "lfs.attributes (no file)" )
is( msg, "cannot obtain information from file `no_file.txt'" )
f = io.open("file.txt")
f:close()
error_like(function () lfs.lock(f) end,
"lock: closed file",
"lfs.lock (closed)")
is( lfs.symlinkattributes('file.txt', 'mode'), 'file', "lfs.symlinkattributes 'mode'" )
is( lfs.symlinkattributes('file.txt', 'size'), 14, "lfs.symlinkattributes 'size'" )
os.remove('file.txt') -- clean up
-- Local Variables:
-- mode: lua
-- lua-indent-level: 4
-- fill-column: 100
-- End:
-- vim: ft=lua expandtab shiftwidth=4: