Repository navigation
Expand file tree
/
Copy pathtest-dir.lua
More file actions
94 lines (68 loc) · 2.8 KB
/
Copy pathtest-dir.lua
File metadata and controls
94 lines (68 loc) · 2.8 KB
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
-- This test file expects to be ran from 'run.lua' in the root Penlight directory.
local dir = require( "pl.dir" )
local file = require( "pl.file" )
local path = require( "pl.path" )
local asserteq = require( "pl.test" ).asserteq
asserteq(dir.fnmatch("foobar", "foo*bar"), true)
asserteq(dir.fnmatch("afoobar", "foo*bar"), false)
asserteq(dir.fnmatch("foobars", "foo*bar"), false)
asserteq(dir.fnmatch("foonbar", "foo*bar"), true)
asserteq(dir.fnmatch("foo'n'bar", "foo*bar"), true)
asserteq(dir.fnmatch("foonbar", "foo?bar"), true)
asserteq(dir.fnmatch("foo'n'bar", "foo?bar"), false)
asserteq(dir.fnmatch("foo", "FOO"), path.is_windows)
asserteq(dir.fnmatch("FOO", "foo"), path.is_windows)
local filtered = dir.filter({"foobar", "afoobar", "foobars", "foonbar"}, "foo*bar")
asserteq(filtered, {"foobar", "foonbar"})
local normpath = path.normpath
local doc_files = dir.getfiles(normpath "doc/", "*.ld")
asserteq(doc_files, {normpath "doc/config.ld"})
local all_doc_files = dir.getallfiles(normpath "doc/", "*.ld")
asserteq(all_doc_files, {normpath "doc/config.ld"})
local test_samples = dir.getallfiles(normpath "tests/lua")
table.sort(test_samples)
asserteq(test_samples, {
normpath "tests/lua/animal.lua",
normpath "tests/lua/bar.lua",
normpath "tests/lua/foo/args.lua",
normpath "tests/lua/mod52.lua",
normpath "tests/lua/mymod.lua"
})
-- Test move files -----------------------------------------
-- Create a dummy file
local fileName = path.tmpname()
file.write( fileName, string.rep( "poot ", 1000 ) )
local newFileName = path.tmpname()
local err, msg = dir.movefile( fileName, newFileName )
-- Make sure the move is successful
assert( err, msg )
-- Check to make sure the original file is gone
asserteq( path.exists( fileName ), false )
-- Check to make sure the new file is there
asserteq( path.exists( newFileName ) , newFileName )
-- Try to move the original file again (which should fail)
local newFileName2 = path.tmpname()
local err, msg = dir.movefile( fileName, newFileName2 )
asserteq( err, false )
-- Clean up
file.delete( newFileName )
-- Test copy files -----------------------------------------
-- Create a dummy file
local fileName = path.tmpname()
file.write( fileName, string.rep( "poot ", 1000 ) )
local newFileName = path.tmpname()
local err, msg = dir.copyfile( fileName, newFileName )
-- Make sure the move is successful
assert( err, msg )
-- Check to make sure the new file is there
asserteq( path.exists( newFileName ) , newFileName )
-- Try to move a non-existant file (which should fail)
local fileName2 = 'blub'
local newFileName2 = 'snortsh'
local err, msg = dir.copyfile( fileName2, newFileName2 )
asserteq( err, false )
-- Clean up the files
file.delete( fileName )
file.delete( newFileName )
-- have NO idea why forcing the return code is necessary here (Windows 7 64-bit)
os.exit(0)