Allow stripping unit tests
This commit is contained in:
parent
da4072a118
commit
32af2783f0
|
@ -14,6 +14,8 @@ before_install:
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir deploy
|
- mkdir deploy
|
||||||
|
# Remove all tests to reduce binary size
|
||||||
|
- ./striptests
|
||||||
# Linux Docker image
|
# Linux Docker image
|
||||||
- name="$DOCKER_BASE"
|
- name="$DOCKER_BASE"
|
||||||
- DOCKER_BUILDS="$DOCKER_BUILDS $name"
|
- DOCKER_BUILDS="$DOCKER_BUILDS $name"
|
||||||
|
@ -25,6 +27,8 @@ script:
|
||||||
- id=$(docker create "$name:current")
|
- id=$(docker create "$name:current")
|
||||||
- docker cp "$id:/bin/shellcheck" "shellcheck"
|
- docker cp "$id:/bin/shellcheck" "shellcheck"
|
||||||
- docker rm "$id"
|
- docker rm "$id"
|
||||||
|
- ls -l shellcheck
|
||||||
|
- ./shellcheck myscript
|
||||||
- for tag in $TAGS; do cp "shellcheck" "deploy/shellcheck-$tag.linux"; done
|
- for tag in $TAGS; do cp "shellcheck" "deploy/shellcheck-$tag.linux"; done
|
||||||
# Linux Alpine based Docker image
|
# Linux Alpine based Docker image
|
||||||
- name="$DOCKER_BASE-alpine"
|
- name="$DOCKER_BASE-alpine"
|
||||||
|
|
|
@ -86,8 +86,8 @@ executable shellcheck
|
||||||
json >= 0.3.6,
|
json >= 0.3.6,
|
||||||
mtl >= 2.2.1,
|
mtl >= 2.2.1,
|
||||||
parsec >= 3.0,
|
parsec >= 3.0,
|
||||||
regex-tdfa,
|
QuickCheck >= 2.7.4,
|
||||||
QuickCheck >= 2.7.4
|
regex-tdfa
|
||||||
main-is: shellcheck.hs
|
main-is: shellcheck.hs
|
||||||
|
|
||||||
test-suite test-shellcheck
|
test-suite test-shellcheck
|
||||||
|
@ -100,7 +100,7 @@ test-suite test-shellcheck
|
||||||
json,
|
json,
|
||||||
mtl >= 2.2.1,
|
mtl >= 2.2.1,
|
||||||
parsec,
|
parsec,
|
||||||
regex-tdfa,
|
QuickCheck >= 2.7.4,
|
||||||
QuickCheck >= 2.7.4
|
regex-tdfa
|
||||||
main-is: test/shellcheck.hs
|
main-is: test/shellcheck.hs
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
-}
|
-}
|
||||||
{-# LANGUAGE TemplateHaskell, FlexibleContexts #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
module ShellCheck.Analytics (runAnalytics, ShellCheck.Analytics.runTests) where
|
module ShellCheck.Analytics (runAnalytics, ShellCheck.Analytics.runTests) where
|
||||||
|
|
||||||
import ShellCheck.AST
|
import ShellCheck.AST
|
||||||
|
|
|
@ -21,9 +21,7 @@
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
|
||||||
-- This module contains checks that examine specific commands by name.
|
-- This module contains checks that examine specific commands by name.
|
||||||
module ShellCheck.Checks.Commands (checker
|
module ShellCheck.Checks.Commands (checker , ShellCheck.Checks.Commands.runTests) where
|
||||||
, ShellCheck.Checks.Commands.runTests
|
|
||||||
) where
|
|
||||||
|
|
||||||
import ShellCheck.AST
|
import ShellCheck.AST
|
||||||
import ShellCheck.ASTLib
|
import ShellCheck.ASTLib
|
||||||
|
|
|
@ -19,9 +19,7 @@
|
||||||
-}
|
-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
module ShellCheck.Checks.ShellSupport (checker
|
module ShellCheck.Checks.ShellSupport (checker , ShellCheck.Checks.ShellSupport.runTests) where
|
||||||
, ShellCheck.Checks.ShellSupport.runTests
|
|
||||||
) where
|
|
||||||
|
|
||||||
import ShellCheck.AST
|
import ShellCheck.AST
|
||||||
import ShellCheck.ASTLib
|
import ShellCheck.ASTLib
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
-}
|
-}
|
||||||
{-# LANGUAGE NoMonomorphismRestriction, TemplateHaskell, FlexibleContexts #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE NoMonomorphismRestriction #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
module ShellCheck.Parser (parseScript, runTests) where
|
module ShellCheck.Parser (parseScript, runTests) where
|
||||||
|
|
||||||
import ShellCheck.AST
|
import ShellCheck.AST
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# This file strips all unit tests from ShellCheck, removing
|
||||||
|
# the dependency on QuickCheck and Template Haskell and
|
||||||
|
# reduces the binary size considerably.
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
sponge() {
|
||||||
|
data="$(cat)"
|
||||||
|
printf '%s\n' "$data" > "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
modify() {
|
||||||
|
if ! "${@:2}" < "$1" | sponge "$1"
|
||||||
|
then
|
||||||
|
{
|
||||||
|
printf 'Failed to modify %s: ' "$1"
|
||||||
|
printf '%q ' "${@:2}"
|
||||||
|
printf '\n'
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
detestify() {
|
||||||
|
echo "-- AUTOGENERATED from ShellCheck by striptests. Do not modify."
|
||||||
|
awk '
|
||||||
|
BEGIN {
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/LANGUAGE TemplateHaskell/ { next; }
|
||||||
|
/^import Test\./ { next; }
|
||||||
|
|
||||||
|
/^module/ {
|
||||||
|
sub(/,[^,)]*runTests/, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
# Delete tests
|
||||||
|
/^prop_/ { state = 1; next; }
|
||||||
|
|
||||||
|
# ..and any blank lines following them.
|
||||||
|
state == 1 && /^ / { next; }
|
||||||
|
|
||||||
|
# Template Haskell marker
|
||||||
|
/^return / {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
{ state = 0; print; }
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ! -e ShellCheck.cabal ]]
|
||||||
|
then
|
||||||
|
echo "Run me from the ShellCheck directory." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d '.git' ]] && ! git diff --exit-code > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
echo "You have local changes! These may be overwritten." >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
modify ShellCheck.cabal sed -e '
|
||||||
|
/QuickCheck/d
|
||||||
|
/^test-suite/{ s/.*//; q; }
|
||||||
|
'
|
||||||
|
|
||||||
|
find . -name '.git' -prune -o -type f -name '*.hs' -print |
|
||||||
|
while IFS= read -r file
|
||||||
|
do
|
||||||
|
modify "$file" detestify
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in New Issue