From 73333d9556a7697ed00e90263f09f6c4d7bb793a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sat, 2 Mar 2019 21:38:29 +0100 Subject: [PATCH] test: Add makefile rule to check if ports are unique --- Makefile | 9 ++++++--- scripts/check-ports.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100755 scripts/check-ports.sh diff --git a/Makefile b/Makefile index 1ff2f42..7a50a86 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ readme: README.md ## Regenerate README.md. docs: ## Build the documentation locally. poetry run sphinx-build -E -b html docs build/docs -check: check-bandit check-black check-flake8 check-isort check-safety ## Check it all! +check: check-bandit check-black check-flake8 check-isort check-safety check-ports ## Check it all! check-black: ## Check if code is formatted nicely using black. poetry run black --check src/ tests/ @@ -35,6 +35,9 @@ check-safety: ## Check for vulnerabilities in dependencies using safety. grep -v aria2p | \ poetry run safety check --stdin --full-report 2>/dev/null +check-ports: ## Check if the ports used in the tests are all unique. + ./scripts/check-ports.sh + run-black: ## Lint the code using black. poetry run black src/ tests/ @@ -50,8 +53,8 @@ clean: clean-tests ## Delete temporary files. @rm -rf build 2>/dev/null @rm -rf dist 2>/dev/null @rm -rf src/aria2p.egg-info 2>/dev/null - @rm -rf .coverage 2>/dev/null + @rm -rf .coverage* 2>/dev/null @rm -rf .pytest_cache 2>/dev/null -test: clean-tests ## Run the tests using pytest. +test: check-ports clean-tests ## Run the tests using pytest. poetry run pytest -n6 2>/dev/null diff --git a/scripts/check-ports.sh b/scripts/check-ports.sh new file mode 100755 index 0000000..20446a3 --- /dev/null +++ b/scripts/check-ports.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +dups="$(grep -Eo 'port=[0-9]{4}' tests/test_* | cut -d: -f2 | sort | uniq -c | grep -v '1 ')" + +if [ -n "${dups}" ]; then + echo "${dups}" | while read -r dup; do + port="${dup#*=}" + num=${dup% *} + echo "-- Port ${port} used" ${num} "times:" >&2 + grep -n --color=auto "port=${port}" tests/test_* + echo + done + exit 1 +fi + +exit 0