run-tests 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/sh
  2. set -e
  3. DIR=$(readlink -f $(dirname $0))
  4. echo "Compiling the tests …"
  5. (cd $DIR && make)
  6. echo "Running all testcases …"
  7. LDPATH="$DIR/../../build/bin"
  8. EXT="_libapt_test"
  9. EXIT_CODE=0
  10. # detect if output is on a terminal (colorful) or better not
  11. if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null; then
  12. COLHIGH='\033[1;35m'
  13. COLRESET='\033[0m'
  14. TESTOKAY='\033[1;32mOKAY\033[0m'
  15. TESTFAIL='\033[1;31mFAILED\033[0m'
  16. else
  17. COLHIGH=''
  18. COLRESET=''
  19. TESTOKAY='OK'
  20. TESTFAIL='###FAILED###'
  21. fi
  22. for testapp in $(ls ${LDPATH}/*$EXT)
  23. do
  24. name=$(basename ${testapp})
  25. NAME="${COLHIGH}${name}${COLRESET}"
  26. tmppath=""
  27. if [ $name = "GetListOfFilesInDir${EXT}" ]; then
  28. # TODO: very-low: move env creation to the actual test-app
  29. tmppath=$(mktemp -d)
  30. touch "${tmppath}/anormalfile" \
  31. "${tmppath}/01yet-anothernormalfile" \
  32. "${tmppath}/anormalapt.conf" \
  33. "${tmppath}/01yet-anotherapt.conf" \
  34. "${tmppath}/anormalapt.list" \
  35. "${tmppath}/01yet-anotherapt.list" \
  36. "${tmppath}/wrongextension.wron" \
  37. "${tmppath}/wrong-extension.wron" \
  38. "${tmppath}/strangefile." \
  39. "${tmppath}/s.t.r.a.n.g.e.f.i.l.e" \
  40. "${tmppath}/.hiddenfile" \
  41. "${tmppath}/.hiddenfile.conf" \
  42. "${tmppath}/.hiddenfile.list" \
  43. "${tmppath}/multi..dot" \
  44. "${tmppath}/multi.dot.conf" \
  45. "${tmppath}/multi.dot.list" \
  46. "${tmppath}/disabledfile.disabled" \
  47. "${tmppath}/disabledfile.conf.disabled" \
  48. "${tmppath}/disabledfile.list.disabled" \
  49. "${tmppath}/invälid.conf" \
  50. "${tmppath}/invalíd" \
  51. "${tmppath}/01invalíd"
  52. mkdir "${tmppath}/invaliddir" \
  53. "${tmppath}/directory.conf" \
  54. "${tmppath}/directory.list" \
  55. "${tmppath}/directory.wron" \
  56. "${tmppath}/directory.list.disabled"
  57. ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list"
  58. ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list"
  59. elif [ $name = "getLanguages${EXT}" ]; then
  60. tmppath=$(mktemp -d)
  61. touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \
  62. "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \
  63. "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \
  64. "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak" \
  65. "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-ast_DE" \
  66. "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tlh%5fDE"
  67. elif [ $name = "HashSums${EXT}" ]; then
  68. TMP="$(readlink -f "./${0}")"
  69. echo -n "Testing with ${NAME} "
  70. LD_LIBRARY_PATH=${LDPATH} ${testapp} $TMP $(md5sum $TMP | cut -d' ' -f 1) $(sha1sum $TMP | cut -d' ' -f 1) $(sha256sum $TMP | cut -d' ' -f 1) $(sha512sum $TMP | cut -d' ' -f 1) && echo "$TESTOKAY" || echo "$TESTFAIL"
  71. continue
  72. elif [ $name = "CompareVersion${EXT}" ]; then
  73. tmppath="${DIR}/versions.lst"
  74. elif [ $name = "CdromFindPackages${EXT}" ]; then
  75. tmppath=$(mktemp -d)
  76. mkdir -p "${tmppath}/.disk" "${tmppath}/pool" \
  77. "${tmppath}/dists/stable/main/binary-i386" \
  78. "${tmppath}/dists/stable/main/source" \
  79. "${tmppath}/dists/stable/contrib/binary-amd64" \
  80. "${tmppath}/dists/stable/contrib/binary-all" \
  81. "${tmppath}/dists/unstable/main/binary-i386" \
  82. "${tmppath}/dists/unstable/main/i18n" \
  83. "${tmppath}/dists/unstable/main/source" \
  84. "${tmppath}/dists/broken/non-free/source"
  85. touch "${tmppath}/dists/broken/.aptignr" \
  86. "${tmppath}/dists/stable/main/binary-i386/Packages" \
  87. "${tmppath}/dists/stable/main/binary-i386/Packages.bz2" \
  88. "${tmppath}/dists/stable/main/source/Sources.xz" \
  89. "${tmppath}/dists/stable/contrib/binary-amd64/Packages" \
  90. "${tmppath}/dists/stable/contrib/binary-amd64/Packages.gz" \
  91. "${tmppath}/dists/stable/contrib/binary-all/Packages" \
  92. "${tmppath}/dists/unstable/main/binary-i386/Packages.xz" \
  93. "${tmppath}/dists/unstable/main/binary-i386/Packages.lzma" \
  94. "${tmppath}/dists/unstable/main/i18n/Translation-en" \
  95. "${tmppath}/dists/unstable/main/i18n/Translation-de.bz2" \
  96. "${tmppath}/dists/unstable/main/source/Sources.xz" \
  97. "${tmppath}/dists/broken/non-free/source/Sources.gz" \
  98. "${tmppath}/dists/stable/Release.gpg" \
  99. "${tmppath}/dists/stable/Release" \
  100. "${tmppath}/dists/unstable/InRelease" \
  101. "${tmppath}/dists/broken/Release.gpg"
  102. ln -s "${tmppath}/dists/unstable" "${tmppath}/dists/sid"
  103. fi
  104. echo -n "Testing with ${NAME} "
  105. if LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} ; then
  106. echo "$TESTOKAY"
  107. else
  108. echo "$TESTFAIL"
  109. EXIT_CODE=1
  110. fi
  111. if [ -n "$tmppath" -a -d "$tmppath" ]; then
  112. rm -rf "$tmppath"
  113. fi
  114. done
  115. exit $EXIT_CODE