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 620eba4 commit 074f6c1
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/graal-tests.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tests
name: Main tests
on: [push, pull_request]

jobs:
Expand All @@ -25,5 +25,6 @@ jobs:
with:
path: ~/.m2/repository
key: deps-${{ hashFiles('project.clj') }}
restore-keys: deps-

- run: lein test-all
10 changes: 10 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
:dependencies
[[org.clojure/test.check "1.1.1"]]}

: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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns taoensso.graal-tests
(:require [taoensso.tempura :as tempura])
(:gen-class))

(defn -main [& args] (println "Namespace loaded successfully"))

0 comments on commit 074f6c1

Please sign in to comment.