File: striptests

package info (click to toggle)
shellcheck 0.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,052 kB
  • sloc: haskell: 15,964; sh: 59; makefile: 15
file content (78 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/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() {
  local data
  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() {
  printf '%s\n' '-- AUTOGENERATED from ShellCheck by striptests. Do not modify.'
  awk '
    BEGIN {
      state = 0;
    }

    /STRIP/ { next; }
    /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