Skip to content

Commit

Permalink
test: Add makefile rule to check if ports are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Mar 2, 2019
1 parent 62eeed7 commit 73333d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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/

Expand All @@ -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
15 changes: 15 additions & 0 deletions scripts/check-ports.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 73333d9

Please sign in to comment.