| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (main.clj)

This example Java source code file (main.clj) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

author, copyright, eclipse, halloway, hickey, license, object, public, rich, run, stringwriter, the, you

The main.clj Java example source code

;   Copyright (c) Rich Hickey. All rights reserved.
;   The use and distribution terms for this software are covered by the
;   Eclipse Public License 1.0 (
;   which can be found in the file epl-v10.html at the root of this distribution.
;   By using this software in any fashion, you are agreeing to be bound by
;   the terms of this license.
;   You must not remove this notice, or any other, from this software.

; Author: Stuart Halloway

(ns clojure.test-clojure.main
  (:use clojure.test
        [clojure.test-helper :only [platform-newlines]])
  (:require [clojure.main :as main]))

(deftest eval-opt
  (testing "evals and prints forms"
    (is (= (platform-newlines "2\n4\n") (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)")))))

  (testing "skips printing nils"
    (is (= (platform-newlines ":a\n:c\n") (with-out-str (#'clojure.main/eval-opt ":a nil :c")))))

  (testing "does not block access to *in* (#299)"
    (with-in-str "(+ 1 1)"
      (is (= (platform-newlines "(+ 1 1)\n") (with-out-str (#'clojure.main/eval-opt "(read)")))))))

(defmacro with-err-str
  "Evaluates exprs in a context in which *err* is bound to a fresh
  StringWriter.  Returns the string created by any nested printing
  [& body]
  `(let [s# (new
         p# (new s#)]
     (binding [*err* p#]
       (str s#))))

(defn run-repl-and-return-err
  "Run repl, swallowing stdout and returing stderr."
      (with-in-str in-str

;argh - test fragility, please fix
#_(deftest repl-exception-safety
  (testing "catches and prints exception on bad equals"
    (is (re-matches #"java\.lang\.NullPointerException\r?\n"
            "(proxy [Object] [] (equals [o] (.toString nil)))")))))

Other Java examples (source code examples)

Here is a short list of links related to this Java main.clj source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.