Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d16d661
Very basic suggestion function based on spec
bhb Feb 15, 2018
53c5730
Try to replace suggested values with more recognizable values
bhb Feb 16, 2018
dc13f73
Adds simplification algorithm, refactors
bhb Feb 17, 2018
5287552
Cleanup
bhb Feb 17, 2018
d592a1c
Try several options, pick highest score
bhb Feb 18, 2018
b144288
Change algorithm to handle multiple problems in the same bad data
bhb Feb 19, 2018
7ff32e4
Add tool for flame graphs
bhb Feb 28, 2018
45e2ecf
Reduce number of values for exercise, since that takes lots of time
bhb Feb 28, 2018
960bdd7
Fixes CLJS tests
bhb Feb 28, 2018
69c26e1
Merge branch 'master' into gen-code2
bhb Feb 28, 2018
1787be6
Bump number to 8
bhb Feb 28, 2018
f560ae1
Reliably generate values for sets
bhb Mar 5, 2018
d3c7917
Score based on suggestion type
bhb Mar 5, 2018
220f5ae
Don't eval every suggestion, add example values that may match regex
bhb Mar 6, 2018
c856abe
Fixes formatting
bhb Mar 6, 2018
88f73b9
Adds fixed seed
bhb Mar 6, 2018
c44c0ae
Update jar contents
bhb Mar 6, 2018
4a99679
Reduce number of samples, add check for 'good enough' score
bhb Mar 8, 2018
0822b48
Use reusable cache
bhb Mar 8, 2018
23fcc6c
Add suggestions for deleting elements
bhb Mar 8, 2018
55a8f7b
Fixes bugs and reduces number of wrong args in test
bhb Mar 8, 2018
9c5ef58
Insert elements
bhb Mar 8, 2018
9f96d49
Adds rounds of simplification
bhb Mar 14, 2018
aa622d7
Wrap or unwrap collections
bhb Mar 14, 2018
459c434
Avoid creating symbols that contain whitespace
bhb Mar 16, 2018
c59317a
Fixes suggestion for defn
bhb Mar 16, 2018
f7d63bf
Adds tests
bhb Mar 16, 2018
5c18fb6
Adds support for swapping elements
bhb Mar 17, 2018
37abbc6
Adds tests
bhb Mar 17, 2018
01b1b0b
Perf improvements
bhb Mar 19, 2018
0c417a7
Updates jar contents
bhb Mar 19, 2018
ac2d29b
Update jar contents again
bhb Mar 19, 2018
7db4f17
Print suggestion during instrumentation or macroexpansion
bhb Mar 21, 2018
0fabec0
Fix cljs tests
bhb Mar 23, 2018
c1b4e6f
Use sorted-map
bhb Mar 23, 2018
13c97f9
Fixes 'lein check' by compiling java first
bhb Mar 23, 2018
50a23d6
Updates expected file in package
bhb Mar 23, 2018
fb2da49
Merge branch 'master' into gen-code2
bhb May 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:

- run: bin/install-chrome
- run: sudo bin/install-node && npm install
- run: lein check
- run: lein with-profile test-common javac && lein check
- run: lein with-profile test-common test
- run: lein clean && lein with-profile test-web cljsbuild once test && bin/tests
- run: lein jar && diff -u <(jar tf target/*.jar | sort) <(cat expected-jar-contents.txt | sort)
Expand Down
11 changes: 11 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ or

`lein with-profile +test-common test-refresh :changes-only`

## Profiling in the REPL

```
(comment
(require '[clj-async-profiler.core :as prof])
(do
(prof/start {})
;; some expensive operation here
(prof/stop {}))
)

## Release

### clojars
Expand Down
8 changes: 8 additions & 0 deletions expected-jar-contents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ expound/alpha.cljc
expound/problems.cljc
expound/printer.cljc
expound/specs.cljc
expound/suggest.cljc
expound/java/
expound/java/Util.java
expound/java/Util.class
expound/js/
expound/js/util.js
Util.class
Util.java
project.clj
expound/ansi.cljc
7 changes: 6 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
[org.clojure/spec.alpha "0.1.143" :scope "provided"]]
:deploy-repositories [["releases" :clojars]]
:jar-exclusions [#"^public/.*"]
:java-source-paths ["src/expound/java"]
:plugins [[com.jakemccrary/lein-test-refresh "0.22.0"]
[lein-cljfmt "0.5.7"]
[lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]
[lein-figwheel "0.5.15"]]


:cljsbuild {:builds
[{:id "test"
:source-paths ["src" "test"]
Expand All @@ -26,7 +28,9 @@
:main "expound.test-runner"
:optimizations :none
:verbose true
:compiler-stats true}}]}
:compiler-stats true
:libs ["src/expound/js/util.js"]
}}]}
:figwheel {;; :http-server-root "public" ;; default and assumes "resources"
:server-port 3446 ;; default is 3449

Expand Down Expand Up @@ -78,6 +82,7 @@
[io.aviso/pretty "0.1.34"]
[vvvvalvalval/scope-capture "0.1.4"]
[org.clojure/test.check "0.9.0"]
[com.clojure-goes-fast/clj-async-profiler "0.1.2"]
[metosin/spec-tools "0.6.1"]]
:plugins [[io.aviso/pretty "0.1.34"]]
;; need to add dev source path here to get user.clj loaded
Expand Down
19 changes: 17 additions & 2 deletions src/expound/alpha.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#?(:cljs [goog.string])
[expound.printer :as printer]
[expound.util :as util]
[expound.ansi :as ansi]))
[expound.ansi :as ansi]
[expound.suggest :as suggest]))

;;;;;; registry ;;;;;;

Expand Down Expand Up @@ -617,7 +618,7 @@ returned an invalid value.
(str
(ansi/color (instrumentation-info failure caller) :none)
(printer/format
"%s%s
"%s%s%s
%s %s %s\n"
(apply str
(for [[[in type] probs] problems]
Expand All @@ -630,6 +631,20 @@ returned an invalid value.
(if (empty? s)
s
(str s "\n\n"))))))
;; FIXME - this is not a very clear heuristic, but until
;; https://dev.clojure.org/jira/browse/CLJ-2271 is fixed, I think it's the best we can do
(if (::s/args explain-data')
(str
(header-label "Example")
"\n\n"
(printer/indent (str (conj
(suggest/suggestion (::s/spec explain-data') (::s/value explain-data'))
;; FIXME - when https://dev.clojure.org/jira/browse/CLJ-2218 and
;; https://dev.clojure.org/jira/browse/CLJ-2271 are fixed and explain-data
;; contains the name of the function, use it here
(symbol "<f>"))))
"\n\n")
"")
(ansi/color (section-label) :footer)
(ansi/color "Detected" :footer)
(ansi/color (count problems) :footer)
Expand Down
20 changes: 20 additions & 0 deletions src/expound/java/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package expound.java;

public class Util {

public static int distance(String a, String b) {
int [] costs = new int [b.length() + 1];
for (int j = 0; j < costs.length; j++)
costs[j] = j;
for (int i = 1; i <= a.length(); i++) {
costs[0] = i;
int nw = i - 1;
for (int j = 1; j <= b.length(); j++) {
int cj = Math.min(1 + Math.min(costs[j], costs[j - 1]), a.charAt(i - 1) == b.charAt(j - 1) ? nw : nw + 1);
nw = costs[j];
costs[j] = cj;
}
}
return costs[b.length()];
}
}
15 changes: 15 additions & 0 deletions src/expound/js/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
goog.provide("expound.js.util")

expound.js.util.hello = function() { return "hi";}

expound.js.util.levenshtein = function levenshtein(a, b) {
var t = [], u, i, j, m = a.length, n = b.length;
if (!m) { return n; }
if (!n) { return m; }
for (j = 0; j <= n; j++) { t[j] = j; }
for (i = 1; i <= m; i++) {
for (u = [i], j = 1; j <= n; j++) {
u[j] = a[i - 1] === b[j - 1] ? t[j - 1] : Math.min(t[j - 1], t[j], u[j - 1]) + 1;
} t = u;
} return u[n];
}
65 changes: 44 additions & 21 deletions src/expound/problems.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
(assoc k (summary-form show-valid-values? (nth form k) rst))))

(and (int? k) (set? form))
(into #{} (-> displayed-form
vec
(assoc k (summary-form show-valid-values? (nth (seq form) k) rst))))
(set (-> displayed-form
vec
(assoc k (summary-form show-valid-values? (nth (seq form) k) rst))))

(and (int? k) (list? form))
(into '() (-> displayed-form
Expand Down Expand Up @@ -122,24 +122,26 @@
problems)))

(defn annotate [explain-data]
(let [{:keys [::s/problems ::s/value ::s/args ::s/ret ::s/fn ::s/failure ::s/spec]} explain-data
caller (or (:clojure.spec.test.alpha/caller explain-data) (:orchestra.spec.test/caller explain-data))
form (if (not= :instrument failure)
value
(cond
(contains? explain-data ::s/ret) ret
(contains? explain-data ::s/fn) fn
(contains? explain-data ::s/args) args))
problems' (map (comp (partial adjust-in form)
(partial adjust-path failure)
(partial add-spec spec)
(partial fix-via spec)
#(assoc % :expound/form form))
problems)]
(assoc explain-data
:expound/form form
:expound/caller caller
:expound/problems problems')))
(if (nil? explain-data)
nil
(let [{:keys [::s/problems ::s/value ::s/args ::s/ret ::s/fn ::s/failure ::s/spec]} explain-data
caller (or (:clojure.spec.test.alpha/caller explain-data) (:orchestra.spec.test/caller explain-data))
form (if (not= :instrument failure)
value
(cond
(contains? explain-data ::s/ret) ret
(contains? explain-data ::s/fn) fn
(contains? explain-data ::s/args) args))
problems' (map (comp (partial adjust-in form)
(partial adjust-path failure)
(partial add-spec spec)
(partial fix-via spec)
#(assoc % :expound/form form))
problems)]
(assoc explain-data
:expound/form form
:expound/caller caller
:expound/problems problems'))))

(defn value-in
"Similar to get-in, but works with paths that reference map keys"
Expand All @@ -161,6 +163,27 @@
(and (int? k) (seqable? form))
(recur (nth (seq form) k) rst))))

;; TODO - deduple with value-in??
;; TODO - rename
(defn assoc-in1 [form in value]
(let [[k & rst] in]
(cond
(empty? in)
value

(and (map? form) (paths/kps? k))
(assoc form (:key k) value)

;; TODO - make this work
;;(and (map? form) (paths/kvps? k))
;;(recur (nth (seq form) (:idx k)) rst)

(associative? form)
(assoc form k (assoc-in1 (get form k) rst value))

(and (int? k) (seq? form))
(list* (assoc (vec form) k (assoc-in1 (nth (seq form) k) rst value))))))

(defn escape-replacement [pattern s]
#?(:clj (if (string? pattern)
s
Expand Down
Loading