-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
303b8ce
commit 130d9d5
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
name: Run generative tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
schedule: | ||
- cron: "0 0 1 * *" # every month | ||
|
||
jobs: | ||
gen-tests: | ||
name: Run generative tests | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup latest Java | ||
uses: actions/setup-java@v3.11.0 | ||
with: | ||
distribution: zulu | ||
java-version: 21 | ||
- name: Setup Clojure | ||
uses: DeLaGuardo/setup-clojure@bc7570e912b028bbcc22f457adec7fdf98e2f4ed # 12.5 | ||
with: | ||
cli: 1.10.1.693 | ||
- name: Run tests | ||
run: CLOJURE=clojure-11 bin/run-gen-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env bash | ||
# Should work if the env var is empty | ||
clojure -A:"$CLOJURE" -M:test -m kaocha.runner "$@" | ||
clojure -A:"$CLOJURE" -M:test -m kaocha.runner --skip-meta :generative "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
# Should work if the env var is empty | ||
clojure -A:"$CLOJURE" -M:test -m kaocha.runner --focus oksa.generator-test "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns ^:generative oksa.generator-test | ||
(:require [#?(:clj clojure.test | ||
:cljs cljs.test) :as t] | ||
[malli.generator :as mg] | ||
[malli.core :as m] | ||
[oksa.parse] | ||
[oksa.test-util :refer [unparse-and-validate]])) | ||
|
||
#?(:bb nil | ||
:clj (require '[kaocha.config] | ||
'[kaocha.testable])) | ||
|
||
(def document-schema (oksa.parse/-graphql-dsl-lang {:oksa/strict true} :oksa.parse/Document)) | ||
(def document-parser (m/parser document-schema)) | ||
|
||
#?(:bb nil | ||
:clj (t/deftest generator-test | ||
(let [seed (or (:kaocha.plugin.randomize/seed kaocha.testable/*config*) | ||
(.nextLong (java.util.Random.))) | ||
samples (loop [seed seed | ||
samples nil | ||
tries 10] | ||
(cond (some? samples) samples | ||
(zero? tries) (throw (ex-info "could not generate examples" {})) | ||
:else (recur | ||
(inc seed) | ||
(try (mg/generate document-schema {:size 10 :seed seed}) | ||
(catch Exception _ nil)) | ||
(dec tries))))] | ||
(prn ::seed seed) | ||
(doseq [sample samples] | ||
(t/is (true? (or (= :malli.core/invalid (document-parser sample)) | ||
(string? (try (unparse-and-validate sample) | ||
(catch Throwable e | ||
(prn (ex-info "invalid sample" {:sample sample} e)) | ||
nil)))))))))) |