From 921620e3df696442b688024c499541862bcd03eb Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 15 Oct 2016 17:44:39 +0200 Subject: blogc: added some "integration" tests --- .gitignore | 1 + Makefile.am | 4 + configure.ac | 9 +- tests/blogc/check_blogc.sh.in | 379 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 390 insertions(+), 3 deletions(-) create mode 100755 tests/blogc/check_blogc.sh.in diff --git a/.gitignore b/.gitignore index 9929690..cc4e242 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ blogc*.html /blogc-runserver # tests +/tests/blogc/check_blogc.sh /tests/blogc/check_content_parser /tests/blogc/check_datetime_parser /tests/blogc/check_loader diff --git a/Makefile.am b/Makefile.am index 2d526f8..edf3b75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -331,6 +331,10 @@ check_SCRIPTS += \ endif endif +check_SCRIPTS += \ + tests/blogc/check_blogc.sh \ + $(NULL) + if USE_CMOCKA check_PROGRAMS += \ diff --git a/configure.ac b/configure.ac index 081dfbc..2ec6dcd 100644 --- a/configure.ac +++ b/configure.ac @@ -146,8 +146,9 @@ AS_IF([test "x$enable_tests" != "xno"], [ have_bgr_deps=yes ]) AC_PATH_PROG([bash], [bash]) + AC_PATH_PROG([diff], [diff]) AC_PATH_PROG([tee], [tee]) - AS_IF([test "x$ac_cv_path_bash" = "x" -o "x$ac_cv_path_tee" = "x"], [ + AS_IF([test "x$ac_cv_path_bash" = "x" -o "x$ac_cv_path_diff" = "x" -o "x$ac_cv_path_tee" = "x"], [ have_blogc_deps=no ], [ have_blogc_deps=yes @@ -169,9 +170,9 @@ AS_IF([test "x$have_blogc_deps" = "xyes"],, [ have_tests=no TESTS="disabled" AS_IF([test "x$enable_tests" = "xyes"], [ - AC_MSG_ERROR([tests requested but bash and/or tee not found]) + AC_MSG_ERROR([tests requested but bash, diff and/or tee not found]) ], [ - AC_MSG_WARN([bash and/or tee not found, install it to run tests]) + AC_MSG_WARN([bash, diff and/or tee not found, install it to run tests]) ]) ]) AS_IF([test "x$have_bgr_deps" = "xyes"], , [ @@ -199,6 +200,8 @@ AC_CONFIG_FILES([ Makefile blogc.spec ]) +AC_CONFIG_FILES([tests/blogc/check_blogc.sh], + [chmod +x tests/blogc/check_blogc.sh]) AC_CONFIG_FILES([tests/blogc-git-receiver/check_pre_receive.sh], [chmod +x tests/blogc-git-receiver/check_pre_receive.sh]) AC_CONFIG_FILES([tests/blogc-git-receiver/check_post_receive.sh], diff --git a/tests/blogc/check_blogc.sh.in b/tests/blogc/check_blogc.sh.in new file mode 100755 index 0000000..7ea0c96 --- /dev/null +++ b/tests/blogc/check_blogc.sh.in @@ -0,0 +1,379 @@ +#!@BASH@ + +set -xe -o pipefail + +export LC_ALL=C + +TEMP="$(mktemp -d)" +[[ -n "${TEMP}" ]] + +trap_func() { + [[ -n "${TEMP}" ]] && rm -rf "${TEMP}" +} + +trap trap_func EXIT + +${TESTS_ENVIRONMENT} ./blogc -v | grep blogc + +cat > "${TEMP}/post1.txt" < "${TEMP}/post2.txt" < "${TEMP}/atom.tmpl" < + + {{ SITE_TITLE }} + {{ BASE_URL }}/atom.xml + {{ DATE_FIRST_FORMATTED }} + + + + {{ AUTHOR_NAME }} + {{ AUTHOR_EMAIL }} + + {{ SITE_TAGLINE }} + {% block listing %} + + {{ TITLE }} + {{ BASE_URL }}/post/{{ FILENAME }}/ + {{ DATE_FORMATTED }} + {{ DATE_FORMATTED }} + + + {{ AUTHOR_NAME }} + {{ AUTHOR_EMAIL }} + + + + {% endblock %} + +EOF + +cat > "${TEMP}/expected-output.xml" < + + Chunda's website + /atom.xml + 2010-01-01T11:11:11Z + + + + Chunda + chunda@bola.com + + + + + foo + /post/post1/ + 2010-01-01T11:11:11Z + 2010-01-01T11:11:11Z + + + Chunda + chunda@bola.com + + f]]> + + + + bar + /post/post2/ + 2010-01-01T22:22:22Z + 2010-01-01T22:22:22Z + + + Chunda + chunda@bola.com + + b]]> + + + +EOF + +${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D AUTHOR_NAME=Chunda \ + -D AUTHOR_EMAIL=chunda@bola.com \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ" \ + -t "${TEMP}/atom.tmpl" \ + -o "${TEMP}/output.xml" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" + +diff -uN "${TEMP}/output.xml" "${TEMP}/expected-output.xml" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D AUTHOR_NAME=Chunda \ + -D AUTHOR_EMAIL=chunda@bola.com \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ" \ + -t "${TEMP}/atom.tmpl" \ + -o "${TEMP}/output2.xml" \ + -l \ + -i + +diff -uN "${TEMP}/output2.xml" "${TEMP}/expected-output.xml" + +${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D AUTHOR_NAME=Chunda \ + -D AUTHOR_EMAIL=chunda@bola.com \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ" \ + -t "${TEMP}/atom.tmpl" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" > "${TEMP}/output3.xml" + +diff -uN "${TEMP}/output3.xml" "${TEMP}/expected-output.xml" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D AUTHOR_NAME=Chunda \ + -D AUTHOR_EMAIL=chunda@bola.com \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ" \ + -t "${TEMP}/atom.tmpl" \ + -l \ + -i > "${TEMP}/output4.xml" + +diff -uN "${TEMP}/output4.xml" "${TEMP}/expected-output.xml" + +cat > "${TEMP}/main.tmpl" < + + + {% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %} + + +
{{ SITE_TITLE }}
+ {% block listing_once %} +
+
+
+
Blog
+
    + {% endblock %} + {% block listing %} +
  • +
    {{ DATE_FORMATTED }}
    +
    {{ TITLE }}
    +
  • + {% endblock %} + {% block listing_once %} +
+
+
+
+ {% endblock %} + {% block entry %} +
+
+
+ {% ifdef IS_POST %}
{% endif %} +
+
{{ TITLE }}
+
+ {% ifdef IS_POST %} +
+
{{ DATE_FORMATTED }}
+
+
+ {% endif %} +
+ {{ CONTENT }} + {% ifdef IS_POST %} +
+

Back to posts

+ {% endif %} +
+
+
+
+ {% endblock %} + + +EOF + +cat > "${TEMP}/expected-output.html" < + + + Chunda's website + + +
Chunda's website
+ +
+
+
+
Blog
+
    + + +
  • +
    Jan 01, 2010, 11:11 AM GMT
    +
    foo
    +
  • + +
  • +
    Jan 01, 2010, 10:22 PM GMT
    +
    bar
    +
  • + + +
+
+
+
+ + + + +EOF + +${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output.html" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" + +diff -uN "${TEMP}/output.html" "${TEMP}/expected-output.html" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output2.html" \ + -l \ + -i + +diff -uN "${TEMP}/output2.html" "${TEMP}/expected-output.html" + +${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" > "${TEMP}/output3.html" + +diff -uN "${TEMP}/output3.html" "${TEMP}/expected-output.html" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -l \ + -i > "${TEMP}/output4.html" + +diff -uN "${TEMP}/output4.html" "${TEMP}/expected-output.html" + +cat > "${TEMP}/expected-output2.html" < + + + foo + + +
Chunda's website
+ + + + +
+
+
+ +
+
foo
+
+ +
+

foo?

+ + +
+
+
+
+ + + +EOF + +${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output5.html" \ + "${TEMP}/post1.txt" + +diff -uN "${TEMP}/output5.html" "${TEMP}/expected-output2.html" + +echo -e "${TEMP}/post1.txt" | ${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output6.html" \ + -i + +diff -uN "${TEMP}/output6.html" "${TEMP}/expected-output2.html" + +${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + "${TEMP}/post1.txt" > "${TEMP}/output7.html" + +diff -uN "${TEMP}/output7.html" "${TEMP}/expected-output2.html" + +echo -e "${TEMP}/post1.txt" | ${TESTS_ENVIRONMENT} ./blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -t "${TEMP}/main.tmpl" \ + -i > "${TEMP}/output8.html" + +diff -uN "${TEMP}/output8.html" "${TEMP}/expected-output2.html" + +echo "{% block listig %}foo{% endblock %}\n" > "${TEMP}/error.tmpl" + +${TESTS_ENVIRONMENT} ./blogc \ + -t "${TEMP}/error.tmpl" \ + "${TEMP}/post1.txt" 2>&1 | tee "${TEMP}/output.txt" || true + +grep "blogc: error: template: Invalid block type" "${TEMP}/output.txt" -- cgit v1.2.3-18-g5258