# Environment with delayed expansion

I'm trying to define an environment test that stores its contents unexpanded in a macro \testcontents.

For example, the code

\newcommand{\cmd}{bad}

\begin{test}
\cmd
\end{test}

\renewcommand{\cmd}{okay}

\testcontents


should print out "okay".

How would I define such an environment? I know that the environ package could be used to store the contents after expansion, but I need them unexpanded.

-
environ doesn't expand the body as far as I can see? – David Carlisle Dec 10 '12 at 2:10

environ works as you require, it collects the body without expansion, the following typesets okay

\documentclass{article}

\usepackage{environ}

\NewEnviron{test}
{\global\let\testcontents\BODY}

\begin{document}