Files
bin
doc
examples
files
lib
python
src
t
bin
00-assert.rb
00-exit_nonzero.rb
00-exit_status.rb
00-exit_zero.rb
00-file_equal.rb
00-file_not_equal.rb
00-ignore_file.rb
00-import_file.rb
00-stderr_equal.rb
00-stderr_not_equal.rb
00-stdout_equal.rb
00-stdout_not_equal.rb
01-cmd.rb
01-misc.rb
01-simple.rb
CMDTEST_assert.rb
CMDTEST_chdir.rb
CMDTEST_cmd.rb
CMDTEST_dont_ignore_files.rb
CMDTEST_exit_nonzero.rb
CMDTEST_exit_status.rb
CMDTEST_exit_zero.rb
CMDTEST_file_equal.rb
CMDTEST_file_not_equal.rb
CMDTEST_ignore_file.rb
CMDTEST_import_directory.rb
CMDTEST_import_file.rb
CMDTEST_misc.rb
CMDTEST_options.rb
CMDTEST_raise.rb
CMDTEST_readonly.rb
CMDTEST_setenv.rb
CMDTEST_simple.rb
CMDTEST_stdxxx_equal.rb
CMDTEST_summary.rb
CMDTEST_teardown.rb
selftest_utils.rb
.gitignore
.hgignore
CMDTEST_example.yml
CMakeLists.txt
COPYING.txt
README.html
README.rst
Rakefile
cmdtest.gemspec
file1.txt
file2.txt
replace_strings.pl
run-regression.rb
setup.rb
cmdtest/t/CMDTEST_chdir.rb
Johan Holmberg 6a7bdbdfe4 make tests more Windows-friendly
by using Ruby helper scripts instead fo relying
on the existence of Unix commands
2016-11-05 00:49:22 +01:00

129 lines
2.8 KiB
Ruby

require "selftest_utils"
class CMDTEST_chdir < Cmdtest::Testcase
include SelftestUtils
# The Ruby builtin "Dir.chdir" and "chdir" from "cmdtest"
# can be used in a test-method. In both cases the following
# should happen:
#
# - the "current directory" of the "cmdtest" Ruby process should be set,
# so later code in the samne test-method can rely on the new
# current directory.
#
# - when a command is executed with "cmd", it should get the same
# current directory as the "cmdtest" Ruby process.
#
# without any "chdir"
def test_chdir_NONE
create_CMDTEST_foo [
"create_file 'SUBDIR/.flagfile', ''",
"puts Dir.pwd",
]
cmd_cmdtest do
stdout_equal /^\/.*\/top\/work$/
end
end
# "chdir" to a subdirectory
def test_chdir_SUBDIR
create_CMDTEST_foo [
"create_file 'SUBDIR/.flagfile', ''",
"chdir 'SUBDIR'",
"puts Dir.pwd",
]
cmd_cmdtest do
stdout_equal /^\/.*\/top\/work\/SUBDIR$/
end
end
# "Dir.chdir" to a subdirectory
def test_dir_chdir_SUBDIR
create_CMDTEST_foo [
"create_file 'SUBDIR/.flagfile', ''",
"Dir.chdir 'SUBDIR'",
"puts Dir.pwd",
]
cmd_cmdtest do
stdout_equal /^\/.*\/top\/work\/SUBDIR$/
end
end
# "cmd" after no "chdir"
def test_chdir_NONE_cmd
create_CMDTEST_foo [
"create_file 'SUBDIR/.flagfile', ''",
"cmd 'echo_pwd.rb' do",
" stdout_equal /^PWD=\\/.*\\/top\\/work$/",
"end",
]
cmd_cmdtest do
stdout_equal [
"### echo_pwd.rb",
]
end
end
# "cmd" after "chdir"
def test_chdir_SUBDIR_cmd
create_CMDTEST_foo [
"create_file 'SUBDIR/.flagfile', ''",
"chdir 'SUBDIR'",
"cmd 'echo_pwd.rb' do",
" stdout_equal /^PWD=\\/.*\\/top\\/work\\/SUBDIR$/",
"end",
]
cmd_cmdtest do
stdout_equal [
"### echo_pwd.rb",
]
end
end
# "cmd" after "Dir.chdir"
def test_dir_chdir_SUBDIR_cmd
create_CMDTEST_foo [
"create_file 'SUBDIR/.flagfile', ''",
"Dir.chdir 'SUBDIR'",
"cmd 'echo PWD=$(pwd)' do",
" stdout_equal /^PWD=\\/.*\\/top\\/work\\/SUBDIR$/",
"end",
]
cmd_cmdtest do
stdout_equal [
"### echo PWD=$(pwd)",
]
end
end
# "create_file" after "Dir.chdir"
def test_dir_chdir_SUBDIR_create_file
create_CMDTEST_foo [
"create_file 'SUBDIR/f0.txt', ''",
"create_file 'f1.txt', ''",
"Dir.chdir 'SUBDIR'",
"create_file 'f2.txt', ''",
"Dir.chdir '..'",
"cmd 'find_files.rb' do",
" stdout_equal [",
" './SUBDIR/f0.txt',",
" './SUBDIR/f2.txt',",
" './f1.txt',",
" ]",
"end",
]
cmd_cmdtest do
stdout_equal [
"### find_files.rb",
]
end
end
end