I made a simple macro called \cmd{} which detokenizes the input. I would like to print the contents exactly as shown, and it works as I desire, except that it seems to produce a space between an inputted command sequence and the curly braces.
\documentclass{article}
\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}}
\begin{document}
\cmd{\test{}}
\end{document}
results in \test {}
Edit: I would like a verbatim-like macro called \cmd{} that does the following:
\cmd{\test{}} → \test{}
Edit: I did try the solutions posed in Detokenizing without extra spaces?, but have had no luck. I am using LuaLaTeX.

\verb, but this sounds like an XY problem: what exactly are you after? – campa Sep 01 '22 at 14:06\detokenizedoes. If your argument is a single control sequence,\stringcan produce it without the space. What is your actual use case? – Steven B. Segletes Sep 01 '22 at 14:06\detokenizeis like writing tokens unexpanded to an external file and then inputting the external file under a category code régime where the space character has category code 10 (space) and all other characters have category code 12(other) and\endlinecharhas a negative value.\newlinecharis obeyed with the writing-part. When writing a control word token, TeX automatically appends a space character. Another peculiarity of TeX's way of writing tokens is: When writing an explicit hash of category 6(parameter) that gets doubled. – Ulrich Diez Sep 02 '22 at 15:02