Public Vars

Back

assert (clj)

(source)

macro

(assert x) (assert x message)
Evaluates expr and throws an exception if it does not evaluate to logical true.

Examples

clojure
(ns clojure.test-clojure.reducers
  (:require [clojure.core.reducers :as r]
            [clojure.test.generative :refer (defspec)]
            [clojure.data.generators :as gen])
  (:use clojure.test))

(defspec reduced-always-returns
  (fn [probe to-end]
    (let [len (+ probe to-end 1)
          nums (range len)
          m (zipmap nums nums)]
      (reduced-at-probe m probe)))
  [^{:tag `gen-num} probe ^{:tag `gen-num} to-end]
  (assert (= :foo %)))
clojure/core.async
;; The clojure.core.async namespace contains the public API.
(require '[clojure.core.async :as async :refer :all])

(let [c (chan 10)]
  (>!! c "hello")
  (assert (= "hello" (<!! c)))
  (close! c))

(let [c (chan)]
  (thread (>!! c "hello"))
  (assert (= "hello" (<!! c)))
  (close! c))

;; Here we convert our prior channel example to use go blocks:
(let [c (chan)]
  (go (>! c "hello"))
  (assert (= "hello" (<!! (go (<! c)))))
  (close! c))

(let [n 1000
      cs (repeatedly n chan)
      begin (System/currentTimeMillis)]
  (doseq [c cs] (go (>! c "hi")))
  (dotimes [i n]
    (let [[v c] (alts!! cs)]
      (assert (= "hi" v))))
  (println "Read" n "msgs in" (- (System/currentTimeMillis) begin) "ms"))
clojure/core.typed
(ns clojure.core.typed.test.def-arrow
  (:require [clojure.core.typed :as t]))

(assert (= (+ a 1) 2))
clj-commons/manifold
(ns manifold.stream.async
  {:no-doc true}
  (:require
    [manifold.deferred :as d]
    [clojure.core.async :as a]
    [manifold.stream
     [graph :as g]
     [core :as s]]
    [manifold
     [executor :as executor]
     [utils :as utils]])
  (:import
    [java.util.concurrent.atomic
     AtomicReference]))

    (assert (not (nil? x)) "core.async channel cannot take `nil` as a message")

    (if (nil? timeout)
      (.put this x blocking?)
      (assert (not (nil? x)) "core.async channel cannot take `nil` as a message"))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/*1 t/Any
cc/*2 t/Any
cc/*3 t/Any
cc/*e #?(:cljs t/Any :default (t/U nil Throwable))
#?@(:cljs [] :default [
cc/*agent* (t/U nil (t/Deref t/Any) #_(t/Agent t/Any))
cc/*allow-unresolved-vars* t/Any
cc/*data-readers* (t/Map t/Sym t/AnyVar)
cc/*default-data-reader-fn* (t/U nil [t/Any t/Any :-> t/Any])
cc/*fn-loader* t/Any
cc/*math-context* t/Any
cc/*source-path* t/Str
cc/*use-context-classloader* t/Any
])
cc/*assert* t/Any

#?@(:cljs [] :default [
clojure.test/function? [t/Any :-> t/Bool]
clojure.test/assert-any [t/Any t/Any :-> t/Any]
clojure.test/do-report [t/Any :-> t/Any]
clojure.test/run-tests [t/Sym :* :-> (t/Map t/Any t/Any)]
clojure.test/run-all-tests [(t/? t/Regex) :-> (t/Map t/Any t/Any)]
clojure.test/successful? [(t/U nil (t/Map t/Any t/Any)) :-> t/Bool]
clojure.test/compose-fixtures [[[:-> t/Any] :-> t/Any] [[:-> t/Any] :-> t/Any] :-> [[:-> t/Any] :-> t/Any]]
clojure.test/testing-vars-str [(t/Map t/Any t/Any) :-> t/Str]
clojure.test/testing-contexts-str [:-> t/Str]
clojure.test/test-ns [(t/U t/Namespace t/Sym) :-> (t/Map t/Any t/Any)]
clojure.test/test-var [t/AnyVar :-> t/Any]

cc/peek (t/All [x] (t/IFn [(t/I t/NonEmptyCount (t/Stack x)) :-> x]
                          [(t/Stack x) :-> (t/Nilable x)]))
;;TODO assert non-empty arg
cc/pop (t/All [x] (t/IFn [(t/List x) :-> (t/List x)]
                         [(t/Vec x) :-> (t/Vec x)]
                         [(t/Stack x) :-> (t/Stack x)]))
lynaghk/zmq-async
(ns com.keminglabs.zmq-async.t-core
  (:require [com.keminglabs.zmq-async.core :refer :all]
            [clojure.core.async :refer [go close! >!! <!! chan timeout alts!!]]
            [midje.sweet :refer :all])
  (:import org.zeromq.ZMQ))

                                 (try
                                   ?form
                                   (finally
                                     (send! zcontrol "shutdown")
                                     (.join zmq-thread 100)
                                     (assert (not (.isAlive zmq-thread)))

                                 (.connect sock-client addr)
                                 (.start async-thread)
                                 (try
                                   ?form
                                   (finally
                                     (close! acontrol)
                                     (.join async-thread 100)
                                     (assert (not (.isAlive async-thread)))

                                 (try
                                   ?form
                                   (finally
                                     ((:shutdown context))
                                     (.join async-thread 100)
                                     (assert (not (.isAlive async-thread)))

                                     (.join zmq-thread 100)
                                     (assert (not (.isAlive zmq-thread)))


    (fact "wrapped req <-> wrapped rep, go/future"
      (let [addr "inproc://test-addr"
            [s-out s-in c-out c-in] (repeatedly 4 chan)
            n 5
            server (go
                     (dotimes [_ n]
                       (assert (= "ping" (String. (<! s-out)))
                               "server did not receive ping")
                       (>! s-in "pong"))
                     :success)

            client (future
                     (dotimes [_ n]
                       (>!! c-in "ping")
                       (assert (= "pong" (String. (<!! c-out)))
                               "client did not receive pong"))
                     :success)]

    (fact "wrapped req <-> wrapped rep, go/go"
      (let [addr "inproc://test-addr"
            [s-out s-in c-out c-in] (repeatedly 4 chan)
            n 5
            server (go
                     (dotimes [_ n]
                       (assert (= "ping" (String. (<! s-out)))
                               "server did not receive ping")
                       (>! s-in "pong"))
                     :success)

            client (go
                     (dotimes [_ n]
                       (>! c-in "ping")
                       (assert (= "pong" (String. (<! c-out)))
                               "client did not receive pong"))
                     :success)]