如何设置clojureScript项目以使用规范并在运行时测试clojure.core函数? [英] How do I set up a clojureScript project to use specs and test the clojure.core functions at runtime?

查看:130
本文介绍了如何设置clojureScript项目以使用规范并在运行时测试clojure.core函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Clojure 1.9引入了规范。 clojure.core库中的函数现在具有规范。如何设置clojurescript项目以使用规范并在运行时测试clojure.core函数?

Clojure 1.9 introduced specs. Functions in the clojure.core library now have specs. How do I set up a clojurescript project to use specs and test the clojure.core functions at runtime?

我使用了库 [org.clojure /test.check 0.10.0-alpha2] [org.clojure / spec.alpha 0.1.123] 安装规格和命令 instrument 。它可以检测我编写的规范中的问题。但是它没有检测到 clojure.core 的问题(例如, map )。

I used the libraries [org.clojure/test.check "0.10.0-alpha2"] and [org.clojure/spec.alpha "0.1.123"] to install specs and the command instrument. It worked to detect problems in functions that I wrote specs. But it didn't detect problems with clojure.core (for instance, map).

也许规范还不适用于clojurescript。

Maybe specs do not work with clojurescript yet.

推荐答案

这是因为没有规范对于 clojure.core 函数,仅适用于几个宏的规范-参见此处: https://github.com/clojure/core.specs.alpha/blob/master/ src / main / clojure / clojure / core / specs / alpha.clj#L53

This is because there are no specs for clojure.core functions, only specs for a couple of macros - look here: https://github.com/clojure/core.specs.alpha/blob/master/src/main/clojure/clojure/core/specs/alpha.clj#L53

请注意,


在宏扩展过程中始终会检查宏,因此您不需要
宏规格的调用工具

macros are always checked during macro expansion, you do not need to call instrument for macro specs

https://clojure.org/guides/spec#_macros

您可以编写自己的核心功能规范并将其注册为此处显示: https:// clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/fdef

You can write your own specs for core functions and register them as shown here: https://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/fdef

(s/fdef clojure.core/symbol
  :args (s/alt :separate (s/cat :ns string? :n string?)
               :str string?
               :sym symbol?)
  :ret symbol?)

但是请谨慎处理,因为如果操作不正确,可能会遇到令人讨厌的问题。

However, be careful with this since you might get into nasty issues if you don't get it right.

这篇关于如何设置clojureScript项目以使用规范并在运行时测试clojure.core函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆