Last active
          January 13, 2025 13:24 
        
      - 
      
- 
        Save thiagokokada/fee513a7b8578c87c05469267c48e612 to your computer and use it in GitHub Desktop. 
    Babashka's test runner that dynamically discover the tests
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | #!/usr/bin/env bb | |
| ;; Inspired from https://book.babashka.org/#_running_tests | |
| (require '[clojure.test :as t] | |
| '[clojure.string :as string] | |
| '[babashka.classpath :as cp] | |
| '[babashka.fs :as fs]) | |
| (cp/add-classpath "src:test") | |
| (defn test-file->test-ns | |
| [file] | |
| (as-> file $ | |
| (fs/components $) | |
| (drop 1 $) | |
| (mapv str $) | |
| (string/join "." $) | |
| (string/replace $ #"_" "-") | |
| (string/replace $ #".clj$" "") | |
| (symbol $))) | |
| (def test-namespaces | |
| (->> (fs/glob "test" "**/*_test.clj") | |
| (mapv test-file->test-ns))) | |
| (apply require test-namespaces) | |
| (def test-results | |
| (apply t/run-tests test-namespaces)) | |
| (def failures-and-errors | |
| (let [{:keys [:fail :error]} test-results] | |
| (+ fail error))) | |
| (System/exit failures-and-errors) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
https://blog.michielborkent.nl/babashka-test-runner.html
^ this works nicely for me