# HG changeset patch # User alys # Date 2018-10-11 05:33:00 # Node ID 676f2fad6ede9d8b3c27a5ac5a92c0ecfd07b2aa # Parent 3f636ffe886db47b560c50198a087b174dba3ad3 Add property-based testing (and fix a bug). diff --git a/project.clj b/project.clj --- a/project.clj +++ b/project.clj @@ -6,7 +6,8 @@ :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.9.521"] ; [andare "0.9.0"] - [org.clojure/core.async "0.4.474"]] + [org.clojure/core.async "0.4.474"] + [org.clojure/test.check "0.10.0-alpha3"]] :plugins [[lein-cljsbuild "1.1.5"]] diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj --- a/src/project_checkup/core.clj +++ b/src/project_checkup/core.clj @@ -4,7 +4,11 @@ (:require [clojure.java.shell :as shell] [clojure.string :as string])) -(defn get-extension [path] (re-find #"\.[a-zA-Z]+$" path)) +(defn get-extension [path] + "Extracts the extension of a path. + Returns the extension with the period, e.g., '.txt' because that's the format + people are used to seeing extensions in." + (re-find #"\.[a-zA-Z0-9]+$" path)) (defn gather-project-info "Creates a dictionary of project information" diff --git a/test/project_checkup/core_property_test.clj b/test/project_checkup/core_property_test.clj new file mode 100644 --- /dev/null +++ b/test/project_checkup/core_property_test.clj @@ -0,0 +1,27 @@ +(ns project-checkup.core-property-test + (:gen-class) + (:require [clojure.test :refer :all] + [project-checkup.core :refer :all] + [clojure.test.check :as tc] + [clojure.test.check.generators :as gen] + [clojure.test.check.properties :as prop] + [clojure.test.check.clojure-test :refer :all])) + + +;arguably redundant +(defspec get-extension-returns-string + 100 + (prop/for-all [st (gen/not-empty gen/string-ascii) + ext (gen/not-empty gen/string-alphanumeric) ] + (string? (get-extension (str st \. ext ))) )) + + +(defspec get-extension-returns-extension + 100 + (prop/for-all [st (gen/not-empty gen/string-ascii) + ext (gen/not-empty gen/string-alphanumeric) ] + (= (get-extension (str st \. ext )) + (str \. ext)) )) + + + diff --git a/test/project_checkup/core_test.clj b/test/project_checkup/core_test.clj --- a/test/project_checkup/core_test.clj +++ b/test/project_checkup/core_test.clj @@ -39,6 +39,4 @@ (is (= (get-extension "test.txt") ".txt")) (is (= (get-extension "./test.txt") ".txt")) (is (= (get-extension "test.txt.bak") ".bak")) - (is (= (get-extension ".hg/test.txt.bak") ".bak")) - ) - ) + (is (= (get-extension ".hg/test.txt.bak") ".bak"))))