Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: joeyates/sloccount-clojure
base: aaee517a33
...
head fork: joeyates/sloccount-clojure
compare: 125b2fee8b
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 15, 2014
@joeyates Start isolating Java stuff
Make the code testable (and mockable).
9f4edd6
@joeyates Start adding midje tests 125b2fe
View
1  project.clj
@@ -4,4 +4,5 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
+ :profiles {:dev {:dependencies [[midje "1.5.1"]]}}
:main sloccount.core)
View
52 src/sloccount/files.clj
@@ -1,30 +1,39 @@
(ns sloccount.files
- (:use [clojure.java.io :only (reader)])
- (:import (java.io.File)))
+ (:require [clojure.java.io]))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Java stuff
+
+(defn filenames [path]
+ (map
+ #(.toString %)
+ (filter
+ #(.isFile %)
+ (file-seq (clojure.java.io/file (.toString path))))))
+
+(defn file-empty? [file]
+ (= (.length (clojure.java.io/file (.toString file))) 0))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; File selection
-(defn version-control? [file]
- (re-find #"\W(\.git|\.svn)\W" (.toString file)))
-(defn settings? [file]
- (re-find #"/(\.htaccess|\.gitignore)$" (.toString file)))
-(defn binary? [file]
- (re-find #"\.(doc|dot|exe|gif|jpe?g|ods|odt|ott|png|ttf|xls)$" (.toString file)))
-(defn source-file? [file]
+(defn version-control? [filename]
+ (re-find #"(^|/)(\.git|\.svn)/" filename))
+(defn settings? [filename]
+ (re-find #"/(\.htaccess|\.gitignore)$" filename))
+(defn binary? [filename]
+ (re-find #"\.(doc|dot|exe|gif|jpe?g|ods|odt|ott|png|ttf|xls)$" filename))
+(defn source-file? [filename]
(cond
- (version-control? file) false
- (settings? file) false
- (binary? file) false
- true true))
-
-(defn files [path]
- (filter
- #(.isFile %)
- (file-seq (java.io.File. (.toString path)))))
+ (version-control? filename) false
+ (settings? filename) false
+ (binary? filename) false
+ true true))
(defn source-files [path]
(filter
source-file?
- (files path)))
+ (filenames path)))
;; File type inference
(defn clojure-file-name? [filename] (.endsWith filename ".clj"))
@@ -69,14 +78,11 @@
false)))
(defn file-type-from-contents [file]
- (with-open [rdr (reader file)]
+ (with-open [rdr (clojure.java.io/reader file)]
(or
(is-shebang? rdr)
:unknown)))
-(defn file-empty? [file]
- (= (.length (java.io.File. (.toString file))) 0))
-
(defn file-type [file]
(let [filename (.toString file)]
(or
View
7 test/sloccount/core_test.clj
@@ -1,7 +0,0 @@
-(ns sloccount.core-test
- (:require [clojure.test :refer :all]
- [sloccount.core :refer :all]))
-
-(deftest a-test
- (testing "FIXME, I fail."
- (is (= 0 1))))
View
20 test/sloccount/files_test.clj
@@ -0,0 +1,20 @@
+(ns sloccount.files-test
+ (:use midje.sweet)
+ (:require [sloccount.files :as files]))
+
+(facts "about `source-files`"
+ (fact "it returns files in the path"
+ (files/source-files "path") => ["foo"]
+ (provided (files/filenames "path") => ["foo"]))
+
+ (fact "it excludes files in the .git directory"
+ (files/source-files "path") => ["foo"]
+ (provided (files/filenames "path") => [".git/bar" "/.git/baz" "foo"]))
+
+ (fact "it excludes .gitignore"
+ (files/source-files "path") => ["foo"]
+ (provided (files/filenames "path") => [".git/bar" "foo"]))
+
+ (fact "it excludes binary files"
+ (files/source-files "path") => ["foo"]
+ (provided (files/filenames "path") => ["text.doc" "foo"])))

No commit comments for this range

Something went wrong with that request. Please try again.