-
Notifications
You must be signed in to change notification settings - Fork 177
/
test.sh
executable file
·46 lines (39 loc) · 1.81 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
# test.sh
# Checks that these scripts convert the unformatted file to the expected formatted result.
# Copyright 2015 Square, Inc
set -o nounset
set -o errexit
function runTest() {
formatted_example="Testing Support/$1FormattedExample$2"
unformatted_example="Testing Support/$1UnformattedExample$2"
formatted_in_place="Testing Support/$1FormattedInPlace$2"
difference=$(./format-objc-file-dry-run.sh "$unformatted_example" | diff -q "$formatted_example" - | wc -l)
if [ "$difference" -gt 0 ]; then
echo -e "Tests fail. Run\n\t diff <(./format-objc-file-dry-run.sh '$unformatted_example') '$formatted_example' \nto see why."
exit $difference
fi
# Test that the formatted version does not need further formatting
difference=$(./format-objc-file-dry-run.sh "$formatted_example" | diff -q "$formatted_example" - | wc -l)
if [ "$difference" -gt 0 ]; then
echo -e "Tests fail. Run\n\t diff <(./format-objc-file-dry-run.sh '$formatted_example') '$formatted_example' \nto see why."
exit $difference
fi
# Test that the in-place behavior does not differ from stdout
cp "$unformatted_example" "$formatted_in_place"
./format-objc-file.sh "$formatted_in_place"
difference=$(./format-objc-file-dry-run.sh "$unformatted_example" | diff -q "$formatted_in_place" - | wc -l)
if [ "$difference" -gt 0 ]; then
echo -e "Tests fail. Run\n\t diff <(./format-objc-file-dry.sh '$unformatted_example') '$formatted_in_place' \nto see why."
echo "Then, remove the temporary file '$formatted_in_place'"
exit $difference
fi
rm "$formatted_in_place"
}
runTest "" ".m"
runTest "ExemptViaPragma" ".m"
runTest "ExemptViaComment" ".m"
runTest "Unicode" ".m"
runTest "ImportOnlyHeader" ".h"
runTest "QuotesInFirstLine" ".m"
echo "Tests pass"