Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 78226f1

Browse files
author
Mourjo Sen
committed
Add a sample project to test selectors
1 parent fb5fcc0 commit 78226f1

File tree

10 files changed

+362
-0
lines changed

10 files changed

+362
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ pom.xml.asc
1010
.hgignore
1111
.hg/
1212
/test-results/
13+
dev-resources/weasley/target/
14+
dev-resources/weasley/.lein-failures
15+
dev-resources/weasley/test-results/
16+
dev-resources/weasley/.lein-repl-history
17+
test_out.txt
18+
dev-resources/weasley/test_out.txt

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
weasley-test: root-test
2+
@echo "------------------------------------"
3+
@echo "Testing internal project Weasley"
4+
@echo "------------------------------------"
5+
6+
# The goal is to compare test runs with Leiningen where
7+
# possible (is there a better way than this?)
8+
sh test.sh
9+
10+
root-test:
11+
@echo "------------------------------------"
12+
@echo "Testing root project circleci.test"
13+
@echo "------------------------------------"
14+
lein do clean, compile
15+
lein test
16+
17+
test: root-test
18+
19+
.PHONY: test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(def circleci-test-version "0.4.3")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(require '[circleci.test.report :refer (clojure-test-reporter)])
2+
(require '[circleci.test.report.junit :as junit])
3+
(require '[clojure.java.io :as io])
4+
5+
(def ^:dynamic *global-counter* 0)
6+
7+
{:selectors {:all (constantly true)
8+
:default (complement :failing)
9+
:select-vars (fn [m]
10+
(.endsWith (str (:name m)) "-2"))
11+
:combination :combination}
12+
:test-results-dir (or (System/getenv "CIRCLE_TEST_REPORTS")
13+
"test-results")
14+
:reporters [clojure-test-reporter junit/reporter]
15+
:global-fixture (fn [f]
16+
(try
17+
(io/delete-file "global_fixture_test.out" true)
18+
(assert (zero? *global-counter*))
19+
(binding [*global-counter* (inc *global-counter*)]
20+
(spit "global_fixture_test.out" *global-counter* :append true)
21+
(f))
22+
(finally
23+
(io/delete-file "global_fixture_test.out" true)
24+
(assert (false? (.exists (clojure.java.io/file "global_fixture_test.out")))))))}

dev-resources/weasley/project.clj

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(load-file "./circleci.test.version")
2+
(defproject circleci/weasley "0.1.0-SNAPSHOT"
3+
:dependencies [[org.clojure/clojure "1.10.1"]
4+
[circleci/circleci.test ~circleci-test-version]]
5+
:target-path "target/%s"
6+
:profiles {:uberjar {:aot :all}}
7+
:main weasley.core
8+
:aot [weasley.core]
9+
:aliases {"test" ["run" "-m" "circleci.test/dir" :project/test-paths]
10+
"tests" ["run" "-m" "circleci.test"]
11+
"retest" ["run" "-m" "circleci.test.retest"]})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns weasley.core
2+
(:gen-class))
3+
4+
(defn -main
5+
"I don't do a whole lot ... yet."
6+
[& args]
7+
(println "Hello, World!"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(ns weasley.sample-test-ns1
2+
(:require [clojure.test :refer :all]))
3+
4+
(def ^:dynamic vonce 0)
5+
(def ^:dynamic veach 0)
6+
(def ^:dynamic vcommon 0)
7+
8+
(deftest test-1
9+
(println "Running: circleci.sample-test-ns1/test-1")
10+
(is (= 1 1))
11+
(is (zero? veach))
12+
(is (zero? vonce))
13+
(is (zero? vcommon)))
14+
15+
(deftest test-2
16+
(println "Running: circleci.sample-test-ns1/test-2")
17+
(is (= 10 10))
18+
(is (zero? veach))
19+
(is (zero? vonce))
20+
(is (zero? vcommon)))
21+
22+
(deftest test-3
23+
(println "Running: circleci.sample-test-ns1/test-3")
24+
(is (= 109 109))
25+
(is (zero? veach))
26+
(is (zero? vonce))
27+
(is (zero? vcommon)))
28+
29+
30+
(defn test-ns-hook
31+
[]
32+
(test-1)
33+
(test-2)
34+
(test-3))
35+
36+
37+
(defn each-fixture
38+
[f]
39+
(binding [veach (inc veach)
40+
vcommon (inc vcommon)]
41+
(f)))
42+
43+
44+
(defn once-fixture
45+
[f]
46+
(binding [vonce (inc vonce)
47+
vcommon (inc vcommon)]
48+
(f)))
49+
50+
51+
52+
(use-fixtures :each each-fixture)
53+
(use-fixtures :once once-fixture)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
(ns weasley.sample-test-ns2
2+
(:require [clojure.test :refer :all]))
3+
4+
(def ^:dynamic vonce 0)
5+
(def ^:dynamic veach 0)
6+
(def ^:dynamic vcommon 0)
7+
(def ^:dynamic level-of-nesting 0)
8+
9+
(deftest test-1
10+
(when (zero? level-of-nesting)
11+
(println "Running: circleci.sample-test-ns2/test-1"))
12+
(is (= 1 1))
13+
(is (= 1 veach))
14+
(is (= 1 vonce))
15+
(is (= 2 vcommon)))
16+
17+
(deftest test-2
18+
(when (zero? level-of-nesting)
19+
(println "Running: circleci.sample-test-ns2/test-2"))
20+
(is (= 10 10))
21+
(is (= 1 veach))
22+
(is (= 1 vonce))
23+
(is (= 2 vcommon)))
24+
25+
(deftest test-3
26+
(when (zero? level-of-nesting)
27+
(println "Running: circleci.sample-test-ns2/test-3"))
28+
(is (= 109 109))
29+
(is (= 1 veach))
30+
(is (= 1 vonce))
31+
(is (= 2 vcommon)))
32+
33+
(deftest ^:combination test-4
34+
(when (zero? level-of-nesting)
35+
(println "Running: circleci.sample-test-ns2/test-4"))
36+
(binding [level-of-nesting (inc level-of-nesting)]
37+
(test-1)
38+
(test-2)
39+
(test-3)))
40+
41+
(deftest ^:combination test-5
42+
(println "Running: circleci.sample-test-ns2/test-5")
43+
(binding [level-of-nesting (inc level-of-nesting)]
44+
(test-1)
45+
(test-2)
46+
(test-3)
47+
(test-4)))
48+
49+
50+
(defn each-fixture
51+
[f]
52+
(binding [veach (inc veach)
53+
vcommon (inc vcommon)]
54+
(f)))
55+
56+
57+
(defn once-fixture
58+
[f]
59+
(binding [vonce (inc vonce)
60+
vcommon (inc vcommon)]
61+
(f)))
62+
63+
64+
(use-fixtures :each each-fixture)
65+
(use-fixtures :once once-fixture)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
(ns ^:global-fixture weasley.sample-test-ns3
2+
(:require [clojure.test :refer :all]))
3+
4+
(def ^:dynamic vonce 0)
5+
(def ^:dynamic veach 0)
6+
(def ^:dynamic vcommon 0)
7+
(def ^:dynamic level-of-nesting 0)
8+
9+
(defn global-fixture-file
10+
[]
11+
(slurp "global_fixture_test.out"))
12+
13+
(deftest test-1
14+
(when (zero? level-of-nesting)
15+
(println "Running: circleci.sample-test-ns3/test-1"))
16+
(is (= 1 veach))
17+
(is (= 1 vonce))
18+
(is (= 2 vcommon))
19+
(is (= "1" (global-fixture-file))))
20+
21+
(deftest test-2
22+
(when (zero? level-of-nesting)
23+
(println "Running: circleci.sample-test-ns3/test-2"))
24+
(is (= 1 veach))
25+
(is (= 1 vonce))
26+
(is (= 2 vcommon))
27+
(is (= "1" (global-fixture-file))))
28+
29+
(deftest test-3
30+
(when (zero? level-of-nesting)
31+
(println "Running: circleci.sample-test-ns3/test-3"))
32+
(is (= 1 veach))
33+
(is (= 1 vonce))
34+
(is (= 2 vcommon))
35+
(is (= "1" (global-fixture-file))))
36+
37+
(deftest ^:combination test-4
38+
(when (zero? level-of-nesting)
39+
(println "Running: circleci.sample-test-ns3/test-4"))
40+
(binding [level-of-nesting (inc level-of-nesting)]
41+
(test-1)
42+
(test-2)
43+
(test-3)
44+
(assert (= "1" (global-fixture-file)))))
45+
46+
(deftest ^:combination test-5
47+
(println "Running: circleci.sample-test-ns3/test-5")
48+
(binding [level-of-nesting (inc level-of-nesting)]
49+
(test-1)
50+
(test-2)
51+
(test-3)
52+
(test-4)
53+
(assert (= "1" (global-fixture-file)))))
54+
55+
56+
(defn each-fixture
57+
[f]
58+
(binding [veach (inc veach)
59+
vcommon (inc vcommon)]
60+
(assert (= "1" (global-fixture-file)))
61+
(f)))
62+
63+
64+
(defn once-fixture
65+
[f]
66+
(binding [vonce (inc vonce)
67+
vcommon (inc vcommon)]
68+
(assert (= "1" (global-fixture-file)))
69+
(f)))
70+
71+
72+
(use-fixtures :each each-fixture)
73+
(use-fixtures :once once-fixture)

test.sh

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
grep defproject project.clj | cut -d" " -f3 | xargs -I {} echo "(def circleci-test-version \"{}\")" > dev-resources/weasley/circleci.test.version
2+
3+
lein install
4+
5+
cd dev-resources/weasley/
6+
7+
lein do clean, compile
8+
9+
# Counts between leiningen and circleci are off because of tests with global fixtures (ns3)
10+
lein test > test_out.txt &&
11+
grep "Ran 33 tests containing 108 assertions." test_out.txt &&
12+
lein update-in :aliases empty -- update-in : assoc :test-selectors '{:default (complement :global-fixture)}' -- test > test_out.txt &&
13+
grep "Ran 18 tests containing 60 assertions." test_out.txt &&
14+
15+
lein tests weasley.sample-test-ns1 weasley.sample-test-ns2 > test_out.txt &&
16+
grep "Ran 18 tests containing 60 assertions." test_out.txt &&
17+
lein update-in :aliases empty -- test :only weasley.sample-test-ns1 weasley.sample-test-ns2 > test_out.txt &&
18+
grep "Ran 18 tests containing 60 assertions." test_out.txt &&
19+
20+
lein tests weasley.sample-test-ns1 > test_out.txt &&
21+
grep "Ran 3 tests containing 12 assertions." test_out.txt &&
22+
lein update-in :aliases empty -- test :only weasley.sample-test-ns1 > test_out.txt &&
23+
grep "Ran 3 tests containing 12 assertions." test_out.txt &&
24+
25+
lein tests weasley.sample-test-ns2 > test_out.txt &&
26+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
27+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2 > test_out.txt &&
28+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
29+
30+
lein tests weasley.sample-test-ns2 weasley.sample-test-ns2 weasley.sample-test-ns2 weasley.sample-test-ns2 > test_out.txt &&
31+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
32+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2 weasley.sample-test-ns2 weasley.sample-test-ns2 > test_out.txt &&
33+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
34+
35+
lein tests x y/z > test_out.txt &&
36+
grep "Ran 0 tests containing 0 assertions." test_out.txt &&
37+
lein update-in :aliases empty -- test :only x y/z > test_out.txt &&
38+
grep "Ran 0 tests containing 0 assertions." test_out.txt &&
39+
40+
lein tests weasley.sample-test-ns2 weasley.sample-test-ns1/test-1 x y/z > test_out.txt &&
41+
grep "Ran 16 tests containing 52 assertions." test_out.txt &&
42+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2 weasley.sample-test-ns1/test-1 x y/z > test_out.txt &&
43+
grep "Ran 16 tests containing 52 assertions." test_out.txt &&
44+
45+
lein tests weasley.sample-test-ns2/test-1 > test_out.txt &&
46+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
47+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2/test-1 > test_out.txt &&
48+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
49+
50+
lein tests weasley.sample-test-ns2/test-1 weasley.sample-test-ns2/test-2 > test_out.txt &&
51+
grep "Ran 2 tests containing 8 assertions." test_out.txt &&
52+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2/test-1 weasley.sample-test-ns2/test-2 > test_out.txt &&
53+
grep "Ran 2 tests containing 8 assertions." test_out.txt &&
54+
55+
lein tests weasley.sample-test-ns2/test-1 weasley.sample-test-ns2 weasley.sample-test-ns2/test-2 weasley.sample-test-ns2/test-1 > test_out.txt &&
56+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
57+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2/test-1 weasley.sample-test-ns2 weasley.sample-test-ns2/test-2 weasley.sample-test-ns2/test-1 > test_out.txt &&
58+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
59+
60+
lein tests :select-vars weasley.sample-test-ns2 > test_out.txt &&
61+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
62+
lein update-in :aliases empty -- test :only weasley.sample-test-ns2/test-2 > test_out.txt &&
63+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
64+
65+
lein tests :select-vars weasley.sample-test-ns1 > test_out.txt &&
66+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
67+
lein update-in :aliases empty -- test :only weasley.sample-test-ns1/test-2 > test_out.txt &&
68+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
69+
70+
# The equivalent run for this in Leiningen does not work (test-ns-hook)
71+
lein tests :combination weasley.sample-test-ns2 > test_out.txt &&
72+
grep "Ran 12 tests containing 36 assertions." test_out.txt &&
73+
74+
# The equivalent run for this in Leiningen does not work (test calling another test)
75+
lein tests :combination weasley.sample-test-ns2/test-4 weasley.sample-test-ns2/test-5 weasley.sample-test-ns2/test-1 > test_out.txt &&
76+
grep "Ran 12 tests containing 36 assertions." test_out.txt &&
77+
78+
lein tests :combination weasley.sample-test-ns1 > test_out.txt &&
79+
grep "Ran 0 tests containing 0 assertions." test_out.txt &&
80+
lein update-in :aliases empty -- update-in : assoc :test-selectors '{:combination :combination}' -- test weasley.sample-test-ns1 :combination > test_out.txt &&
81+
grep "Ran 0 tests containing 0 assertions." test_out.txt &&
82+
83+
# The equivalent run for this in Leiningen does not work (test calling another test)
84+
lein tests :combination weasley.sample-test-ns2/test-4 > test_out.txt &&
85+
grep "Ran 4 tests containing 12 assertions." test_out.txt &&
86+
87+
# Global fixtures tests
88+
lein tests weasley.sample-test-ns3 > test_out.txt &&
89+
grep "Ran 15 tests containing 48 assertions." test_out.txt &&
90+
91+
lein tests weasley.sample-test-ns3/test-1 > test_out.txt &&
92+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
93+
94+
lein tests weasley.sample-test-ns3/test-1 weasley.sample-test-ns3/test-2 > test_out.txt &&
95+
grep "Ran 2 tests containing 8 assertions." test_out.txt &&
96+
97+
lein tests :select-vars weasley.sample-test-ns3/test-1 weasley.sample-test-ns3/test-2 > test_out.txt &&
98+
grep "Ran 1 tests containing 4 assertions." test_out.txt &&
99+
100+
lein tests :combination weasley.sample-test-ns3 > test_out.txt &&
101+
grep "Ran 12 tests containing 36 assertions." test_out.txt &&
102+
103+
rm -f test_out.txt

0 commit comments

Comments
 (0)