digitalmars.D.learn - Run unitest as default behaviour of a program.
- BoQsc (50/50) Apr 05 Testing is quite important when things change rapidly.
Testing is quite important when things change rapidly. To make sure the debugging is easier, I decided to make programs that would notify me about something not working as expected. I'm getting tired with specifying `-unittest` flag on every script (.cmd .bat .sh .bash) and manually in a command line or terminal. Wonder if there is any way to make `unittest{}` the **main** method of a source file. Here is an example of my program. As you can see the **main** method currently used for showing notice on how to run the test. I would like to not need that. ``` void main() { writeln("Please run: rdmd -unittest Path_Parser.d to start the test. "); } string[] splitPathString(string text) { string word; string[] wordList; foreach (char letter; text) { if (letter == '/' || letter == '\\') { wordList ~= word; word = ""; continue; } word ~= letter; } return wordList; } unittest { string[] paths = [ "./directory/folder/subfolder/", "./directory/folder/subfolder/", r"C:\Users\Windows10\Documents\GitHub\Operating-System\Operating_System\System\Print_Folder_Tree\Path_Parser", ]; foreach (path; paths) writeln(path); foreach (string path; paths) { foreach (directory; splitPathString(path)) { write(directory, ); write("\n"); } } } ```
Apr 05