Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8035c96

Browse files
committedJan 7, 2023
CLJCLR-126 split AOT-dependent parts of clojure.test-clojure.compilation into a separate file
1 parent a677b78 commit 8035c96

File tree

4 files changed

+118
-9
lines changed

4 files changed

+118
-9
lines changed
 

‎Clojure/Clojure.Tests/Clojure.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<None Update="clojure\test_clojure\compilation.clj">
6060
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6161
</None>
62+
<None Update="clojure\test_clojure\compilation2.clj">
63+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64+
</None>
6265
<None Update="clojure\test_clojure\compilation\examples.clj">
6366
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6467
</None>

‎Clojure/Clojure.Tests/clojure/test_clojure/compilation.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
; Author: Frantisek Sodomka
1010

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
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
1313
(ns clojure.test-clojure.compilation
1414
(:import (clojure.lang Compiler Compiler+CompilerException)) ;;; Compiler$CompilerException
1515
(:require [clojure.test.generative :refer (defspec)]
1616
[clojure.data.generators :as gen]
17-
[clojure.test-clojure.compilation.line-number-examples :as line]
17+
;;;[clojure.test-clojure.compilation.line-number-examples :as line]
1818
clojure.string) ;;; DM:Added -- seem to have an order dependency that no longer works.
1919
(:use clojure.test
2020
[clojure.test-helper :only (should-not-reflect should-print-err-message)]))
@@ -228,7 +228,7 @@
228228

229229
;; compile uses a separate code path so we have to call it directly
230230
;; to test it
231-
(letfn [(compile [s] (System.IO.Directory/CreateDirectory "test/clojure") ;;; DM: Added the CreateDirectory
231+
#_(letfn [(compile [s] (System.IO.Directory/CreateDirectory "test/clojure") ;;; DM: Added the CreateDirectory
232232
(spit "test/clojure/bad_def_test.clj" (str "(ns test.clojure.bad-def-test)\n" s)) ;;; DM: Added test. to ns
233233
(try
234234
(binding [*compile-path* "test"]
@@ -285,7 +285,7 @@
285285
#clojure.test_clojure.compilation.Y[1]
286286
(defrecord Y [b])
287287

288-
(binding [*compile-path* "."] ;;; "target/test-classes"
288+
#_(binding [*compile-path* "."] ;;; "target/test-classes"
289289
(compile 'clojure.test-clojure.compilation.examples))
290290

291291
#_(deftest test-compiler-line-numbers ;;; DM: TODO :: Improve Compiler source information. And then do https://github.com/clojure/clojure/commit/715754d3f69e85b07fa56047f0d43d400ab36fce
@@ -318,15 +318,15 @@
318318
(is (fails-on-line-number? 112 line/keyword-invoke))
319319
(is (fails-on-line-number? 119 line/invoke-cast))))
320320

321-
(deftest CLJ-979
321+
#_(deftest CLJ-979
322322
(is (= clojure.test_clojure.compilation.examples.X
323323
(class (clojure.test-clojure.compilation.examples/->X))))
324324
(is (.b (clojure.test_clojure.compilation.Y. 1)))
325325
(is (= clojure.test_clojure.compilation.examples.T
326326
(class (clojure.test_clojure.compilation.examples.T.))
327327
(class (clojure.test-clojure.compilation.examples/->T)))))
328328

329-
(deftest clj-1208
329+
#_(deftest clj-1208
330330
;; clojure.test-clojure.compilation.load-ns has not been loaded
331331
;; so this would fail if the deftype didn't load it in its static
332332
;; initializer as the implementation of f requires a var from
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

‎Clojure/build.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
Value="#{clojure.test-clojure.compilation.load-ns clojure.test-clojure.ns-libs-load-later}" />
169169
<SetEnvironmentVariable Condition="'$(TestTargetFramework)' != 'net462'"
170170
Name="clojure.test-clojure.exclude-namespaces"
171-
Value="#{clojure.test-clojure.compilation.load-ns clojure.test-clojure.ns-libs-load-later clojure.test-clojure.attributes clojure.test-clojure.compilation clojure.test-clojure.genclass}" />
171+
Value="#{clojure.test-clojure.compilation.load-ns clojure.test-clojure.ns-libs-load-later clojure.test-clojure.attributes clojure.test-clojure.compilation2 clojure.test-clojure.genclass}" />
172172
<Exec Command="$(clji) run_test.clj" WorkingDirectory="$(TestDir)" Condition=" '$(Runtime)' == '.Net' "/>
173173
<Exec Command="mono $(clji) run_test.clj" WorkingDirectory="$(TestDir)" Condition=" '$(Runtime)' == 'Mono' "/>
174174
</Target>
@@ -177,7 +177,7 @@
177177
<Copy SkipUnchangedFiles="true" SourceFiles="Clojure.Tests\clojure\run_test_generative.clj" DestinationFolder="$(TestDir)" />
178178
<SetEnvironmentVariable Condition="'$(TestTargetFramework)' != 'net462'"
179179
Name="clojure.test-clojure.exclude-namespaces"
180-
Value="#{clojure.test-clojure.compilation.load-ns clojure.test-clojure.attributes clojure.test-clojure.compilation clojure.test-clojure.genclass}" />
180+
Value="#{clojure.test-clojure.compilation.load-ns clojure.test-clojure.attributes clojure.test-clojure.compilation2 clojure.test-clojure.genclass}" />
181181
<Exec Command="$(clji) run_test_generative.clj" WorkingDirectory="$(TestDir)" Condition=" '$(Runtime)' == '.Net' "/>
182182
<Exec Command="mono $(clji) run_test_generative.clj" WorkingDirectory="$(TestDir)" Condition=" '$(Runtime)' == 'Mono' "/>
183183
</Target>

0 commit comments

Comments
 (0)
Please sign in to comment.