Skip to content

Instantly share code, notes, and snippets.

@ghaskins
Created May 14, 2018 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghaskins/11857fef7dfc8e56dc90d422d11ceb9a to your computer and use it in GitHub Desktop.
Save ghaskins/11857fef7dfc8e56dc90d422d11ceb9a to your computer and use it in GitHub Desktop.
(ns protoc-gen-clojure.core-test
(:require [clojure.test :refer :all]
[clojure.java.io :as io]
[clojure.pprint :refer :all]
[clojure.tools.namespace :as namespace]
[me.raynes.fs :as fs]
[protoc-gen-clojure.main :as main]
[protoc-gen-clojure.core :refer :all])
(:import [java.io ByteArrayOutputStream]))
(deftest io-test
(testing "Drive a sample request through plugin IO"
(let [in (io/input-stream (io/resource "testdata/sample.request"))
out (ByteArrayOutputStream.)]
(main/execute in out))))
(do
(let [{:keys [file]} (-> (io/resource "testdata/sample.request")
io/input-stream
main/decode-request
generate)
dir (io/file "target/test")]
;; Ensure we start fresh
(fs/delete-dir dir)
;; Write the file(s) to our temp-dir
(doseq [{:keys [name content]} file]
(let [h (io/file dir name)
parent (.getParent h)]
(fs/mkdirs parent)
(spit h content)))
(require '[com.example.tutorial.sample :as sample] :reload-all)))
(deftest compile-test
(testing "Generate and then compile our sample"
(pprint (sample/map->Person {:name "Test User" :id 42 :email "tester@acme.com"}))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment