<commit_before>#lang racket/base
(require racket/list racket/cmdline raco/command-name
         "main.rkt"
         "private/shared.rkt")

(module+ test
  (require rackunit racket/runtime-path racket/set))

(module+ main

  (define coverage-dir "coverage")
  (define output-format "html")
  (define exclude-paths '())
  (define include-exts '())

  (define args
     (command-line
      #:program (short-program+command-name)
      #:once-each
      [("-d" "--directory") d
       "Specify output directory. Defaults to ./coverage."
       (set! coverage-dir d)]
      [("-c" "--coverage") format
       "Specify that coverage should be run and optional what format. Defaults to html."
       (set! output-format format)]
      [("-v" "--verbose")
       "Verbose mode"
       (verbose #t)]
      [("-p" "--exclude-pkg-defaults")
        "exclude info.rkt, the tests directory, and the scribblings directory from the coverage report"
        (set! exclude-paths (append '("info.rkt" "tests" "scribblings") exclude-paths))]
      #:multi
      [("-e" "--exclude-from-output") t
       "exclude any paths named this from the coverage report."
       (set! exclude-paths (cons t exclude-paths))]
      [("-i" "--include-extentions") f
       "include these extentions in files to cover."
       (set! include-exts (cons f include-exts))]
      #:args (file . files)
      (cons file files)))
  (define files (expand-directories args include-exts))
  (define generate-coverage
    (case output-format
      [("html") generate-html-coverage]
      [("coveralls") generate-coveralls-coverage]
      [("raw") generate-raw-coverage]
      [else (error 'cover "given unknown coverage output format: ~s" output-format)]))
  (printf "generating test coverage for ~s\n" files)
  (define passed (apply test-files! files))
  (define coverage (remove-excluded-paths (get-test-coverage) exclude-paths))
  (printf "dumping coverage info into ~s\n" coverage-dir)
  (generate-coverage coverage coverage-dir)
  (exit
   (case passed
     [(#t) 0]
     [(#f) 1])))

;; TODO allow for arbitrary extensions
(define extensions '(#rx"\\.rkt$" #rx"\\.ss$"))
(define (expand-directories files [exts null])
  (define comped (map regexp exts))
  (flatten
   (for/list ([f files])
     (if (not (directory-exists? f))
         f
         (parameterize ([current-directory
                         (if (absolute-path? f)
                             f
                             (build-path (current-directory) f))])
           (expand-directory (append extensions comped)))))))

(module+ test
  (define-runtime-path root".")
  (define-runtime-path private "private")
  (define-runtime-path main.rkt "main.rkt")
  (parameterize ([current-directory root])
    (check-equal? (list->set
                   (map (compose path->string ->relative)
                        (expand-directories (list (path->string main.rkt)
                                                  (->relative (path->string private))))))
                  (set "main.rkt"
                       "private/coveralls.rkt"
                       "private/contracts.rkt"
                       "private/html.rkt"
                       "private/format-utils.rkt"
                       "private/shared.rkt"<commit_msg>removed vestage of better-test (exit code now only reflects internal errors)<commit_after>#lang racket/base
(require racket/list racket/cmdline raco/command-name
         "main.rkt"
         "private/shared.rkt")

(module+ test
  (require rackunit racket/runtime-path racket/set))

(module+ main

  (define coverage-dir "coverage")
  (define output-format "html")
  (define exclude-paths '())
  (define include-exts '())

  (define args
     (command-line
      #:program (short-program+command-name)
      #:once-each
      [("-d" "--directory") d
       "Specify output directory. Defaults to ./coverage."
       (set! coverage-dir d)]
      [("-c" "--coverage") format
       "Specify that coverage should be run and optional what format. Defaults to html."
       (set! output-format format)]
      [("-v" "--verbose")
       "Verbose mode"
       (verbose #t)]
      [("-p" "--exclude-pkg-defaults")
        "exclude info.rkt, the tests directory, and the scribblings directory from the coverage report"
        (set! exclude-paths (append '("info.rkt" "tests" "scribblings") exclude-paths))]
      #:multi
      [("-e" "--exclude-from-output") t
       "exclude any paths named this from the coverage report."
       (set! exclude-paths (cons t exclude-paths))]
      [("-i" "--include-extentions") f
       "include these extentions in files to cover."
       (set! include-exts (cons f include-exts))]
      #:args (file . files)
      (cons file files)))
  (define files (expand-directories args include-exts))
  (define generate-coverage
    (case output-format
      [("html") generate-html-coverage]
      [("coveralls") generate-coveralls-coverage]
      [("raw") generate-raw-coverage]
      [else (error 'cover "given unknown coverage output format: ~s" output-format)]))
  (printf "generating test coverage for ~s\n" files)
  (define passed (apply test-files! files))
  (define coverage (remove-excluded-paths (get-test-coverage) exclude-paths))
  (printf "dumping coverage info into ~s\n" coverage-dir)
  (generate-coverage coverage coverage-dir)
  (unless passed
    (printf "some tests failed\n")))

;; TODO allow for arbitrary extensions
(define extensions '(#rx"\\.rkt$" #rx"\\.ss$"))
(define (expand-directories files [exts null])
  (define comped (map regexp exts))
  (flatten
   (for/list ([f files])
     (if (not (directory-exists? f))
         f
         (parameterize ([current-directory
                         (if (absolute-path? f)
                             f
                             (build-path (current-directory) f))])
           (expand-directory (append extensions comped)))))))

(module+ test
  (define-runtime-path root".")
  (define-runtime-path private "private")
  (define-runtime-path main.rkt "main.rkt")
  (parameterize ([current-directory root])
    (check-equal? (list->set
                   (map (compose path->string ->relative)
                        (expand-directories (list (path->string main.rkt)
                                                  (->relative (path->string private))))))
                  (set "main.rkt"
                       "private/coveralls.rkt"
                       "private/contracts.rkt"
                       "private/html.rkt"
                       "private/format-utils.rkt"
                       "private/shared.rkt"
{'fraction_non_alphanumeric': 0.14102954614681693, 'fraction_numerical': 0.0003045994517209869, 'mean_word_length': 2.2590570719602976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7158679', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1896, 'n_words': 534}