[pacman-dev] repo-add test harness

Dave Reisner d at falconindy.com
Thu Jun 30 14:07:27 EDT 2011


The attached script is what I used for testing my repo-add changes, and
worked out rather well. It's extremely primitive, but it does a bit of a
smoke test again bash3 and bash4, which is important.

I imagine that the next step might be to take a variety of .PKGINFO
files and provide those as inputs for writing DB entries. This is
hopefuly the next thing on my plate after I get some more work done on
the download code.

d

-------------- next part --------------
#!/bin/bash

cachedir=/var/cache/pacman/pkg

test_path() {
  local -a packages=("$cachedir"/*.pkg.tar.xz)
  printf $'\e[1;33m::\e[0m Testing path: `%s\'\n' "$1"
  ./scripts/repo-add "$1" "${packages[0]}"
}

paths=(foo.db.tar.gz::0
       ../foo.db.tar.gz::0
       /foo.db.tar.gz::1
       /tmp/foo.files.tar.gz::0
       /mnt/lol/foo.files.tar.gz::1)

if [[ ! -f ./scripts/repo-add ]]; then
  printf './scripts/repo-add not found!\n'
  exit 1
fi

# path check regression testing
for path in "${paths[@]}"; do
  res=${path##*::}
  repo=${path%%::*}

  test_path "$repo"
  ret=$?
  printf 'got %d, expected %d: ' $ret $res
  if (( ret == res )); then
    printf "\e[1;32mPASS\e[0m\n"
    (( ++success ))
  else
    printf "\e[1;31mFAIL\e[0m\n"
    (( ++failure ))
    continue
  fi

  rm -f "$repo" "${repo%.tar.gz}"
done

# bash3 v. bash4
printf 'comparing bash3 repo tarball to bash4\n'
if type -P bash3 &>/dev/null; then
  {
    bash3 ./scripts/repo-add bash3.db.tar "$cachedir"/a*.pkg.tar.xz
    bash ./scripts/repo-add bash4.db.tar  "$cachedir"/a*.pkg.tar.xz
  } &>/dev/null
else
  printf 'bash3 not found -- skipping test\n'
fi

diff -u <(bsdtar xOf bash3.db.tar) <(bsdtar xOf bash4.db.tar)
res=0
ret=$?
printf 'got %d, expected %d: ' $ret $res
if (( ret == res )); then
  printf "\e[1;32mPASS\e[0m\n"
  (( ++success ))
else
  printf "\e[1;31mFAIL\e[0m\n"
  (( ++failure ))
fi

rm bash?.db*

echo
if (( failure )); then
  printf '%s tests failed\n' "$failure"
else
  printf 'all tests passed!\n'
fi



More information about the pacman-dev mailing list