| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # author: deadc0de6 |
| 3 | # |
| 4 | # test negative ignore on install |
| 5 | # returns 1 in case of error |
| 6 | # |
| 7 | |
| 8 | ## start-cookie |
| 9 | set -eu -o errtrace -o pipefail |
| 10 | cur=$(cd "$(dirnamescip-shell system . . dirname. "${0}")" && pwdscip-shell system . . pwd.) |
| 11 | ddpath="${cur}/../" |
| 12 | PPATH="{PYTHONPATH:-}" |
| 13 | export PYTHONPATH="${ddpath}:${PPATH}" |
| 14 | altbin="python3 -m dotdrop.dotdrop" |
| 15 | if hash coverage 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 16 | mkdirscip-shell system . . mkdir. -p coverages/ |
| 17 | altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop" |
| 18 | fi |
| 19 | bin="${DT_BIN:-${altbin}}" |
| 20 | # shellcheck source=tests-ng/helpers |
| 21 | source "${cur}"/helpers |
| 22 | echoscip-shell system . . echo. -e "$(tputscip-shell system . . tput. setaf 6)==> RUNNING $(basenamescip-shell system . . basename. "${BASH_SOURCE[0]}") <==$(tputscip-shell system . . tput. sgr0)" |
| 23 | ## end-cookie |
| 24 | |
| 25 | ################################################################ |
| 26 | # this is the test |
| 27 | ################################################################ |
| 28 | |
| 29 | # $1 pattern |
| 30 | # $2 path |
| 31 | grep_or_failscip-shell shell dotdrop 1.16.1-1 grep_or_fail().() |
| 32 | { |
| 33 | [scip-shell system . . `[`. ! -e "${2}" ] && (echoscip-shell system . . echo. "file ${2} does not exist" && exit 1) |
| 34 | grepscip-shell system . . grep. "${1}" "${2}" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || (echoscip-shell system . . echo. "pattern \"${1}\" not found in ${2}" && exit 1) |
| 35 | } |
| 36 | |
| 37 | # dotdrop directory |
| 38 | basedir=$(mktempscip-shell system . . mktemp. -d --suffix='-dotdrop-tests' 2>/dev/nullscip-shell filesystem . . `/dev/null`. || mktempscip-shell system . . mktemp. -d) |
| 39 | # the dotfile to be updated |
| 40 | tmpd=$(mktempscip-shell system . . mktemp. -d --suffix='-dotdrop-tests' 2>/dev/nullscip-shell filesystem . . `/dev/null`. || mktempscip-shell system . . mktemp. -d) |
| 41 | |
| 42 | echoscip-shell system . . echo. "[+] dotdrop dir: ${basedir}" |
| 43 | echoscip-shell system . . echo. "[+] dotpath dir: ${basedir}/dotfiles" |
| 44 | echoscip-shell system . . echo. "[+] dst dir: ${tmpd}" |
| 45 | |
| 46 | # dotfiles in dotdrop |
| 47 | mkdirscip-shell system . . mkdir. -p "${basedir}"/dotfiles/a/{b,c,x} |
| 48 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/b/abfile1 |
| 49 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/b/abfile2 |
| 50 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/b/abfile3 |
| 51 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/c/acfile |
| 52 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/x/axfile |
| 53 | |
| 54 | clear_on_exit "${basedir}" |
| 55 | clear_on_exit "${tmpd}" |
| 56 | |
| 57 | # create the config file |
| 58 | cfg="${basedir}/config.yaml" |
| 59 | catscip-shell system . . cat. > "${cfg}" << _EOF |
| 60 | config: |
| 61 | backup: false |
| 62 | create: true |
| 63 | dotpath: dotfiles |
| 64 | dotfiles: |
| 65 | d_abc: |
| 66 | dst: ${tmpd}/a |
| 67 | src: a |
| 68 | instignore: |
| 69 | - "*" |
| 70 | - "!*/c/**" |
| 71 | - "!*/d/**" |
| 72 | - "!x/**" |
| 73 | profiles: |
| 74 | p1: |
| 75 | dotfiles: |
| 76 | - d_abc |
| 77 | _EOF |
| 78 | |
| 79 | # install |
| 80 | echoscip-shell system . . echo. "[+] install" |
| 81 | cd "${ddpath}" | ${bin} install -f -c "${cfg}" --verbose --profile=p1 |
| 82 | |
| 83 | [scip-shell system . . `[`. -d "${tmpd}/a/b" ] && (echoscip-shell system . . echo. "/a/b createdscip-shell filesystem . . `/a/b created`." && exit 1) |
| 84 | grep_or_failscip-shell shell dotdrop 1.16.1-1 grep_or_fail(). "original" "${tmpd}/a/c/acfile" |
| 85 | #grep_or_fail "original" "${tmpd}/a/d/adfile" |
| 86 | grep_or_failscip-shell shell dotdrop 1.16.1-1 grep_or_fail(). "original" "${tmpd}/a/x/axfile" |
| 87 | |
| 88 | echoscip-shell system . . echo. "OK" |
| 89 | exit 0 |