This commit is contained in:
anon 2025-01-23 09:41:54 +01:00
parent 92e10d4822
commit c06b63ca07
8 changed files with 195 additions and 0 deletions

183
test/CMDTEST_vimdir.rb Normal file
View File

@ -0,0 +1,183 @@
require 'etc'
class CMDTEST_basic < Cmdtest::Testcase
def test_help
cmd "vimdir -h" do
exit_zero
stdout_equal /.+/
end
end
def test_wrong_arg
cmd "vimdir -j" do
exit_nonzero
stdout_equal /.+/
stderr_equal /.+/
end
end
def test_missing_folder
cmd "vimdir ./this/directory/does/not/exist/" do
exit_nonzero
created_files ["vimdir_test_file.vimdir"]
stderr_equal /.+error.+/
end
end
def test_editor
import_file "test/saver.sh", "./"
cmd "EDITOR=./saver.sh vimdir ./" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
end
end
def test_vimdir_editor
import_file "test/saver.sh", "./"
cmd "VIMDIREDITOR=./saver.sh vimdir ./" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
end
end
end
class CMDTEST_mydir < Cmdtest::Testcase
def setup
import_file "test/replacer.sh", "./"
import_file "test/saver.sh", "./"
import_file "test/memoryhole.sh", "./"
import_directory "test/mydir/", "./mydir/"
end
def test_noop
cmd "EDITOR=./memoryhole.sh vimdir -n ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir"]
end
end
def test_contents
expected = [
"000\t./mydir/.gitkeep",
"001\t./mydir/file.txt",
"002\t./mydir/script.sh",
]
cmd "EDITOR=./saver.sh vimdir -n ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
file_equal "vimdir_test_file.vimdir", expected
end
end
def test_permission_contents
expected = [
"000\t-rw-r--r--\t./mydir/.gitkeep",
"001\t-rw-r--r--\t./mydir/file.txt",
"002\t-rwxr-xr-x\t./mydir/script.sh",
]
cmd "EDITOR=./saver.sh vimdir -n -p ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
file_equal "vimdir_test_file.vimdir", expected
end
end
def test_owner_contents
username = Etc.getpwuid(1000).name
groupname = Etc.getgrgid(1000).name
expected = [
"000\t#{username}:#{groupname}\t./mydir/.gitkeep",
"001\t#{username}:#{groupname}\t./mydir/file.txt",
"002\t#{username}:#{groupname}\t./mydir/script.sh",
]
cmd "EDITOR=./saver.sh vimdir -n -o ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
file_equal "vimdir_test_file.vimdir", expected
end
end
def test_permissoin_owner_contents
username = Etc.getpwuid(1000).name
groupname = Etc.getgrgid(1000).name
expected = [
"000\t-rw-r--r--\t#{username}:#{groupname}\t./mydir/.gitkeep",
"001\t-rw-r--r--\t#{username}:#{groupname}\t./mydir/file.txt",
"002\t-rwxr-xr-x\t#{username}:#{groupname}\t./mydir/script.sh",
]
cmd "EDITOR=./saver.sh vimdir -n -p -o ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
file_equal "vimdir_test_file.vimdir", expected
end
end
def test_del_file
File.write('target.txt',
[
"000\t./mydir/.gitkeep",
"002\t./mydir/script.sh"
].join("\n")
)
cmd "EDITOR=./replacer.sh vimdir -n ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir"]
removed_files ["target.txt"]
stderr_equal /^.*delete '.*file.txt'.*$/
end
end
def test_chmod_file
File.write('target.txt',
[
"000\t-rw-r--r--\t./mydir/.gitkeep",
"001\t-rw-r--r--\t./mydir/file.txt",
"002\t-rw-r--r--\t./mydir/script.sh",
].join("\n")
)
cmd "EDITOR=./replacer.sh vimdir -n -p ./mydir/" do
exit_zero
created_files ["vimdir_test_file.vimdir"]
removed_files ["target.txt"]
stderr_equal /^.*chmod '.*script.sh' (.+).*$/
end
end
end
class CMDTEST_mynesteddir < Cmdtest::Testcase
def setup
import_file "test/replacer.sh", "./"
import_file "test/saver.sh", "./"
import_file "test/memoryhole.sh", "./"
import_directory "test/mynesteddir/", "./mynesteddir/"
end
def test_trailing_slash_included
cmd "EDITOR=./saver.sh vimdir -n ./mynesteddir/" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
file_equal "vimdir_test_file.vimdir", /^000\t.+nest\/$/
end
end
def test_recursive
expected = [
"000\t./mynesteddir/nest/",
"001\t./mynesteddir/nest/.gitkeep",
]
cmd "EDITOR=./saver.sh vimdir -n -r ./mynesteddir/" do
exit_zero
created_files ["vimdir_test_file.vimdir", "output.txt"]
file_equal "vimdir_test_file.vimdir", expected
end
end
end

2
test/memoryhole.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
cat $1 >> /dev/null # is this required? no. does this explain why this script is here? yes.

0
test/mydir/.gitkeep Normal file
View File

2
test/mydir/file.txt Normal file
View File

@ -0,0 +1,2 @@
this they file contains some text,
for no reason at all really

3
test/mydir/script.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo hw

View File

2
test/replacer.sh Executable file
View File

@ -0,0 +1,2 @@
#/bin/sh
mv target.txt $1

3
test/saver.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
cp $1 output.txt