Reject Guile import forms in Jerboa scripts
ober
5b46f1bf9dd97a698b9ef3e0b3531263d8de7b0b
--- a/src/jcode/core/verified-run.ss +++ b/src/jcode/core/verified-run.ss @@ -5333,6 +5333,8 @@ (list (cons "(library " "user-facing Jerboa files must be .ss scripts/modules, not (library ...) forms") (cons "(library)" "user-facing Jerboa files must be .ss scripts/modules, not (library ...) forms") + (cons "(use-modules" "Jerboa imports use `(import ...)`, not Guile `(use-modules ...)`; write `(import (jerboa prelude) ...)` at the top of the script") + (cons "#:use" "Jerboa scripts do not use `#:use` module directives; write a top-level `(import (jerboa prelude) ...)` form") (cons "(define-struct" "Jerboa uses defstruct, or plain globals for generated examples; do not use define-struct") (cons "(define-record-type" "avoid define-record-type in generated Jerboa; use defstruct or plain globals") (cons "(return " "Jerboa has no return form; use cond/if/named let to return values") --- a/test/run.ss +++ b/test/run.ss @@ -7149,6 +7149,79 @@ (safe-delete-test-file! target-path)) (let* ([vr-dir "/tmp"] + [target "jcode-use-modules-import-guard.ss"] + [target-path (string-append vr-dir "/" target)] + [initial + (string-append + "(import (jerboa prelude))\n" + "(define (message) \"initial\")\n" + "(displayln (message))\n")] + [bad + (string-append + "(use-modules '(jerboa prelude))\n" + "(use-modules '(jerboa-qt qt))\n" + "(define (message) \"bad\")\n" + "(displayln \"ok\")\n")] + [good + (string-append + "(import (jerboa prelude)\n" + " (jerboa-qt qt))\n" + "(define (message) \"ok\")\n" + "(displayln \"ok\")\n")] + [tool-results '()] + [resp + (scripted-responder + (list + (list + (make-wtool-call "write" + (list (cons "path" target) + (cons "content" bad)) + #f)) + (list + (make-wtool-call "balance" + (list (cons "path" target)) + #f)) + (list + (make-wtool-call "write" + (list (cons "path" target) + (cons "content" good)) + #f))))]) + (safe-delete-test-file! target-path) + (write-test-output-file target-path + (lambda (o) (display initial o)) + 'replace) + (let ([result + (verified-run resp "repair Guile use-modules imports" + (list + (cons 'cwd vr-dir) + (cons 'verify-command + (string-append "grep -q '^(import' " target)) + (cons 'write-scope (parse-write-scope target)) + (cons 'local-model? #t) + (cons 'max-iterations 8) + (cons 'max-tool-errors 2) + (cons 'on-message + (lambda (m) + (when (equal? (message-role m) "tool") + (set! tool-results + (cons (message-content m) tool-results)))))))]) + (check! "verified-run: use-modules import guard recovers" + result "VERIFIED: exit 0\n") + (check-pred! "verified-run: use-modules import guard explains repair" + (reverse tool-results) + (lambda (xs) + (and (pair? xs) + (str-contains? (car xs) "Jerboa imports use") + (str-contains? (car xs) "(import ...)") + (str-contains? (car xs) "(jerboa prelude)")))) + (check-pred! "verified-run: use-modules import guard wrote repaired source" + (call-with-input-file target-path (lambda (p) (get-string-all p))) + (lambda (s) + (and (str-contains? s "(import (jerboa prelude)") + (not (str-contains? s "use-modules")))))) + (safe-delete-test-file! target-path)) + + (let* ([vr-dir "/tmp"] [target "jcode-invalid-defstruct-diagnosis.ss"] [target-path (string-append vr-dir "/" target)] [bad-source "(import (jerboa prelude))\n(defstruct game\n board\n score)\n\n(define (next) 2)\n"])