Skip to content

Commit

Permalink
[nop] Update tests template, add GraalVM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jul 26, 2023
1 parent 6dc9df0 commit fde7790
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/graal-tests.yml
@@ -0,0 +1,32 @@
name: Graal tests
on: [push, pull_request]

jobs:
test:
strategy:
matrix:
java: ['17']
os: [ubuntu-latest, macOS-latest, windows-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
with:
version: 'latest'
java-version: ${{ matrix.java }}
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: DeLaGuardo/setup-clojure@10.0
with:
lein: latest
bb: latest

- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: deps-${{ hashFiles('deps.edn') }}
restore-keys: deps-

- run: bb graal-tests
30 changes: 30 additions & 0 deletions .github/workflows/main-tests.yml
@@ -0,0 +1,30 @@
name: Main tests
on: [push, pull_request]

jobs:
tests:
strategy:
matrix:
java: ['17', '18', '19']
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: ${{ matrix.java }}

- uses: DeLaGuardo/setup-clojure@10.0
with:
lein: latest

- uses: actions/cache@v3
id: cache-deps
with:
path: ~/.m2/repository
key: deps-${{ hashFiles('project.clj') }}
restore-keys: deps-

- run: lein test-all
10 changes: 10 additions & 0 deletions bb.edn
@@ -0,0 +1,10 @@
{:paths ["bb"]
:tasks
{:requires ([graal-tests])
graal-tests
{:doc "Run Graal native-image tests"
:task
(do
(graal-tests/uberjar)
(graal-tests/native-image)
(graal-tests/run-tests))}}}
36 changes: 36 additions & 0 deletions bb/graal_tests.clj
@@ -0,0 +1,36 @@
#!/usr/bin/env bb

(ns graal-tests
(:require
[clojure.string :as str]
[babashka.fs :as fs]
[babashka.process :refer [shell]]))

(defn uberjar []
(let [command "lein with-profiles +graal-tests uberjar"
command
(if (fs/windows?)
(if (fs/which "lein")
command
;; Assume PowerShell powershell module
(str "powershell.exe -command " (pr-str command)))
command)]

(shell command)))

(defn executable [dir name]
(-> (fs/glob dir (if (fs/windows?) (str name ".{exe,bat,cmd}") name))
first
fs/canonicalize
str))

(defn native-image []
(let [graalvm-home (System/getenv "GRAALVM_HOME")
bin-dir (str (fs/file graalvm-home "bin"))]
(shell (executable bin-dir "gu") "install" "native-image")
(shell (executable bin-dir "native-image") "-jar" "target/graal-tests.jar" "--no-fallback" "graal_tests")))

(defn run-tests []
(let [{:keys [out]} (shell {:out :string} (executable "." "graal_tests"))]
(assert (str/includes? out "loaded") out)
(println "Native image works!")))
7 changes: 7 additions & 0 deletions project.clj
Expand Up @@ -36,6 +36,13 @@
[[lein-expectations "0.0.8"]
[lein-autoexpect "1.4.2"]]}

:graal-tests
{:dependencies [[org.clojure/clojure "1.11.1"]
[com.github.clj-easy/graal-build-time "0.1.4"]]
:main taoensso.graal-tests
:aot [taoensso.graal-tests]
:uberjar-name "graal-tests.jar"}

:dev
[:c1.11 :test
{:jvm-opts ["-server"]
Expand Down
5 changes: 5 additions & 0 deletions test/taoensso/graal_tests.clj
@@ -0,0 +1,5 @@
(ns taoensso.graal-tests
(:require [taoensso.tower :as tower])
(:gen-class))

(defn -main [& args] (println "Namespace loaded successfully"))
@@ -1,9 +1,9 @@
(ns taoensso.tower.tests.main
(ns taoensso.tower-tests
(:require [expectations :as test :refer :all]
[taoensso.tower :as tower :refer (with-tscope)])
(:import [java.util Date]))

(comment (test/run-tests '[taoensso.tower.tests.main]))
(comment (test/run-tests '[taoensso.tower-tests]))

(defn- before-run {:expectations-options :before-run} [])
(defn- after-run {:expectations-options :after-run} [])
Expand Down

0 comments on commit fde7790

Please sign in to comment.