Skip to content

Commit 467e7ac

Browse files
committed
review: check parameters
1 parent 314611b commit 467e7ac

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ fast_check_generated:
6565
# Benchmark with a local version
6666
# LINTER=gosec VERSION=v1.59.0 make bench_local
6767
bench_local: hyperfine
68+
@:$(call check_defined, LINTER VERSION, 'missing parameter(s)')
6869
@./scripts/bench/bench_local.sh $(LINTER) $(VERSION)
6970
.PHONY: bench_local
7071

7172
# Benchmark between 2 existing versions
72-
# LINTER=gosec VERSION_OLD=v1.58.2 VERSION_NEW=v1.59.0 make bench_version
73+
# make bench_version LINTER=gosec VERSION_OLD=v1.58.2 VERSION_NEW=v1.59.0
7374
bench_version: hyperfine
75+
@:$(call check_defined, LINTER VERSION_OLD VERSION_NEW, 'missing parameter(s)')
7476
@./scripts/bench/bench_version.sh $(LINTER) $(VERSION_OLD) $(VERSION_NEW)
7577
.PHONY: bench_version
7678

@@ -120,3 +122,19 @@ website_dump_info:
120122
update_contributors_list:
121123
cd .github/contributors && npm run all
122124

125+
# Functions
126+
127+
# Check that given variables are set and all have non-empty values,
128+
# die with an error otherwise.
129+
#
130+
# Params:
131+
# 1. Variable name(s) to test.
132+
# 2. (optional) Error message to print.
133+
#
134+
# https://stackoverflow.com/a/10858332/8228109
135+
check_defined = \
136+
$(strip $(foreach 1,$1, \
137+
$(call __check_defined,$1,$(strip $(value 2)))))
138+
__check_defined = \
139+
$(if $(value $1),, \
140+
$(error Undefined $1$(if $2, ($2))))

scripts/bench/bench_local.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,3 @@ hyperfine \
3636
--prepare './golangci-lint cache clean' "./golangci-lint run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER}" \
3737
--prepare "./golangci-lint-${VERSION} cache clean" "./golangci-lint-${VERSION} run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER}"
3838

39-
## Clean
40-
41-
rm "./golangci-lint-${VERSION}"

scripts/bench/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ The script use [Hyperfine](https://github.com/sharkdp/hyperfine) to benchmark th
55
## Benchmark one linter: with a local version
66

77
```bash
8-
LINTER=gosec VERSION=v1.59.0 make bench_local
8+
make bench_local LINTER=gosec VERSION=v1.59.0
99
```
1010

1111
## Benchmark one linter: between 2 existing versions
1212

1313
```bash
14-
LINTER=gosec VERSION_OLD=v1.58.1 VERSION_NEW=v1.59.0 make bench_version
14+
make bench_version LINTER=gosec VERSION_OLD=v1.58.1 VERSION_NEW=v1.59.0
1515
```

0 commit comments

Comments
 (0)