Please help: All the tests fail, but the output of my function is correct

I am currently working on the anagram task and I have included my solution below. When I run this in the emacs scratchpad it works just fine providing an appropriate output in the message area. I have no idea why this is wrong, nor do I know how else I should output the answer (as the question doesn’t ask for the output to be in a particular form).

Any help would be greatly appreciated.

;;; anagram.el — Anagram (exercism) -- lexical-binding: t; --

;;; Commentary:

(defun anagrams-for (subject candidates)
;;; Code:
(setq list1 ())

(setq val nil)
(dolist (val candidates)
;(insert “%s” val)
(if (not (equal (downcase subject) (downcase val)))
(setq list1 (cons val list1))

  ))

(setq subn (sort (string-to-list (downcase subject)) '<))
(setq list2 'nil)

(dolist (i list1)
(if (equal subn (sort (string-to-list (downcase i)) '<) )
(setq list2 (cons i list2))
))
(message (format “%s” list2))

)

(provide 'anagram)
;;; anagram.el ends here

  1. You can use a codeblock to make the code readable.
  2. Sharing (and closely examining) the test output would be incredibly helpful to debug what is failing. It shows the failure.
  3. “it works just fine providing an appropriate output in the message area” – the exercise doesn’t ask you to output anything in the message area. It works fine to do one thing (output a message) but that’s not what the exercise/test asks you to do. All Exercism exercises ask you to return a value in some fashion. You may want to look at the first Hello World exercise to see how what the track expects your code to do.
  4. You may also want to run the tests locally. You can find instructions on the track docs: Testing on the Emacs Lisp track | Exercism's Docs

Thank you, for your help, my fault for taking too long between exercises. All fixed now.