Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing "framework" for scripts with nonstandard filenames

Tags:

bash

shell

Here are many comments on some questions (especially for shell) that say basically one or more of the following:

  • This will fail on file names that contain spaces, newlines, etc,
  • This will fail if the file is a symbolic link (or not),
  • This will fail if the $filaneme is a directory and not regular file,
  • and so on.

While I understand that every script needs its own testing environment, but these are some common things for what the script should be immune against.

So, my intention is to write a script what will create some directory hierarchy with "specially crafted" file names for testing purposes.

The question is: what "special" file names are good for this test?

Currently I have (the script creates files and directories) with:

  • space in the file name
  • newline in the file name
  • file name that starts with one of:
    • - (like command argument)
    • # (comment char)
    • ! (command history)
  • file name that contains one of:
    • | char (pipe)
    • () chars
    • * and ? (wildcards)
  • file name with unicode characters
  • all above for the directories
  • symbolic link to the directory
  • symbolic link to the file

Any other idea what I shouldn't miss?

like image 449
jm666 Avatar asked Oct 21 '22 10:10

jm666


1 Answers

What comes to my mind:

  • quotes in the filename single and double
  • the $ character at the start
  • several redirection characters like > < << <<<
  • the ~ char ($HOME)
  • the ';' (as command delimiter)
  • backslash in the filename \

basically, go thru ascii table and test all chars, if you think that you need this :)

Some another comments:

  • If you want test scripts for the stack-overflow questions, you should create one file with the OP's content (calling as the "basic file")
  • And the all above "special files" should be symlinks to the above basic file. With this method you can easily modify the content of the files (you need change only one - the basic).
  • Or, if symlinks not a solution for you use hard-links.

Not directly about special characters in the filenames, but it is good care about:

  • different case filenames, especially for images like image.jpg image.JPG, same filename only different extension

EDIT: Ideas from the comments:

  • Very long filenames, lots and lots of files, and very deep directory hierarchies (tripleee)
like image 68
jm666 Avatar answered Oct 28 '22 15:10

jm666