From 3836db19028d60ffd18fe7b3de283f80d3438e5a Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Sun, 28 Dec 2014 23:52:19 -0600 Subject: [PATCH] added rudementary coveralls support --- README.md | 8 ++++++-- curl.sh | 5 +++++ format.rkt | 17 +++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100755 curl.sh diff --git a/README.md b/README.md index 81f955f..945fde3 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,16 @@ This library is a replacement for rackets `raco test` that has a few benefits. N install via `raco pkg install better-test`. To install for development, checkout the repo into a folder named `Better Test` and in the parent directory run `raco pkg install better-test/`. +If you're doing developement remember: better-test *cannot* run on itself. + ## How to use To view the arguments for Better Test run `raco better-test -h`. Code coverage can be generated by specifying the `-c ` flag. -Right now the valid formats are: html. Coveralls support is comming. +Right now the valid formats are: html and coveralls. +Using coveralls requires the "COVERALLS_REPO_TOKEN" to be set, and needs bash and curl. +Travic-ci/Coveralls support coming soon... The directory that the coverage is outputted to can be specified with the `-d` flag. If any tests run by `rackunit` fail, Better Test will return with exit code `1`. If all tests pass it will return with exit code `0`. @@ -19,4 +23,4 @@ If any tests run by `rackunit` fail, Better Test will return with exit code `1`. ## Internals -Better Test also comes with a racket API for running tests and generating coverage reports. Documentation comming soon... +Better Test also comes with a racket API for running tests and generating coverage reports. Documentation coming soon... diff --git a/curl.sh b/curl.sh new file mode 100755 index 0000000..6cf1c20 --- /dev/null +++ b/curl.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +file=$1 + +curl -v --include --form json_file=@"$file" "https://coveralls.io/api/v1/jobs" diff --git a/format.rkt b/format.rkt index 3ab9503..b825524 100644 --- a/format.rkt +++ b/format.rkt @@ -3,6 +3,7 @@ (require syntax/modread syntax/parse unstable/sequence + racket/runtime-path json syntax-color/racket-lexer (only-in xml write-xexpr)) @@ -175,21 +176,29 @@ ;; Coveralls ;; Coverage [Hasheq String String] [path-string] -> Void +(define-runtime-path post "curl.sh") (define (generate-coveralls-coverage coverage meta [dir "coverage"]) (make-directory* dir) (define coverage-path (path->string (build-path (current-directory) dir))) - (with-output-to-file (string-append coverage-path "/coverage.json") - (λ () (write-json (generate-coveralls-json coverage meta))) - #:exists 'replace)) + (define coverage-file (string-append coverage-path "/coverage.json")) + (define json (generate-coveralls-json coverage meta)) + (define token (or (getenv "COVERALLS_REPO_TOKEN") "")) + (with-output-to-file coverage-file + (λ () (write-json (hash-set (hash-set json 'repo_token token) + 'service_name + "better-test"))) + #:exists 'replace) + (system* (path->string post) coverage-file)) ;; Coverage [Hasheq String String] -> JSexpr ;; Generates a string that represents a valid coveralls json_file object (define (generate-coveralls-json coverage meta) (define src-files (for/list ([file (hash-keys coverage)]) + (define local-file (path->string (find-relative-path (current-directory) file))) (define src (file->string file)) (define c (line-coverage coverage file)) - (hasheq 'src src 'coverage c))) + (hasheq 'source src 'coverage c 'name local-file))) (hash-set meta 'source_files src-files)) ;; CoverallsCoverage = Nat | json-null