From 5a3f7ffdc70538b87a78c367b6fba743d11e5a7d Mon Sep 17 00:00:00 2001 From: clyhtsuriva Date: Sun, 18 Jun 2023 21:29:21 +0200 Subject: Add a test for convert-filenames Using BATS (Bash Automated Testing System) for the tests. More to come soon for other scripts --- bin/tests/convert-filenames.bats | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 bin/tests/convert-filenames.bats diff --git a/bin/tests/convert-filenames.bats b/bin/tests/convert-filenames.bats new file mode 100755 index 0000000..d8ea465 --- /dev/null +++ b/bin/tests/convert-filenames.bats @@ -0,0 +1,68 @@ +#!/usr/bin/env bats + +@test "Test if file exists" { + run convert-filenames.sh non_existent_file.txt + + [ "$status" -ne 0 ] + [ "${lines[0]}" = "File 'non_existent_file.txt' does not exist." ] +} + +@test "Test already correct file name conversion" { + og_file='/tmp/already_correct-filename.test' + new_name="$og_file" + + touch "$og_file" + + run convert-filenames.sh "$og_file" + + # Verify the file stayed the same + [ "$status" -eq 0 ] + [ "$output" = "$new_name" ] + + rm "$new_name" +} + +@test "Test file name conversion with brackets and spaces" { + og_file='/tmp/file.name-with(brackets]and spaces.test' + new_name='/tmp/file.name-with-brackets-and_spaces.test' + + touch "$og_file" + + run convert-filenames.sh "$og_file" + + # Verify the file has been renamed correctly + [ "$status" -eq 0 ] + [ "$output" = "$new_name" ] + + rm "$new_name" +} +### +@test "Test file name conversion with consecutive occurrences of characters" { + og_file='/tmp/filename_-_with--consecutive__occurrences-.test' + new_name='/tmp/filename-with-consecutive_occurrences.test' + + touch "$og_file" + + run convert-filenames.sh "$og_file" + + # Verify the file has been renamed correctly + [ "$status" -eq 0 ] + [ "$output" = "$new_name" ] + + rm "$new_name" +} + +@test "Test file name conversion with leading special characters and uppercases" { + og_file='/tmp/@FileName-w-leaDing-char-aNd-Uppercases' + new_name='/tmp/filename-w-leading-char-and-uppercases' + + touch "$og_file" + + run convert-filenames.sh "$og_file" + + # Verify the file has been renamed correctly + [ "$status" -eq 0 ] + [ "$output" = "$new_name" ] + + rm "$new_name" +} -- cgit v1.2.3