| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # author: deadc0de6 |
| 3 | # |
| 4 | # test negative ignore on compare |
| 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 | # dotdrop directory |
| 30 | basedir=$(mktempscip-shell system . . mktemp. -d --suffix='-dotdrop-tests' 2>/dev/nullscip-shell filesystem . . `/dev/null`. || mktempscip-shell system . . mktemp. -d) |
| 31 | # the dotfile to be updated |
| 32 | tmpd=$(mktempscip-shell system . . mktemp. -d --suffix='-dotdrop-tests' 2>/dev/nullscip-shell filesystem . . `/dev/null`. || mktempscip-shell system . . mktemp. -d) |
| 33 | |
| 34 | echoscip-shell system . . echo. "[+] dotdrop dir: ${basedir}" |
| 35 | echoscip-shell system . . echo. "[+] dotpath dir: ${basedir}/dotfiles" |
| 36 | echoscip-shell system . . echo. "[+] dst dir: ${tmpd}" |
| 37 | |
| 38 | # dotfiles in dotdrop |
| 39 | mkdirscip-shell system . . mkdir. -p "${basedir}"/dotfiles/a/{b,c,x} |
| 40 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/b/abfile1 |
| 41 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/b/abfile2 |
| 42 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/b/abfile3 |
| 43 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/c/acfile |
| 44 | echoscip-shell system . . echo. 'original' > "${basedir}"/dotfiles/a/x/axfile |
| 45 | |
| 46 | # filesystem |
| 47 | mkdirscip-shell system . . mkdir. -p "${tmpd}"/a/{b,c,d,x} |
| 48 | echoscip-shell system . . echo. "updated" > "${tmpd}/a/b/abfile1" |
| 49 | echoscip-shell system . . echo. "updated" > "${tmpd}/a/b/abfile2" |
| 50 | echoscip-shell system . . echo. "updated" > "${tmpd}/a/b/abfile3" |
| 51 | echoscip-shell system . . echo. "updated" > "${tmpd}/a/c/acfile" |
| 52 | echoscip-shell system . . echo. "updated" > "${tmpd}/a/d/adfile" |
| 53 | echoscip-shell system . . echo. "updated" > "${tmpd}/a/x/axfile" |
| 54 | |
| 55 | clear_on_exit "${basedir}" |
| 56 | clear_on_exit "${tmpd}" |
| 57 | |
| 58 | # create the config file |
| 59 | cfg="${basedir}/config.yaml" |
| 60 | catscip-shell system . . cat. > "${cfg}" << _EOF |
| 61 | config: |
| 62 | backup: false |
| 63 | create: true |
| 64 | dotpath: dotfiles |
| 65 | dotfiles: |
| 66 | d_abc: |
| 67 | dst: ${tmpd}/a |
| 68 | src: a |
| 69 | cmpignore: |
| 70 | - "*" |
| 71 | - "!*/c/**" |
| 72 | - "!*/d/**" |
| 73 | - "!x/**" |
| 74 | profiles: |
| 75 | p1: |
| 76 | dotfiles: |
| 77 | - d_abc |
| 78 | _EOF |
| 79 | |
| 80 | # compare |
| 81 | echoscip-shell system . . echo. "[+] compare" |
| 82 | set +e |
| 83 | cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 |
| 84 | ret="$?" |
| 85 | echoscip-shell system . . echo. "return code: ${ret}" |
| 86 | [scip-shell system . . `[`. "${ret}" != "1" ] && exit 1 |
| 87 | set -e |
| 88 | |
| 89 | echoscip-shell system . . echo. "OK" |
| 90 | exit 0 |