This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 888
/
check-bin.sh
executable file
·134 lines (105 loc) · 5.56 KB
/
check-bin.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Copyright 2014 Palantir Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
num_failures=0
expectOut () {
actual=$1
expect=$2
msg=$3
nodeV=`node -v`
# if Node 0.10.*, node will sometimes exit with status 8 when an error is thrown
if [[ $expect != $actual || $nodeV == v0.10.* && $expect == 1 && $actual == 8 ]] ; then
echo "$msg: expected $expect got $actual"
num_failures=$(expr $num_failures + 1)
fi
}
echo "Checking tslint binary"
# make sure calling tslint with no args exits correctly.
./bin/tslint
expectOut $? 1 "tslint with no args did not exit correctly"
# make sure calling tslint with a good file exits correctly.
./bin/tslint src/configuration.ts
expectOut $? 0 "tslint with a good file did not exit correctly"
# make sure calling tslint without the -f flag exits correctly
./bin/tslint src/configuration.ts src/formatterLoader.ts
expectOut $? 0 "tslint with valid arguments did not exit correctly"
# make sure calling tslint with the -f flag exits correctly
./bin/tslint src/configuration.ts -f src/formatterLoader.ts
expectOut $? 1 "tslint with -f flag did not exit correctly"
# make sure calling tslint with a CLI custom rules directory that doesn't exist fails
# (redirect stderr because it's confusing to see a stack trace during the build)
./bin/tslint -c ./test/config/tslint-custom-rules.json -r ./someRandomDir src/tslint.ts
expectOut $? 1 "tslint with -r pointing to a nonexistent directory did not fail"
# make sure calling tslint with a CLI custom rules directory that does exist finds the errors it should
./bin/tslint -c ./test/config/tslint-custom-rules.json -r ./test/files/custom-rules src/tslint.ts
expectOut $? 2 "tslint with with -r pointing to custom rules did not find lint failures"
# make sure calling tslint with a rulesDirectory in a config file works
./bin/tslint -c ./test/config/tslint-custom-rules-with-dir.json src/tslint.ts
expectOut $? 2 "tslint with with JSON pointing to custom rules did not find lint failures"
# make sure calling tslint with an array as rulesDirectory in a config file works
./bin/tslint -c ./test/config/tslint-custom-rules-with-two-dirs.json src/tslint.ts
expectOut $? 2 "tslint with with JSON pointing to two custom rules did not find lint failures from second directory"
# make sure --force option makes TSLint return a status code of 0 when there are lint errors
./bin/tslint -c ./test/config/tslint-custom-rules.json -r ./test/files/custom-rules --force src/tslint.ts
expectOut $? 0 "tslint with with -r pointing to custom rules did not find lint failures"
# make sure path to config without a preceding "./" works on the CLI
./bin/tslint -c test/config/tslint-almost-empty.json src/tslint.ts
expectOut $? 0 "-c relative path without ./ did not work"
# make sure calling tslint with a config file which extends a package relative to the config file works
./bin/tslint -c test/config/tslint-extends-package-no-mod.json src/tslint.ts
expectOut $? 0 "tslint (with config file extending relative package) did not work"
# make sure tslint --init generates a file
cd ./bin
if [ -f tslint.json ]; then
rm tslint.json
fi
./tslint --init
if [ ! -f tslint.json ]; then
echo "--init failed, tslint.json not created"
num_failures=$(expr $num_failures + 1)
fi
expectOut $? 0 "tslint with --init flag did not exit correctly"
# should fail since tslint.json already exists
./tslint --init
expectOut $? 1 "tslint with --init flag did not exit correctly when tslint.json already exists"
rm tslint.json
cd ..
# ensure --test command works correctly
./bin/tslint --test test/rules/no-eval
expectOut $? 0 "tslint --test did not exit correctly for a passing test"
./bin/tslint --test test/files/incorrect-rule-test
expectOut $? 1 "tslint --test did not exit correctly for a failing test"
# ensure --test command works correctly with custom rules
./bin/tslint --test test/files/custom-rule-rule-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules"
./bin/tslint -r test/files/custom-rules-2 --test test/files/custom-rule-cli-rule-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules from the CLI"
# ensure --test command works correctly with fixes
./bin/tslint --test test/files/fixes-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with fixes"
./bin/tslint --test test/files/incorrect-fixes-test
expectOut $? 1 "tslint --test did not exit correctly for a failing test with fixes"
# make sure tslint exits correctly when tsconfig is specified but no files are given
./bin/tslint -c test/files/tsconfig-test/tslint.json --project test/files/tsconfig-test/tsconfig.json
expectOut $? 0 "tslint with tsconfig did not exit correctly"
# make sure tslint only lints files given if tsconfig is also specified
./bin/tslint -c test/files/tsconfig-test/tslint.json --project test/files/tsconfig-test/tsconfig.json test/files/tsconfig-test/other.test.ts
expectOut $? 2 "tslint with tsconfig and files did not find lint failures from given files"
if [ $num_failures != 0 ]; then
echo "Failed $num_failures tests"
exit 1
else
echo "Done!"
exit 0
fi