test-mcfly-tools.rkt
#lang racket/base
;; For legal info, see file "info.rkt".

(require racket/file
         (planet neil/overeasy)
         "mcfly-tools.rkt")

(test-section 'mcfly-tools

  (test-section 'update-info-file

    (define (%test-inforkt-update #:inforkt-contents contents-str)
      (let ((dir "temporary-test-inforkt-dir"))
        (dynamic-wind
          void
          (lambda ()
            (with-handlers ((exn:fail? void))
              (delete-directory/files dir))
            (make-directory dir)
            (parameterize ((current-directory dir))
              (let ((info-file "info.rkt"))

                (display-to-file contents-str info-file)
                (update-info-file info-file)
                (let ((first-lines (file->lines info-file)))
                  (update-info-file info-file)
                  (let ((second-lines (file->lines info-file)))
                    (if (equal? first-lines second-lines)
                        second-lines
                        (error '%test-inforkt-update
                               "file-changed between updates: ~S ~S"
                               first-lines
                               second-lines)))))))
          (lambda ()
            (with-handlers ((exn:fail? void))
              (delete-directory/files dir))))))

    (test 'empty-file
          (%test-inforkt-update
           #:inforkt-contents "")
          '("#lang setup/infotab"
            ""
            ""
            ";; TODO: Add the PLaneT owner and package name, and double-check the version:"
            "(define mcfly-planet       '!!!/!!!:1:0)"
            ""
            ";; TODO: Add the name of the package (may be capitalized and have spaces):"
            "(define name               \"!!!\")"
            ""
            ";; TODO: Add the subtitle string, or define \"mcfly-title\" instead:"
            "(define mcfly-subtitle     \"!!!\")"
            ""
            "(define blurb              (list name \": \" mcfly-subtitle))"
            ""
            ";; TODO: Add the Web home page URL for this package:"
            "(define homepage           \"http://!!!\")"
            ""
            ";; TODO: Add the author(s):"
            "(define mcfly-author       \"!!!\")"
            ""
            "(define repositories       '(\"4.x\"))"
            ""
            "(define categories         '(misc))"
            ""
            ";; TODO: See http://doc.racket-lang.org/search/index.html?q=can-be-loaded-with"
            "(define can-be-loaded-with 'all)"
            ""
            "(define scribblings        '((\"doc.scrbl\" () (library))))"
            ""
            ";; TODO: Double-check this:"
            "(define primary-file       \"main.rkt\")"
            ""
            ";; TODO: Set this to the file that has starting \"doc\" forms:"
            "(define mcfly-start        \"main.rkt\")"
            ""
            ";; TODO: Double-check that this includes all files for the PLaneT package:"
            "(define mcfly-files        '(defaults))"
            ""
            ";; TODO: Add short name for license (e.g., \"LGPLv3\"). See http://www.gnu.org/licenses/"
            "(define mcfly-license      \"!!!\")"
            ""
            ";; TODO: Add copyright, license, disclaimers, and other legal information."
            "(define mcfly-legal        \"Copyright !!!\")")
          #:out #"raco mcfly: Modifying \"info.rkt\"...\n")

    (test 'pound-lang
          (%test-inforkt-update
           #:inforkt-contents "#lang setup/infotab\n(define name 'foo)\n\n(define blurb \"yo\")\n")
          '("#lang setup/infotab"
            "(define name 'foo)"
            ""
            "(define blurb \"yo\")"
            ""
            ";; TODO: Add the PLaneT owner and package name, and double-check the version:"
            "(define mcfly-planet       '!!!/!!!:1:0)"
            ""
            ";; TODO: Add the subtitle string, or define \"mcfly-title\" instead:"
            "(define mcfly-subtitle     \"!!!\")"
            ""
            ";; TODO: Add the Web home page URL for this package:"
            "(define homepage           \"http://!!!\")"
            ""
            ";; TODO: Add the author(s):"
            "(define mcfly-author       \"!!!\")"
            ""
            "(define repositories       '(\"4.x\"))"
            ""
            "(define categories         '(misc))"
            ""
            ";; TODO: See http://doc.racket-lang.org/search/index.html?q=can-be-loaded-with"
            "(define can-be-loaded-with 'all)"
            ""
            "(define scribblings        '((\"doc.scrbl\" () (library))))"
            ""
            ";; TODO: Double-check this:"
            "(define primary-file       \"main.rkt\")"
            ""
            ";; TODO: Set this to the file that has starting \"doc\" forms:"
            "(define mcfly-start        \"main.rkt\")"
            ""
            ";; TODO: Double-check that this includes all files for the PLaneT package:"
            "(define mcfly-files        '(defaults))"
            ""
            ";; TODO: Add short name for license (e.g., \"LGPLv3\"). See http://www.gnu.org/licenses/"
            "(define mcfly-license      \"!!!\")"
            ""
            ";; TODO: Add copyright, license, disclaimers, and other legal information."
            "(define mcfly-legal        \"Copyright !!!\")")
          #:out #"raco mcfly: Modifying \"info.rkt\"...\n")

    (test 'paren-module
          (%test-inforkt-update
           #:inforkt-contents "(module info setup/infotab\n\n  (define name 'foo)\n\n  (define blurb \"yo\"))\n")
          '("(module info setup/infotab"
            ""
            "  (define name 'foo)"
            ""
            "  (define blurb \"yo\")"
            ""
            ";; TODO: Add the PLaneT owner and package name, and double-check the version:"
            "(define mcfly-planet       '!!!/!!!:1:0)"
            ""
            ";; TODO: Add the subtitle string, or define \"mcfly-title\" instead:"
            "(define mcfly-subtitle     \"!!!\")"
            ""
            ";; TODO: Add the Web home page URL for this package:"
            "(define homepage           \"http://!!!\")"
            ""
            ";; TODO: Add the author(s):"
            "(define mcfly-author       \"!!!\")"
            ""
            "(define repositories       '(\"4.x\"))"
            ""
            "(define categories         '(misc))"
            ""
            ";; TODO: See http://doc.racket-lang.org/search/index.html?q=can-be-loaded-with"
            "(define can-be-loaded-with 'all)"
            ""
            "(define scribblings        '((\"doc.scrbl\" () (library))))"
            ""
            ";; TODO: Double-check this:"
            "(define primary-file       \"main.rkt\")"
            ""
            ";; TODO: Set this to the file that has starting \"doc\" forms:"
            "(define mcfly-start        \"main.rkt\")"
            ""
            ";; TODO: Double-check that this includes all files for the PLaneT package:"
            "(define mcfly-files        '(defaults))"
            ""
            ";; TODO: Add short name for license (e.g., \"LGPLv3\"). See http://www.gnu.org/licenses/"
            "(define mcfly-license      \"!!!\")"
            ""
            ";; TODO: Add copyright, license, disclaimers, and other legal information."
            "(define mcfly-legal        \"Copyright !!!\"))")
          #:out #"raco mcfly: Modifying \"info.rkt\"...\n")

    (let ((orig-lines `("#lang setup/infotab"
                        "(define mcfly-planet       '!!!/!!!:1:0)"
                        "(define mcfly-subtitle     \"!!!\")"
                        "(define homepage           \"http://!!!\")"
                        "(define mcfly-author       \"!!!\")"
                        "(define repositories       '(\"4.x\"))"
                        "(define categories         '(misc))"
                        "(define can-be-loaded-with 'all)"
                        "(define scribblings        '((\"doc.scrbl\" () (library))))"
                        "(define primary-file       \"main.rkt\")"
                        "(define mcfly-start        \"main.rkt\")"
                        "(define mcfly-files        '(defaults))"
                        "(define mcfly-license      \"!!!\")"
                        "(define mcfly-legal        \"Copyright !!!\")"
                        "(define name 'foo)"
                        "(define blurb \"yo\")")))
      (test 'no-changes
            (%test-inforkt-update
             #:inforkt-contents (apply string-append (map (lambda (line)
                                                            (string-append line "\n"))
                                                          orig-lines)))
            orig-lines))))