#!@BASH@

set -xe -o pipefail

export LC_ALL=C

export BLOGC=@abs_top_builddir@/blogc

TEMP="$(mktemp -d)"
[[ -n "${TEMP}" ]]

trap_func() {
    [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt"
    [[ -n "${TEMP}" ]] && rm -rf "${TEMP}"
}

trap trap_func EXIT

mkdir -p "${TEMP}"/proj{,/templates,/content/post}


### minimal settings, will produce no file

cat > "${TEMP}/proj/blogcfile" <<EOF
[global]
AUTHOR_NAME = Lol
AUTHOR_EMAIL = author@example.com
SITE_TITLE = Lol's Website
SITE_TAGLINE = WAT?!
BASE_DOMAIN = http://example.org
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1


### default settings with some posts

cat > "${TEMP}/proj/content/post/foo.txt" <<EOF
TITLE: Foo
DATE: 2016-10-01
----------------
This is foo.
EOF

cat > "${TEMP}/proj/content/post/bar.txt" <<EOF
TITLE: Bar
DATE: 2016-09-01
----------------
This is bar.
EOF

for i in $(seq -f "%02g" 1 11); do
    cat > "${TEMP}/proj/content/post/post${i}.txt" <<EOF
TITLE: Post ${i}
DATE: 2016-09-${i}
----------------
This is Post ${i}.
EOF
done

cat > "${TEMP}/proj/templates/main.tmpl" <<EOF
{% block listing %}
Listing: {% ifdef FILTER_TAG %}{{ FILTER_TAG }} - {% endif %}{{ TITLE }} - {{ DATE_FORMATTED }}
{% endblock %}
{% block entry %}
{{ TITLE }}{% if MAKE_TYPE == "post" %} - {{ DATE_FORMATTED }}{% endif %}

{{ CONTENT }}
{% endblock %}
EOF

cat >> "${TEMP}/proj/blogcfile" <<EOF
[posts]
foo
bar
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/page/1/index\\.html" "${TEMP}/output.txt"
grep "_build/post/foo/index\\.html" "${TEMP}/output.txt"
grep "_build/post/bar/index\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

cat > "${TEMP}/expected-index.html" <<EOF

Listing: Bar - Sep 01, 2016, 12:00 AM GMT

Listing: Foo - Oct 01, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/page/1/index.html" "${TEMP}/expected-index.html"

cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website</title>
  <id>/atom.xml</id>
  <updated>2016-09-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Bar</title>
    <id>/post/bar/</id>
    <updated>2016-09-01T00:00:00Z</updated>
    <published>2016-09-01T00:00:00Z</published>
    <link href="http://example.org/post/bar/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is bar.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Foo</title>
    <id>/post/foo/</id>
    <updated>2016-10-01T00:00:00Z</updated>
    <published>2016-10-01T00:00:00Z</published>
    <link href="http://example.org/post/foo/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is foo.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-post-foo.html" <<EOF


Foo - Oct 01, 2016, 12:00 AM GMT

<p>This is foo.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/foo/index.html" "${TEMP}/expected-post-foo.html"

cat > "${TEMP}/expected-post-bar.html" <<EOF


Bar - Sep 01, 2016, 12:00 AM GMT

<p>This is bar.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/bar/index.html" "${TEMP}/expected-post-bar.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts, posts per page -1

cat > "${TEMP}/proj/blogcfile" <<EOF
[global]
AUTHOR_NAME = Lol
AUTHOR_EMAIL = author@example.com
SITE_TITLE = Lol's Website
SITE_TAGLINE = WAT?!
BASE_DOMAIN = http://example.org

[settings]
posts_per_page = -1

[posts]
post01
post02
post03
post04
post05
post06
post07
post08
post09
post10
post11
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/post/post01/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post02/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post03/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post04/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post05/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post06/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post07/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post08/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post09/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post10/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post11/index\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

cat > "${TEMP}/expected-index.html" <<EOF

Listing: Post 11 - Sep 11, 2016, 12:00 AM GMT

Listing: Post 10 - Sep 10, 2016, 12:00 AM GMT

Listing: Post 09 - Sep 09, 2016, 12:00 AM GMT

Listing: Post 08 - Sep 08, 2016, 12:00 AM GMT

Listing: Post 07 - Sep 07, 2016, 12:00 AM GMT

Listing: Post 06 - Sep 06, 2016, 12:00 AM GMT

Listing: Post 05 - Sep 05, 2016, 12:00 AM GMT

Listing: Post 04 - Sep 04, 2016, 12:00 AM GMT

Listing: Post 03 - Sep 03, 2016, 12:00 AM GMT

Listing: Post 02 - Sep 02, 2016, 12:00 AM GMT

Listing: Post 01 - Sep 01, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"

cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website</title>
  <id>/atom.xml</id>
  <updated>2016-09-11T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Post 11</title>
    <id>/post/post11/</id>
    <updated>2016-09-11T00:00:00Z</updated>
    <published>2016-09-11T00:00:00Z</published>
    <link href="http://example.org/post/post11/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 11.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 10</title>
    <id>/post/post10/</id>
    <updated>2016-09-10T00:00:00Z</updated>
    <published>2016-09-10T00:00:00Z</published>
    <link href="http://example.org/post/post10/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 10.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 09</title>
    <id>/post/post09/</id>
    <updated>2016-09-09T00:00:00Z</updated>
    <published>2016-09-09T00:00:00Z</published>
    <link href="http://example.org/post/post09/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 09.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 08</title>
    <id>/post/post08/</id>
    <updated>2016-09-08T00:00:00Z</updated>
    <published>2016-09-08T00:00:00Z</published>
    <link href="http://example.org/post/post08/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 08.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 07</title>
    <id>/post/post07/</id>
    <updated>2016-09-07T00:00:00Z</updated>
    <published>2016-09-07T00:00:00Z</published>
    <link href="http://example.org/post/post07/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 07.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 06</title>
    <id>/post/post06/</id>
    <updated>2016-09-06T00:00:00Z</updated>
    <published>2016-09-06T00:00:00Z</published>
    <link href="http://example.org/post/post06/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 06.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 05</title>
    <id>/post/post05/</id>
    <updated>2016-09-05T00:00:00Z</updated>
    <published>2016-09-05T00:00:00Z</published>
    <link href="http://example.org/post/post05/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 05.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 04</title>
    <id>/post/post04/</id>
    <updated>2016-09-04T00:00:00Z</updated>
    <published>2016-09-04T00:00:00Z</published>
    <link href="http://example.org/post/post04/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 04.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 03</title>
    <id>/post/post03/</id>
    <updated>2016-09-03T00:00:00Z</updated>
    <published>2016-09-03T00:00:00Z</published>
    <link href="http://example.org/post/post03/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 03.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Post 02</title>
    <id>/post/post02/</id>
    <updated>2016-09-02T00:00:00Z</updated>
    <published>2016-09-02T00:00:00Z</published>
    <link href="http://example.org/post/post02/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is Post 02.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-post-post01.html" <<EOF


Post 01 - Sep 01, 2016, 12:00 AM GMT

<p>This is Post 01.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/post01/index.html" "${TEMP}/expected-post-post01.html"

cat > "${TEMP}/expected-post-post11.html" <<EOF


Post 11 - Sep 11, 2016, 12:00 AM GMT

<p>This is Post 11.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/post11/index.html" "${TEMP}/expected-post-post11.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts, atom posts per page 0

cat > "${TEMP}/proj/blogcfile" <<EOF
[global]
AUTHOR_NAME = Lol
AUTHOR_EMAIL = author@example.com
SITE_TITLE = Lol's Website
SITE_TAGLINE = WAT?!
BASE_DOMAIN = http://example.org

[settings]
atom_posts_per_page = 0

[posts]
post01
post02
post03
post04
post05
post06
post07
post08
post09
post10
post11
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/post/post01/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post02/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post03/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post04/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post05/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post06/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post07/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post08/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post09/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post10/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post11/index\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

cat > "${TEMP}/expected-index.html" <<EOF

Listing: Post 11 - Sep 11, 2016, 12:00 AM GMT

Listing: Post 10 - Sep 10, 2016, 12:00 AM GMT

Listing: Post 09 - Sep 09, 2016, 12:00 AM GMT

Listing: Post 08 - Sep 08, 2016, 12:00 AM GMT

Listing: Post 07 - Sep 07, 2016, 12:00 AM GMT

Listing: Post 06 - Sep 06, 2016, 12:00 AM GMT

Listing: Post 05 - Sep 05, 2016, 12:00 AM GMT

Listing: Post 04 - Sep 04, 2016, 12:00 AM GMT

Listing: Post 03 - Sep 03, 2016, 12:00 AM GMT

Listing: Post 02 - Sep 02, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"

cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website</title>
  <id>/atom.xml</id>
  <updated></updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-post-post01.html" <<EOF


Post 01 - Sep 01, 2016, 12:00 AM GMT

<p>This is Post 01.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/post01/index.html" "${TEMP}/expected-post-post01.html"

cat > "${TEMP}/expected-post-post11.html" <<EOF


Post 11 - Sep 11, 2016, 12:00 AM GMT

<p>This is Post 11.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/post11/index.html" "${TEMP}/expected-post-post11.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts, order asc

cat > "${TEMP}/proj/blogcfile" <<EOF
[global]
AUTHOR_NAME = Lol
AUTHOR_EMAIL = author@example.com
SITE_TITLE = Lol's Website
SITE_TAGLINE = WAT?!
BASE_DOMAIN = http://example.org

[settings]
html_order = ASC
atom_order = ASC

[posts]
foo
bar
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/page/1/index\\.html" "${TEMP}/output.txt"
grep "_build/post/foo/index\\.html" "${TEMP}/output.txt"
grep "_build/post/bar/index\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

cat > "${TEMP}/expected-index.html" <<EOF

Listing: Foo - Oct 01, 2016, 12:00 AM GMT

Listing: Bar - Sep 01, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/page/1/index.html" "${TEMP}/expected-index.html"

cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website</title>
  <id>/atom.xml</id>
  <updated>2016-10-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Foo</title>
    <id>/post/foo/</id>
    <updated>2016-10-01T00:00:00Z</updated>
    <published>2016-10-01T00:00:00Z</published>
    <link href="http://example.org/post/foo/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is foo.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Bar</title>
    <id>/post/bar/</id>
    <updated>2016-09-01T00:00:00Z</updated>
    <published>2016-09-01T00:00:00Z</published>
    <link href="http://example.org/post/bar/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is bar.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-post-foo.html" <<EOF


Foo - Oct 01, 2016, 12:00 AM GMT

<p>This is foo.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/foo/index.html" "${TEMP}/expected-post-foo.html"

cat > "${TEMP}/expected-post-bar.html" <<EOF


Bar - Sep 01, 2016, 12:00 AM GMT

<p>This is bar.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/bar/index.html" "${TEMP}/expected-post-bar.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts and tags, order asc

cat > "${TEMP}/proj/content/post/baz.txt" <<EOF
TITLE: Baz
DATE: 2016-08-01
TAGS: tag1 tag2
----------------
This is baz.
EOF

cat >> "${TEMP}/proj/blogcfile" <<EOF
baz
[tags]
tag1
tag2
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/atom/tag1\\.xml" "${TEMP}/output.txt"
grep "_build/atom/tag2\\.xml" "${TEMP}/output.txt"
grep "_build/page/1/index\\.html" "${TEMP}/output.txt"
grep "_build/post/foo/index\\.html" "${TEMP}/output.txt"
grep "_build/post/bar/index\\.html" "${TEMP}/output.txt"
grep "_build/post/baz/index\\.html" "${TEMP}/output.txt"
grep "_build/tag/tag1/index\\.html" "${TEMP}/output.txt"
grep "_build/tag/tag2/index\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

cat > "${TEMP}/expected-index.html" <<EOF

Listing: Foo - Oct 01, 2016, 12:00 AM GMT

Listing: Bar - Sep 01, 2016, 12:00 AM GMT

Listing: Baz - Aug 01, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/page/1/index.html" "${TEMP}/expected-index.html"

cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website</title>
  <id>/atom.xml</id>
  <updated>2016-10-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Foo</title>
    <id>/post/foo/</id>
    <updated>2016-10-01T00:00:00Z</updated>
    <published>2016-10-01T00:00:00Z</published>
    <link href="http://example.org/post/foo/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is foo.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Bar</title>
    <id>/post/bar/</id>
    <updated>2016-09-01T00:00:00Z</updated>
    <published>2016-09-01T00:00:00Z</published>
    <link href="http://example.org/post/bar/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is bar.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="text">Baz</title>
    <id>/post/baz/</id>
    <updated>2016-08-01T00:00:00Z</updated>
    <published>2016-08-01T00:00:00Z</published>
    <link href="http://example.org/post/baz/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is baz.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-atom-tag1.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website - tag1</title>
  <id>/atom/tag1.xml</id>
  <updated>2016-08-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom/tag1.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Baz</title>
    <id>/post/baz/</id>
    <updated>2016-08-01T00:00:00Z</updated>
    <published>2016-08-01T00:00:00Z</published>
    <link href="http://example.org/post/baz/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is baz.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom/tag1.xml" "${TEMP}/expected-atom-tag1.xml"

cat > "${TEMP}/expected-atom-tag2.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website - tag2</title>
  <id>/atom/tag2.xml</id>
  <updated>2016-08-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atom/tag2.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Baz</title>
    <id>/post/baz/</id>
    <updated>2016-08-01T00:00:00Z</updated>
    <published>2016-08-01T00:00:00Z</published>
    <link href="http://example.org/post/baz/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is baz.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atom/tag2.xml" "${TEMP}/expected-atom-tag2.xml"

cat > "${TEMP}/expected-post-baz.html" <<EOF


Baz - Aug 01, 2016, 12:00 AM GMT

<p>This is baz.</p>


EOF
diff -uN "${TEMP}/proj/_build/post/foo/index.html" "${TEMP}/expected-post-foo.html"
diff -uN "${TEMP}/proj/_build/post/bar/index.html" "${TEMP}/expected-post-bar.html"
diff -uN "${TEMP}/proj/_build/post/baz/index.html" "${TEMP}/expected-post-baz.html"

cat > "${TEMP}/expected-tag1.html" <<EOF

Listing: tag1 - Baz - Aug 01, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/tag/tag1/index.html" "${TEMP}/expected-tag1.html"

cat > "${TEMP}/expected-tag2.html" <<EOF

Listing: tag2 - Baz - Aug 01, 2016, 12:00 AM GMT


EOF
diff -uN "${TEMP}/proj/_build/tag/tag2/index.html" "${TEMP}/expected-tag2.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts, pages and tags, order asc

cat > "${TEMP}/proj/content/page1.txt" <<EOF
TITLE: Page 1
-------------
This is page 1.
EOF

cat > "${TEMP}/proj/content/page2.txt" <<EOF
TITLE: Page 2
-------------
This is page 2.
EOF

cat >> "${TEMP}/proj/blogcfile" <<EOF
[pages]
page1
page2
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/atom/tag1\\.xml" "${TEMP}/output.txt"
grep "_build/atom/tag2\\.xml" "${TEMP}/output.txt"
grep "_build/page/1/index\\.html" "${TEMP}/output.txt"
grep "_build/post/foo/index\\.html" "${TEMP}/output.txt"
grep "_build/post/bar/index\\.html" "${TEMP}/output.txt"
grep "_build/post/baz/index\\.html" "${TEMP}/output.txt"
grep "_build/tag/tag1/index\\.html" "${TEMP}/output.txt"
grep "_build/tag/tag2/index\\.html" "${TEMP}/output.txt"
grep "_build/page1/index\\.html" "${TEMP}/output.txt"
grep "_build/page2/index\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/page/1/index.html" "${TEMP}/expected-index.html"

diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"

diff -uN "${TEMP}/proj/_build/atom/tag1.xml" "${TEMP}/expected-atom-tag1.xml"
diff -uN "${TEMP}/proj/_build/atom/tag2.xml" "${TEMP}/expected-atom-tag2.xml"

diff -uN "${TEMP}/proj/_build/post/foo/index.html" "${TEMP}/expected-post-foo.html"
diff -uN "${TEMP}/proj/_build/post/bar/index.html" "${TEMP}/expected-post-bar.html"
diff -uN "${TEMP}/proj/_build/post/baz/index.html" "${TEMP}/expected-post-baz.html"

diff -uN "${TEMP}/proj/_build/tag/tag1/index.html" "${TEMP}/expected-tag1.html"
diff -uN "${TEMP}/proj/_build/tag/tag2/index.html" "${TEMP}/expected-tag2.html"

cat > "${TEMP}/expected-page1.html" <<EOF


Page 1

<p>This is page 1.</p>


EOF
diff -uN "${TEMP}/proj/_build/page1/index.html" "${TEMP}/expected-page1.html"

cat > "${TEMP}/expected-page2.html" <<EOF


Page 2

<p>This is page 2.</p>


EOF
diff -uN "${TEMP}/proj/_build/page2/index.html" "${TEMP}/expected-page2.html"

rm -rf "${TEMP}/proj"
mkdir -p "${TEMP}"/proj{,/temp,/contents/poost}


### custom settings with some posts

cat > "${TEMP}/proj/contents/poost/foo.blogc" <<EOF
TITLE: Foo
DATE: 2016-10-01
----------------
This is foo.
EOF

cat > "${TEMP}/proj/contents/poost/bar.blogc" <<EOF
TITLE: Bar
DATE: 2016-09-01
----------------
This is bar.
EOF

cat > "${TEMP}/proj/temp/main.html" <<EOF
{% block listing %}
Listing: {% ifdef FILTER_TAG %}{{ FILTER_TAG }} - {% endif %}{{ TITLE }} - {{ DATE_FORMATTED }}
{% endblock %}
{% block entry %}
{{ TITLE }}{% if MAKE_TYPE == "post" %} - {{ DATE_FORMATTED }}{% endif %}

{{ CONTENT }}
{% endblock %}
EOF

cat > "${TEMP}/proj/blogcfile" <<EOF
[settings]
content_dir = contents
template_dir = temp
main_template = main.html
source_ext = .blogc
pagination_prefix = pagination
posts_per_page = 1
atom_posts_per_page = 1
html_ext = .html
index_prefix = posts
post_prefix = poost
tag_prefix = taag
atom_prefix = atoom
atom_ext = /index.xml
date_format = %b %d, %Y
locale = en_US.utf8
html_order = ASC
atom_order = ASC

[global]
AUTHOR_NAME = Lol
AUTHOR_EMAIL = author@example.com
SITE_TITLE = Lol's Website
SITE_TAGLINE = WAT?!
BASE_DOMAIN = http://example.org

[posts]
foo
bar
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/posts\\.html" "${TEMP}/output.txt"
grep "_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "_build/poost/bar\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

cat > "${TEMP}/expected-index.html" <<EOF

Listing: Foo - Oct 01, 2016


EOF
diff -uN "${TEMP}/proj/_build/posts.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/pagination/1.html" "${TEMP}/expected-index.html"

cat > "${TEMP}/expected-page-2.html" <<EOF

Listing: Bar - Sep 01, 2016


EOF
diff -uN "${TEMP}/proj/_build/pagination/2.html" "${TEMP}/expected-page-2.html"

cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website</title>
  <id>/atoom/index.xml</id>
  <updated>2016-10-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atoom/index.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Foo</title>
    <id>/poost/foo/</id>
    <updated>2016-10-01T00:00:00Z</updated>
    <published>2016-10-01T00:00:00Z</published>
    <link href="http://example.org/poost/foo/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is foo.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atoom/index.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-post-foo.html" <<EOF


Foo - Oct 01, 2016

<p>This is foo.</p>


EOF
diff -uN "${TEMP}/proj/_build/poost/foo.html" "${TEMP}/expected-post-foo.html"

cat > "${TEMP}/expected-post-bar.html" <<EOF


Bar - Sep 01, 2016

<p>This is bar.</p>


EOF
diff -uN "${TEMP}/proj/_build/poost/bar.html" "${TEMP}/expected-post-bar.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts and tags

cat > "${TEMP}/proj/contents/poost/baz.blogc" <<EOF
TITLE: Baz
DATE: 2016-08-01
TAGS: tag1 tag2
----------------
This is baz.
EOF

cat >> "${TEMP}/proj/blogcfile" <<EOF
baz
[tags]
tag1
tag2
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/posts\\.html" "${TEMP}/output.txt"
grep "_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt"
grep "_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "_build/pagination/3\\.html" "${TEMP}/output.txt"
grep "_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "_build/poost/bar\\.html" "${TEMP}/output.txt"
grep "_build/poost/baz\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag1\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag2\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

diff -uN "${TEMP}/proj/_build/posts.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/pagination/1.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/pagination/2.html" "${TEMP}/expected-page-2.html"

cat > "${TEMP}/expected-page-3.html" <<EOF

Listing: Baz - Aug 01, 2016


EOF
diff -uN "${TEMP}/proj/_build/pagination/3.html" "${TEMP}/expected-page-3.html"

diff -uN "${TEMP}/proj/_build/atoom/index.xml" "${TEMP}/expected-atom.xml"

cat > "${TEMP}/expected-atom-tag1.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website - tag1</title>
  <id>/atoom/tag1/index.xml</id>
  <updated>2016-08-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atoom/tag1/index.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Baz</title>
    <id>/poost/baz/</id>
    <updated>2016-08-01T00:00:00Z</updated>
    <published>2016-08-01T00:00:00Z</published>
    <link href="http://example.org/poost/baz/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is baz.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atoom/tag1/index.xml" "${TEMP}/expected-atom-tag1.xml"

cat > "${TEMP}/expected-atom-tag2.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Lol's Website - tag2</title>
  <id>/atoom/tag2/index.xml</id>
  <updated>2016-08-01T00:00:00Z</updated>
  <link href="http://example.org/" />
  <link href="http://example.org/atoom/tag2/index.xml" rel="self" />
  <author>
    <name>Lol</name>
    <email>author@example.com</email>
  </author>
  <subtitle type="text">WAT?!</subtitle>
  
  <entry>
    <title type="text">Baz</title>
    <id>/poost/baz/</id>
    <updated>2016-08-01T00:00:00Z</updated>
    <published>2016-08-01T00:00:00Z</published>
    <link href="http://example.org/poost/baz/" />
    <author>
      <name>Lol</name>
      <email>author@example.com</email>
    </author>
    <content type="html"><![CDATA[<p>This is baz.</p>
]]></content>
  </entry>
  
</feed>
EOF
diff -uN "${TEMP}/proj/_build/atoom/tag2/index.xml" "${TEMP}/expected-atom-tag2.xml"

cat > "${TEMP}/expected-post-baz.html" <<EOF


Baz - Aug 01, 2016

<p>This is baz.</p>


EOF
diff -uN "${TEMP}/proj/_build/poost/foo.html" "${TEMP}/expected-post-foo.html"
diff -uN "${TEMP}/proj/_build/poost/bar.html" "${TEMP}/expected-post-bar.html"
diff -uN "${TEMP}/proj/_build/poost/baz.html" "${TEMP}/expected-post-baz.html"

cat > "${TEMP}/expected-tag1.html" <<EOF

Listing: tag1 - Baz - Aug 01, 2016


EOF
diff -uN "${TEMP}/proj/_build/taag/tag1.html" "${TEMP}/expected-tag1.html"

cat > "${TEMP}/expected-tag2.html" <<EOF

Listing: tag2 - Baz - Aug 01, 2016


EOF
diff -uN "${TEMP}/proj/_build/taag/tag2.html" "${TEMP}/expected-tag2.html"

rm -rf "${TEMP}/proj/_build"


### default settings with some posts, pages and tags

cat > "${TEMP}/proj/contents/page1.blogc" <<EOF
TITLE: Page 1
-------------
This is page 1.
EOF

cat > "${TEMP}/proj/contents/page2.blogc" <<EOF
TITLE: Page 2
-------------
This is page 2.
EOF

cat >> "${TEMP}/proj/blogcfile" <<EOF
[pages]
page1
page2
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/posts\\.html" "${TEMP}/output.txt"
grep "_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt"
grep "_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "_build/pagination/3\\.html" "${TEMP}/output.txt"
grep "_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "_build/poost/bar\\.html" "${TEMP}/output.txt"
grep "_build/poost/baz\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag1\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag2\\.html" "${TEMP}/output.txt"
grep "_build/page1\\.html" "${TEMP}/output.txt"
grep "_build/page2\\.html" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

diff -uN "${TEMP}/proj/_build/posts.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/pagination/1.html" "${TEMP}/expected-index.html"
diff -uN "${TEMP}/proj/_build/pagination/2.html" "${TEMP}/expected-page-2.html"
diff -uN "${TEMP}/proj/_build/pagination/3.html" "${TEMP}/expected-page-3.html"

diff -uN "${TEMP}/proj/_build/atoom/index.xml" "${TEMP}/expected-atom.xml"
diff -uN "${TEMP}/proj/_build/atoom/tag1/index.xml" "${TEMP}/expected-atom-tag1.xml"
diff -uN "${TEMP}/proj/_build/atoom/tag2/index.xml" "${TEMP}/expected-atom-tag2.xml"

diff -uN "${TEMP}/proj/_build/poost/foo.html" "${TEMP}/expected-post-foo.html"
diff -uN "${TEMP}/proj/_build/poost/bar.html" "${TEMP}/expected-post-bar.html"
diff -uN "${TEMP}/proj/_build/poost/baz.html" "${TEMP}/expected-post-baz.html"

diff -uN "${TEMP}/proj/_build/taag/tag1.html" "${TEMP}/expected-tag1.html"
diff -uN "${TEMP}/proj/_build/taag/tag2.html" "${TEMP}/expected-tag2.html"

cat > "${TEMP}/expected-page1.html" <<EOF


Page 1

<p>This is page 1.</p>


EOF
diff -uN "${TEMP}/proj/_build/page1.html" "${TEMP}/expected-page1.html"

cat > "${TEMP}/expected-page2.html" <<EOF


Page 2

<p>This is page 2.</p>


EOF
diff -uN "${TEMP}/proj/_build/page2.html" "${TEMP}/expected-page2.html"

rm -rf "${TEMP}/proj/_build"


### copy rule

mkdir -p "${TEMP}"/proj/{a/b/c,d/e,f}
echo bola > "${TEMP}/proj/a/b/c/foo"
echo guda > "${TEMP}/proj/a/b/bar"
echo chunda > "${TEMP}/proj/a/baz"
echo lol > "${TEMP}/proj/d/e/fuu"
echo hehe > "${TEMP}/proj/d/xd"
echo FFFUUUUUU > "${TEMP}/proj/f/XDDDD"

cat >> "${TEMP}/proj/blogcfile" <<EOF
[copy]
a
d/e/fuu
d/xd
f
EOF

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/posts\\.html" "${TEMP}/output.txt"
grep "_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt"
grep "_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "_build/pagination/3\\.html" "${TEMP}/output.txt"
grep "_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "_build/poost/bar\\.html" "${TEMP}/output.txt"
grep "_build/poost/baz\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag1\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag2\\.html" "${TEMP}/output.txt"
grep "_build/page1\\.html" "${TEMP}/output.txt"
grep "_build/page2\\.html" "${TEMP}/output.txt"
grep "_build/a/b/c/foo" "${TEMP}/output.txt"
grep "_build/a/b/bar" "${TEMP}/output.txt"
grep "_build/a/baz" "${TEMP}/output.txt"
grep "_build/d/e/fuu" "${TEMP}/output.txt"
grep "_build/d/xd" "${TEMP}/output.txt"
grep "_build/f/XDDDD" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

test "$(cat "${TEMP}/proj/_build/a/b/c/foo")" = "bola"
test "$(cat "${TEMP}/proj/_build/a/b/bar")" = "guda"
test "$(cat "${TEMP}/proj/_build/a/baz")" = "chunda"
test "$(cat "${TEMP}/proj/_build/d/e/fuu")" = "lol"
test "$(cat "${TEMP}/proj/_build/d/xd")" = "hehe"
test "$(cat "${TEMP}/proj/_build/f/XDDDD")" = "FFFUUUUUU"


### clean rule

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" clean 2>&1 | tee "${TEMP}/output.txt"
grep "_build/posts\\.html" "${TEMP}/output.txt"
grep "_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt"
grep "_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt"
grep "_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "_build/pagination/3\\.html" "${TEMP}/output.txt"
grep "_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "_build/poost/bar\\.html" "${TEMP}/output.txt"
grep "_build/poost/baz\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag1\\.html" "${TEMP}/output.txt"
grep "_build/taag/tag2\\.html" "${TEMP}/output.txt"
grep "_build/page1\\.html" "${TEMP}/output.txt"
grep "_build/page2\\.html" "${TEMP}/output.txt"
grep "_build/a/b/c/foo" "${TEMP}/output.txt"
grep "_build/a/b/bar" "${TEMP}/output.txt"
grep "_build/a/baz" "${TEMP}/output.txt"
grep "_build/d/e/fuu" "${TEMP}/output.txt"
grep "_build/d/xd" "${TEMP}/output.txt"
grep "_build/f/XDDDD" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

[[ ! -d "${TEMP}/proj/_build" ]]

export OUTPUT_DIR="${TEMP}/___blogc_build"

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "___blogc_build/posts\\.html" "${TEMP}/output.txt"
grep "___blogc_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "___blogc_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt"
grep "___blogc_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt"
grep "___blogc_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "___blogc_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "___blogc_build/pagination/3\\.html" "${TEMP}/output.txt"
grep "___blogc_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "___blogc_build/poost/bar\\.html" "${TEMP}/output.txt"
grep "___blogc_build/poost/baz\\.html" "${TEMP}/output.txt"
grep "___blogc_build/taag/tag1\\.html" "${TEMP}/output.txt"
grep "___blogc_build/taag/tag2\\.html" "${TEMP}/output.txt"
grep "___blogc_build/page1\\.html" "${TEMP}/output.txt"
grep "___blogc_build/page2\\.html" "${TEMP}/output.txt"
grep "___blogc_build/a/b/c/foo" "${TEMP}/output.txt"
grep "___blogc_build/a/b/bar" "${TEMP}/output.txt"
grep "___blogc_build/a/baz" "${TEMP}/output.txt"
grep "___blogc_build/d/e/fuu" "${TEMP}/output.txt"
grep "___blogc_build/d/xd" "${TEMP}/output.txt"
grep "___blogc_build/f/XDDDD" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" clean 2>&1 | tee "${TEMP}/output.txt"
grep "___blogc_build/posts\\.html" "${TEMP}/output.txt"
grep "___blogc_build/atoom/index\\.xml" "${TEMP}/output.txt"
grep "___blogc_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt"
grep "___blogc_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt"
grep "___blogc_build/pagination/1\\.html" "${TEMP}/output.txt"
grep "___blogc_build/pagination/2\\.html" "${TEMP}/output.txt"
grep "___blogc_build/pagination/3\\.html" "${TEMP}/output.txt"
grep "___blogc_build/poost/foo\\.html" "${TEMP}/output.txt"
grep "___blogc_build/poost/bar\\.html" "${TEMP}/output.txt"
grep "___blogc_build/poost/baz\\.html" "${TEMP}/output.txt"
grep "___blogc_build/taag/tag1\\.html" "${TEMP}/output.txt"
grep "___blogc_build/taag/tag2\\.html" "${TEMP}/output.txt"
grep "___blogc_build/page1\\.html" "${TEMP}/output.txt"
grep "___blogc_build/page2\\.html" "${TEMP}/output.txt"
grep "___blogc_build/a/b/c/foo" "${TEMP}/output.txt"
grep "___blogc_build/a/b/bar" "${TEMP}/output.txt"
grep "___blogc_build/a/baz" "${TEMP}/output.txt"
grep "___blogc_build/d/e/fuu" "${TEMP}/output.txt"
grep "___blogc_build/d/xd" "${TEMP}/output.txt"
grep "___blogc_build/f/XDDDD" "${TEMP}/output.txt"

rm "${TEMP}/output.txt"

[[ ! -d "${OUTPUT_DIR}" ]]

unset OUTPUT_DIR