You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to test a function that counts the number of files in a directory.
By using BeforeCall and AfterCall hooks, I create a temporary directory and files before the call, and delete them after the call.
But I get an error. What am I doing wrong here?
Describe 'The count function'
setup(){
mkdir -p /tmp/count_tmp
touch /tmp/count_tmp/file1.txt /tmp/count_tmp/file2.txt
}
cleanup(){ rm -rf /tmp/count_tmp;}
BeforeCall 'setup'
AfterCall 'cleanup'
It 'counts files or directories in directory'
When call count /tmp/count_tmp/*
The output should eq 2
End
End
Hello Shinichi Okada,
nice to see the issue, I was astonished in past because some of my tests do not passed and I could not find out what is going wrong.
It seems to me the path to the folder is substituted in the test section before the BeforeCall was called. If the folder is already available, the test will passed.
This is not a fix of your problem, but you confirm to me, it is a problem of the test tool.
With regards,
Lutz
Appendage:
I create the folder in a additional dummy test first, this is a work around only.
Describe 'The count function'
setup(){
mkdir -p /tmp/count_tmp
touch /tmp/count_tmp/file1.txt /tmp/count_tmp/file2.txt
}
cleanup(){
rm -rf /tmp/count_tmp;}
Describe 'Dummy function test'
BeforeRun 'setup'
It 'create the directory only'
When run true
The status should eq 0
End
End
Describe 'The count function test'
# BeforeCall 'setup'
AfterCall 'cleanup'
Include count.sh
It 'counts files or directories in directory'
When call count /tmp/count_tmp/*
The output should eq 2
End
End
End
I'd like to test a function that counts the number of files in a directory.
By using
BeforeCall
andAfterCall
hooks, I create a temporary directory and files before the call, and delete them after the call.But I get an error. What am I doing wrong here?
Error:
count function:
Are there better ways to test them?
The text was updated successfully, but these errors were encountered: