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

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

(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 (%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              (string-append 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 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 !!!\")"
        ""))

(test (%test-inforkt-update
       #:inforkt-contents "#lang setup/infotab\n(define name 'foo)\n\n(define blurb \"yo\")\n")
      '("#lang setup/infotab"
        ""
        ";; 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 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 !!!\")"
        ""
        "(define name 'foo)"
        ""
        "(define blurb \"yo\")"))

(test (%test-inforkt-update
       #:inforkt-contents "(module info setup/infotab\n\n  (define name 'foo)\n\n  (define blurb \"yo\"))\n")
      '("(module info setup/infotab"
        ""
        "  "
        ";; 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 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 !!!\")"
        ""
        "(define name 'foo)"
        ""
        "  (define blurb \"yo\"))"))