Skip to content

Commit dc630f0

Browse files
committed
fixup! Introduce script testing
1 parent 0edf93a commit dc630f0

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

scripts/testDetectChangedFiles.sh

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,78 +41,95 @@ fail() {
4141
echo "testDetectChangedFiles: Starting tests...."
4242

4343
# Create testing resources
44+
testCaseNumber=0
4445
temporaryTestDirectory=$(mktemp -d 2>/dev/null || mktemp -d -t 'temporaryTestDirectory')
4546
testHashFile="${temporaryTestDirectory}/testHashFile.sha"
4647
testFileForChangeDetection="${temporaryTestDirectory}/testFileForChangeDetection.txt"
4748
echo "Some Test Content" > "${testFileForChangeDetection}"
4849

49-
# Test case 1
50-
echo "testDetectChangedFiles: 1.) Create missing hashfile and report that as changed file."
50+
# Test cases
51+
testCaseNumber=$((testCaseNumber + 1))
52+
echo "testDetectChangedFiles: ${testCaseNumber}.) Create missing hashfile and report that as changed file."
5153
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection}")
5254
if [ "${changeDetectionReturnCode}" != "1" ]; then
53-
fail "1.) Test failed: Expected return code 1 for non existing hash file (change detected), but got ${changeDetectionReturnCode}."
55+
fail "${testCaseNumber}.) Test failed: Expected return code 1 for non existing hash file (change detected), but got ${changeDetectionReturnCode}."
5456
fi
5557

56-
# Test case 2
57-
echo "testDetectChangedFiles: 2.) Detect an unchanged file when the hashfile contains the same value as the newly calculated one."
58+
testCaseNumber=$((testCaseNumber + 1))
59+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect an unchanged file when the hashfile contains the same value as the newly calculated one."
5860
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection}")
5961
if [ "${changeDetectionReturnCode}" != "0" ]; then
60-
fail "2.) Tests failed: Expected return code 0 for an existing hash file with matching value (no change detected), but got ${changeDetectionReturnCode}."
62+
fail "${testCaseNumber}.) Tests failed: Expected return code 0 for an existing hash file with matching value (no change detected), but got ${changeDetectionReturnCode}."
6163
fi
6264

63-
# Test case 3
64-
echo "testDetectChangedFiles: 3.) Detect a changed file when the hashfile contains a different value as the current one."
65+
testCaseNumber=$((testCaseNumber + 1))
66+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect a changed file when the hashfile contains a different value as the current one."
6567
echo "Some CHANGED Test Content" > "${testFileForChangeDetection}"
6668
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection}")
6769
if [ "${changeDetectionReturnCode}" != "2" ]; then
68-
fail "3.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
70+
fail "${testCaseNumber}.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
6971
fi
7072

71-
# Test case 4
72-
echo "testDetectChangedFiles: 4.) Detect an unchanged file when the hashfile contains the same value as the current one again. Same as 2.) but different after 3.)."
73+
testCaseNumber=$((testCaseNumber + 1))
74+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect a changed directory when the hashfile contains a different value as the current one."
75+
echo "Some CHANGED Test Directory Content" > "${testFileForChangeDetection}"
76+
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${temporaryTestDirectory}")
77+
if [ "${changeDetectionReturnCode}" != "2" ]; then
78+
fail "${testCaseNumber}.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
79+
fi
80+
81+
testCaseNumber=$((testCaseNumber + 1))
82+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect an unchanged directory when the hashfile contains the same value as the newly calculated one."
83+
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${temporaryTestDirectory}")
84+
if [ "${changeDetectionReturnCode}" != "0" ]; then
85+
fail "${testCaseNumber}.) Tests failed: Expected return code 0 for an existing hash file with matching value (no change detected), but got ${changeDetectionReturnCode}."
86+
fi
87+
88+
testCaseNumber=$((testCaseNumber + 1))
89+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect an unchanged file when the hashfile contains the same value as the current one again. Same as 2.) but different after 3.)."
7390
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection}")
7491
if [ "${changeDetectionReturnCode}" != "0" ]; then
75-
fail "4.) Tests failed: Expected return code 0 for an existing hash file with matching value (no change detected), but got ${changeDetectionReturnCode}."
92+
fail "${testCaseNumber}.) Tests failed: Expected return code 0 for an existing hash file with matching value (no change detected), but got ${changeDetectionReturnCode}."
7693
fi
7794

78-
# Test case 5
79-
echo "testDetectChangedFiles: 5.) Detect a changed file when the hashfile contains a different value as the current one in read-only mode."
95+
testCaseNumber=$((testCaseNumber + 1))
96+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect a changed file when the hashfile contains a different value as the current one in read-only mode."
8097
echo "Some CHANGED AGAIN Test Content" > "${testFileForChangeDetection}"
8198
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection}" --readonly)
8299
if [ "${changeDetectionReturnCode}" != "2" ]; then
83-
fail "5.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
100+
fail "${testCaseNumber}.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
84101
fi
85102

86-
# Test case 6
87-
echo "testDetectChangedFiles: 6.) Detect a changed file when the hashfile hadn't been update with the last change detection in read-only mode."
103+
testCaseNumber=$((testCaseNumber + 1))
104+
echo "testDetectChangedFiles: ${testCaseNumber}.) Detect a changed file when the hashfile hadn't been update with the last change detection in read-only mode."
88105
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection}" --readonly)
89106
if [ "${changeDetectionReturnCode}" != "2" ]; then
90-
fail "6.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
107+
fail "${testCaseNumber}.) Tests failed: Expected return code 2 for an existing hash file with differing value (change detected), but got ${changeDetectionReturnCode}."
91108
fi
92109

93-
# Test case 7
94-
echo "testDetectChangedFiles: 7.) Fail on not existing first path"
110+
testCaseNumber=$((testCaseNumber + 1))
111+
echo "testDetectChangedFiles: ${testCaseNumber}.) Fail on not existing first path"
95112
if changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "./nonExistingFile.txt,${testFileForChangeDetection}"); then
96-
fail "7.) Tests failed: Expected to fail due to a wrong paths option, but got ${changeDetectionReturnCode}."
113+
fail "${testCaseNumber}.) Tests failed: Expected to fail due to a wrong paths option, but got ${changeDetectionReturnCode}."
97114
fi
98115

99-
# Test case 8
100-
echo "testDetectChangedFiles: 8.) Fail on not existing second path"
116+
testCaseNumber=$((testCaseNumber + 1))
117+
echo "testDetectChangedFiles: ${testCaseNumber}.) Fail on not existing second path"
101118
if changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "${testFileForChangeDetection},./nonExistingFile2.txt"); then
102-
fail "8.) Tests failed: Expected to fail due to a wrong paths option, but got ${changeDetectionReturnCode}."
119+
fail "${testCaseNumber}.) Tests failed: Expected to fail due to a wrong paths option, but got ${changeDetectionReturnCode}."
103120
fi
104121

105-
# Test case 9
106-
echo "testDetectChangedFiles: 9.) Interpret missing paths as 'nothing changed'."
122+
testCaseNumber=$((testCaseNumber + 1))
123+
echo "testDetectChangedFiles: ${testCaseNumber}.) Interpret missing paths as 'nothing changed'."
107124
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths)
108125
if [ "${changeDetectionReturnCode}" != "0" ]; then
109-
fail "9.) Tests failed: Expected return code 0 if there are no files to check, but got ${changeDetectionReturnCode}."
126+
fail "${testCaseNumber}.) Tests failed: Expected return code 0 if there are no files to check, but got ${changeDetectionReturnCode}."
110127
fi
111128

112-
# Test case 10
113-
echo "testDetectChangedFiles: 10.) Fail on not unknown command-line option"
129+
testCaseNumber=$((testCaseNumber + 1))
130+
echo "testDetectChangedFiles: ${testCaseNumber}.) Fail on not unknown command-line option"
114131
if changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${testHashFile}" --paths "./nonExistingFile.txt,${testFileForChangeDetection}" --unknown); then
115-
fail "10.) Tests failed: Expected to fail due to a an unknown command-line option, but got ${changeDetectionReturnCode}."
132+
fail "${testCaseNumber}.) Tests failed: Expected to fail due to a an unknown command-line option, but got ${changeDetectionReturnCode}."
116133
fi
117134

118135
successful

0 commit comments

Comments
 (0)