1
+ ; Copyright (c) Rich Hickey. All rights reserved.
2
+ ; The use and distribution terms for this software are covered by the
3
+ ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4
+ ; which can be found in the file epl-v10.html at the root of this distribution.
5
+ ; By using this software in any fashion, you are agreeing to be bound by
6
+ ; the terms of this license.
7
+ ; You must not remove this notice, or any other, from this software.
8
+
9
+ ; Author: Frantisek Sodomka
10
+
11
+ (assembly-load-from " clojure.test_clojure.compilation.line_number_examples.clj.dll" ) ; ;; DM:Added
12
+ (assembly-load-from " clojure.test_clojure.compilation.load_ns.clj.dll" ) ; ;; DM:Added
13
+ (ns clojure.test-clojure.compilation2
14
+ (:import (clojure.lang Compiler Compiler+CompilerException)) ; ;; Compiler$CompilerException
15
+ (:require [clojure.test.generative :refer (defspec )]
16
+ [clojure.data.generators :as gen]
17
+ [clojure.test-clojure.compilation.line-number-examples :as line]
18
+ clojure.string) ; ;; DM:Added -- seem to have an order dependency that no longer works.
19
+ (:use clojure.test
20
+ [clojure.test-helper :only (should-not-reflect should-print-err-message)]))
21
+
22
+ ; http://clojure.org/compilation
23
+
24
+
25
+ ; ;; this file splits off the tests that can only be done having AOT-compilation.
26
+ ; ;; Eventually, merge this back into compilation.clj.
27
+
28
+
29
+ (defrecord Y [a])
30
+ #clojure.test_clojure.compilation2.Y[1 ]
31
+ (defrecord Y [b])
32
+
33
+ (binding [*compile-path* " ." ] ; ;; "target/test-classes"
34
+ (compile 'clojure.test-clojure.compilation.examples))
35
+
36
+
37
+ #_(deftest test-compiler-line-numbers ; ;; DM: TODO :: Improve Compiler source information. And then do https://github.com/clojure/clojure/commit/715754d3f69e85b07fa56047f0d43d400ab36fce
38
+ (let [fails-on-line-number? (fn [expected function]
39
+ (try
40
+ (function )
41
+ nil
42
+ (catch Exception t ; ;; Throwable
43
+ (let [frames (filter #(= " line_number_examples.clj" (.GetFileName %)) ; ;; .getFileName
44
+ (.GetFrames (System.Diagnostics.StackTrace. t true ))) ; ;; (.getStackTrace t))
45
+ _ (if (zero? (count frames))
46
+ (Console/WriteLine (.ToString t)) ; ;; (.printStackTrace t)
47
+ )
48
+ actual (.GetFileLineNumber ^System.Diagnostics.StackFrame (first frames))] ; ;; .getLineNumber ^StackTraceElement
49
+ (= expected actual)))))]
50
+ (is (fails-on-line-number? 13 line/instance-field))
51
+ (is (fails-on-line-number? 19 line/instance-field-reflected))
52
+ (is (fails-on-line-number? 25 line/instance-field-unboxed))
53
+ #_(is (fails-on-line-number? 32 line/instance-field-assign))
54
+ (is (fails-on-line-number? 40 line/instance-field-assign-reflected))
55
+ #_(is (fails-on-line-number? 47 line/static-field-assign))
56
+ (is (fails-on-line-number? 54 line/instance-method))
57
+ (is (fails-on-line-number? 61 line/instance-method-reflected))
58
+ (is (fails-on-line-number? 68 line/instance-method-unboxed))
59
+ (is (fails-on-line-number? 74 line/static-method))
60
+ (is (fails-on-line-number? 80 line/static-method-reflected))
61
+ (is (fails-on-line-number? 86 line/static-method-unboxed))
62
+ (is (fails-on-line-number? 92 line/invoke))
63
+ (is (fails-on-line-number? 101 line/threading))
64
+ (is (fails-on-line-number? 112 line/keyword-invoke))
65
+ (is (fails-on-line-number? 119 line/invoke-cast))))
66
+
67
+ (deftest clj-1208
68
+ ; ; clojure.test-clojure.compilation.load-ns has not been loaded
69
+ ; ; so this would fail if the deftype didn't load it in its static
70
+ ; ; initializer as the implementation of f requires a var from
71
+ ; ; that namespace
72
+ (is (= 1 (.f (clojure.test_clojure.compilation.load_ns.x. )))))
73
+
74
+
75
+ (deftest CLJ-979
76
+ (is (= clojure.test_clojure.compilation.examples.X
77
+ (class (clojure.test-clojure.compilation.examples/->X ))))
78
+ (is (.b (clojure.test_clojure.compilation2.Y. 1 )))
79
+ (is (= clojure.test_clojure.compilation.examples.T
80
+ (class (clojure.test_clojure.compilation.examples.T. ))
81
+ (class (clojure.test-clojure.compilation.examples/->T )))))
82
+
83
+
84
+ (deftest CLJ-1184-do-in-non-list-test
85
+ (testing " do in a vector throws an exception"
86
+ (is (thrown? Compiler+CompilerException ; ;; Compiler$CompilerException
87
+ (eval '[do 1 2 3 ]))))
88
+ (testing " do in a set throws an exception"
89
+ (is (thrown? Compiler+CompilerException ; ;; Compiler$CompilerException
90
+ (eval '#{do }))))
91
+
92
+ ; ; compile uses a separate code path so we have to call it directly
93
+ ; ; to test it
94
+ (letfn [(compile [s] (System.IO.Directory/CreateDirectory " test/clojure" ) ; ;; DM: Added the CreateDirectory
95
+ (spit " test/clojure/bad_def_test.clj" (str " (ns test.clojure.bad-def-test)\n " s)) ; ;; DM: Added test. to ns
96
+ (try
97
+ (binding [*compile-path* " test" ]
98
+ (clojure.core/compile 'test.clojure.bad-def-test)) ; ;; DM: Added test. to name
99
+ (finally
100
+ (doseq [f (.GetFiles (System.IO.DirectoryInfo. " test/clojure" )) ; ;; .listFiles java.io.File.
101
+ :when (re-find #"bad_def_test" (str f))]
102
+ (.Delete f)))))]
103
+ (testing " do in a vector throws an exception in compilation"
104
+ (is (thrown? Compiler+CompilerException (compile " [do 1 2 3]" )))) ; ;; Compiler$CompilerException
105
+ (testing " do in a set throws an exception in compilation"
106
+ (is (thrown? Compiler+CompilerException (compile " #{do}" )))))) ; ;; Compiler$CompilerException
0 commit comments