# Create a dynamic report summary based on passed/failed tests

I would like to create a report summary at the beginning of my report. The report consists of sections/subsections that outline a test that either passed or failed.

The idea is to only add \passed or \failed in a section to print out passed/failed as well as add passed/failed to the report summary together with the test name (test name equals title of that section - see image below for an example).

The dynamic list from this post seemed to be a great solution, however I can't figure out how to pass along the test name. I've tried many things like adding \label{\thetitle} to each section to reference using \nameref{\thetitle}. But I guess the problem always is that the list is printed before everything else happens. Maybe writing to a temp file is a solution, or some different solution using a modified TOC, or maybe I'm completely off track and there are much better solutions. I'm happy to hear you suggestions.

Just for a better understanding: The goal is to generate this report automatically, that's why it is important to not find a hard coded solution but one that can scale dynamically.

\documentclass[12pt]{article}
\usepackage{xcolor}

\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\defineList}{m}
{\seq_new:c { g_chrillof_list_#1_seq }}
{\iow_shipout:cn { @auxout } { \chrillofaddtolist { #1 } { #2 } }}
{\seq_gput_right:cn { g_chrillof_list_#1_seq } { #2 }}
\NewDocumentCommand{\printList}{m}
{\seq_use:cn { g_chrillof_list_#1_seq } { }}
\ExplSyntaxOff
\defineList{ReportSummary}

\newcommand{\passed}{
\textcolor{green}{
\textbf{PASSED}
}
\newcommand{\failed}{
\textcolor{red}{
\textbf{FAILED}
}

\begin{document}
\tableofcontents

\section{Report Summary}
\begin{tabular}{l l}
Status & Test Name\\
\hline
\printList{ReportSummary}
\end{tabular}

\section{Test 1}
\passed

\section{Test 2}
\subsubsection{Test 2a}
\failed

\subsubsection{Test 2b}
\passed

\end{document}


This is a different approach to include or exclude parts of the report using the codesection package, so the "summary" is simply a standard TOC.

To add also "passed" or "failed" to the ToC (that only have sense if you print all the test) you only need to add this word to the optional argument od the \section (e.g., instead of \section{Foo} some like \section[Foo (passed)]{Foo}. You can use the xesearch package (using xelatex) to mark this keywords in colors automatically. The example print both passed and failed test except one "too bad to show". Setting \DefineCodeSection[true]{Passed} to false will hide sections 1, 2.2 and 2.3 and so on ...

\documentclass{article}
\usepackage{xcolor}
\usepackage{xesearch}
\usepackage{codesection}

\makeatletter

\SearchList*{green}{ \textcolor{green}{#1}}{Passed}
\SearchList{red}{ \textcolor{red}{#1}}{Failed}
\SearchAll{ps}
\DefineCodeSection[true]{Passed} % show Passed ...
\DefineCodeSection[true]{Failed} % and show also (some failed ...)
\newcommand\Section[2]{\section[#1 -- #2]{#1}}
\newcommand\Subsection[2]{\subsection[#1 --~#2]{#1}}
\renewcommand\contentsname{Report summary\par\noindent\hrulefill}

\makeatother

\begin{document}

\tableofcontents\noindent\bigskip\hrulefill

\BeginCodeSection{Passed}
\Section{Test 1}{Passed}  \par Bla bla bla passed this test.
\EndCodeSection{Passed}

\section[So so ...]{Test 2}

\BeginCodeSection{Failed}
\Subsection{Foo}{Failed} Bla bla bla failed this test.
\EndCodeSection{Failed}

\BeginCodeSection{Passed}
\Subsection{Bar}{Passed} Bla bla bla ...
\EndCodeSection{Passed}

\BeginCodeSection{Passed}
\Subsection{Baz}{Passed} Bla bla bla ...
\EndCodeSection{Passed}

\SetCodeSection{Failed}{false} % Too bad pitfall to be showed ...

\BeginCodeSection{Failed}
\Subsection{Whatever}{Failed} Bla bla bla failed miserably ...
\EndCodeSection{Failed}

\SetCodeSection{Failed}{true} %

\BeginCodeSection{Failed}
\Subsection{Whatever else}{Failed} Bla bla bla ...
\EndCodeSection{Failed}

\end{document}

• This wasn't what I had in mind, however this is a very neat solution. Thanks. Aug 8 at 7:02