#!/bin/sh

set -exu

# This is a test that generates a man page and compares the output to what's expected.
cd ${AUTOPKGTEST_TMP}

export SOURCE_DATE_EPOCH=1566164804
cat > example.adoc << __EOF__
= example(1)
Joseph Herlant
v1.0.0
:doctype: manpage
:manmanual: EXAMPLE
:mansource: EXAMPLE

== Name

example - an example of manpage

== Synopsis

*example* [_OPTION_]... _FILE_...

== Options

*-o, --out-file*=_OUT_FILE_::
  Write result to file _OUT_FILE_.

== Exit status

*0*::
  Success.
  Foo!

*1*::
  Failure.
  Bar :(

== Resources

*Project web site:* http://example.org

== Copying

Copyright (C) 2019 {author}. +
Free use of this software is granted under the terms of the MIT License.
__EOF__

cat > example.ref << __EOF__
'\" t
.\"     Title: example
.\"    Author: Joseph Herlant
.\"      Date: v1.0.0
.\"    Manual: EXAMPLE
.\"    Source: EXAMPLE
.\"  Language: English
.\"
.TH "EXAMPLE" "1" "v1\&.0\&.0" "EXAMPLE" "EXAMPLE"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
example \- an example of manpage
.SH "SYNOPSIS"
.sp
\fBexample\fR [\fIOPTION\fR]\&... \fIFILE\fR\&...
.SH "OPTIONS"
.PP
\fB\-o, \-\-out\-file\fR=\fIOUT_FILE\fR
.RS 4
Write result to file
\fIOUT_FILE\fR\&.
.RE
.SH "EXIT STATUS"
.PP
\fB0\fR
.RS 4
Success\&. Foo!
.RE
.PP
\fB1\fR
.RS 4
Failure\&. Bar :(
.RE
.SH "RESOURCES"
.sp
\fBProject web site:\fR http://example\&.org
.SH "COPYING"
.sp
Copyright \(co 2019 Joseph Herlant\&. Free use of this software is granted under the terms of the MIT License\&.
.SH "AUTHOR"
.PP
\fBJoseph Herlant\fR
.RS 4
Author.
.RE
__EOF__

a2x -f manpage example.adoc
# Removing the generator as it contains the version so we would have to change that all the time
sed '/Generator/d' -i example.1
diff example.ref example.1
