summaryrefslogtreecommitdiff
path: root/utils/devel/chart-load-test.sh
blob: 576e0aa52549176bfcacc1ae7d2fab283062e61b (plain)
  1. #!/bin/bash
  2. #
  3. # chart-load-test.sh [SQLDIR] [CHARTFILE]
  4. #
  5. # Attempts to load the charts and associated GIFI sets. Expected output is
  6. # discarded. Normally run from the top-level LSMB directory to check charts in
  7. # the directory 'sql', a chart directory or file can be given. When passed a
  8. # directory name, it checks all charts in that directory provided that a copy
  9. # of Pg-database.sql is present.
  10. #
  11. # This test script requires that plpgsql have been loaded to template1 and that
  12. # the running user has the ability to create and drop databases. Additionally,
  13. # this copy of chart-load-test.sh will not work with LedgerSMB >= 1.3.
  14. #
  15. #######################################################################
  16. # Copyright 2007, The LedgerSMB Core Team
  17. #
  18. # This program is free software; you can redistribute it and/or modify
  19. # it under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation; either version 2 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program; if not, write to the Free Software
  29. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. #
  31. #######################################################################
  32. sqldir="${1:-sql}"
  33. chart="$2"
  34. db="charttest$$"
  35. if [ -f "$sqldir" ] ; then
  36. chart=`basename $sqldir`
  37. sqldir=`dirname $sqldir`
  38. fi
  39. if [ ! -d "$sqldir" ] ; then
  40. echo "chart-load-test.sh: Directory '$sqldir' cannot be accessed" 1>&2
  41. exit 1
  42. elif [ ! -f "${sqldir}/Pg-database.sql" ] ; then
  43. echo "chart-load-test.sh: Directory '$sqldir' does not contain Pg-database.sql" 1>&2
  44. elif [ "$chart" -a ! -f "${sqldir}/$chart" ] ; then
  45. echo "chart-load-test.sh: Chart '$chart' cannot be accessed" 1>&2
  46. exit 1
  47. fi
  48. pushd $sqldir > /dev/null
  49. ( for i in ${chart:-*-chart.sql}; do
  50. createdb $db
  51. psql -f Pg-database.sql $db > /dev/null
  52. sleep 3
  53. psql -f "$i" $db > /dev/null
  54. j="${i/chart.sql/gifi.sql}"
  55. if [ -x "$j" ] ; then
  56. psql -f "$j" $db > /dev/null
  57. fi
  58. sleep 3
  59. dropdb $db
  60. done ) 2>&1 | grep -v 'NOTICE' | grep -v '^CREATE' |grep -v '^DROP'
  61. popd > /dev/null