Skip to content

Instantly share code, notes, and snippets.

@stuartsierra
Created July 4, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartsierra/ca2b9bd7072224e099beb8b95b49b69c to your computer and use it in GitHub Desktop.
Save stuartsierra/ca2b9bd7072224e099beb8b95b49b69c to your computer and use it in GitHub Desktop.
Test script for macro spec in clojure.test
#!/usr/bin/env bash
# Test script attempting to reproduce issue described at
# https://groups.google.com/d/topic/clojure/jASgZpaZkTc/discussion
# $ lein version
# Leiningen 2.7.1 on Java 1.8.0_92 Java HotSpot(TM) 64-Bit Server VM
lein new trymacrospec
cd trymacrospec
cat >project.clj <<'EOF'
(defproject trymacrospec "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.9.0-alpha17"]])
EOF
cat >src/trymacrospec/core.clj <<'EOF'
(ns trymacrospec.core
(:require
[clojure.spec.alpha :as s]))
(s/fdef fish
:args (s/cat :func symbol?
:args (s/* any?))
:ret any?)
(defmacro fish [f & args]
`(~f ~@args))
EOF
cat >test/trymacrospec/core_test.clj <<'EOF'
(ns trymacrospec.core-test
(:require [clojure.test :refer :all]
[trymacrospec.core :refer :all]))
(deftest a-test
(testing "FIXME, I fail."
(is (thrown? Exception (macroexpand '(fish "not a symbol" 1))))))
EOF
lein test
# $ ./trymacrospec.sh
# Generating a project called trymacrospec based on the 'default' template.
# The default template is intended for library projects, not applications.
# To see other templates (app, plugin, etc), try `lein help new`.
#
# lein test trymacrospec.core-test
#
# lein test :only trymacrospec.core-test/a-test
#
# FAIL in (a-test) (core_test.clj:7)
# FIXME, I fail.
# expected: (thrown? Exception (macroexpand (quote (fish "not a symbol" 1))))
# actual: nil
#
# Ran 1 tests containing 1 assertions.
# 1 failures, 0 errors.
# Tests failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment