Skip to content

Commit

Permalink
scripts: add the inefficient assert function usage check (tikv#5110)
Browse files Browse the repository at this point in the history
close tikv#5104

Add the inefficient assert function usage check.

Signed-off-by: JmPotato <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
JmPotato and ti-chi-bot authored Jun 7, 2022
1 parent e19dc71 commit 1f3c305
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ install-tools:

#### Static checks ####

check: install-tools static tidy check-plugin errdoc check-testing-t
check: install-tools static tidy generate-errdoc check-plugin check-test

static: install-tools
@ echo "gofmt ..."
Expand All @@ -160,21 +160,22 @@ tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

@ for mod in $(SUBMODULES); do cd $$mod && $(MAKE) tidy && cd - > /dev/null; done

generate-errdoc: install-tools
@echo "generating errors.toml..."
./scripts/generate-errdoc.sh

check-plugin:
@echo "checking plugin"
@echo "checking plugin..."
cd ./plugin/scheduler_example && $(MAKE) evictLeaderPlugin.so && rm evictLeaderPlugin.so

errdoc: install-tools
@echo "generator errors.toml"
./scripts/check-errdoc.sh

check-testing-t:
./scripts/check-testing-t.sh
check-test:
@echo "checking test..."
./scripts/check-test.sh

.PHONY: check static tidy check-plugin errdoc docker-build-test check-testing-t
.PHONY: check static tidy generate-errdoc check-plugin check-test

#### Test utils ####

Expand Down
18 changes: 18 additions & 0 deletions scripts/check-testing-t.sh → scripts/check-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ if [ "$res" ]; then
exit 1
fi

# Check if there is any inefficient assert function usage in package.

res=$(grep -rn --include=\*_test.go -E "(re|suite|require)\.(True|False)\((t, )?reflect\.DeepEqual\(" . | sort -u) \

if [ "$res" ]; then
echo "following packages use the inefficient assert function: please replace reflect.DeepEqual with require.Equal"
echo "$res"
exit 1
fi

res=$(grep -rn --include=\*_test.go -E "(re|suite|require)\.(True|False)\((t, )?strings\.Contains\(" . | sort -u)

if [ "$res" ]; then
echo "following packages use the inefficient assert function: please replace strings.Contains with require.Contains"
echo "$res"
exit 1
fi

exit 0
File renamed without changes.

0 comments on commit 1f3c305

Please sign in to comment.