-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(rockspec) add a script to validate rockspec file
- Loading branch information
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
shopt -s nullglob | ||
|
||
fail() { | ||
echo "Failure: $@" | ||
exit 1 | ||
} | ||
|
||
lint() { | ||
echo "Linting..." | ||
|
||
luarocks lint "$1" | ||
} | ||
|
||
read_modules() { | ||
local spec="$1" | ||
resty -e ' | ||
local fn = loadstring(io.stdin:read("*a")) | ||
local rock = {} | ||
setfenv(fn, rock) | ||
fn() | ||
for mod, fname in pairs(rock.build.modules) do | ||
print(fname .. "|" .. mod) | ||
end | ||
' < "$spec" | ||
} | ||
|
||
check_modules() { | ||
local spec=$1 | ||
local -A files=() | ||
|
||
echo "Checking modules..." | ||
|
||
for line in $(read_modules "$spec"); do | ||
fname=${line%|*} | ||
module=${line#*|} | ||
files[$fname]="$module" | ||
|
||
if [[ ! -f $fname ]]; then | ||
fail "module ($module) file ($fname) is missing" | ||
fi | ||
done | ||
|
||
for fname in $(git ls-files 'kong/*.lua'); do | ||
mod="${files[$fname]:-}" | ||
|
||
if [[ -z ${mod:-} ]]; then | ||
fail "file ($fname) not found in rockspec ($spec)" | ||
fi | ||
done | ||
} | ||
|
||
|
||
main() { | ||
local files=(kong-*.rockspec) | ||
local spec | ||
|
||
if (( ${#files[@]} == 0 )); then | ||
fail "no rockspec file found" | ||
|
||
elif (( ${#files[@]} > 1 )); then | ||
fail "multiple rockspec files found: ${files[*]}" | ||
|
||
else | ||
spec=${files[0]} | ||
fi | ||
|
||
echo "Found rockspec file to validate: $spec" | ||
|
||
lint "$spec" | ||
|
||
check_modules "$spec" | ||
|
||
echo "OK!" | ||
} | ||
|
||
|
||
main "$@" |