From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: guile-devel@gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [PATCH v3 2/6] tests: Add new compile-file tests.
Date: Sat, 18 Nov 2023 01:05:34 -0500 [thread overview]
Message-ID: <20231118060621.24675-2-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20231118060621.24675-1-maxim.cournoyer@gmail.com>
Add a test for bug #66046.
To run just the compiler tests:
./meta/guile -L test-suite -L . test-suite/tests/compiler.test
* test-suite/tests/compiler.test (with-temporary-directory): New syntax.
(delete-file-recursively): New procedure.
("compile-file: relative include works")
("compile-file: relative include works with load path
canonicalization"): New tests.
---
(no changes since v1)
test-suite/tests/compiler.test | 75 +++++++++++++++++++++++++++++++++-
1 file changed, 74 insertions(+), 1 deletion(-)
diff --git a/test-suite/tests/compiler.test b/test-suite/tests/compiler.test
index a018e0c41..2026d5ff3 100644
--- a/test-suite/tests/compiler.test
+++ b/test-suite/tests/compiler.test
@@ -1,5 +1,5 @@
;;;; compiler.test --- tests for the compiler -*- scheme -*-
-;;;; Copyright (C) 2008-2014, 2018, 2021-2022 Free Software Foundation, Inc.
+;;;; Copyright (C) 2008-2014, 2018, 2021-2023 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,7 @@
(define-module (tests compiler)
#:use-module (test-suite lib)
#:use-module (test-suite guile-test)
+ #:use-module (ice-9 ftw)
#:use-module (system base compile)
#:use-module ((language tree-il)
#:select (tree-il-src call-args))
@@ -27,6 +28,39 @@
(define read-and-compile
(@@ (system base compile) read-and-compile))
+;;; Based on 'with-directory-excursion', from (guix build utils).
+(define-syntax-rule (with-temporary-directory body ...)
+ "Run BODY with DIR as the process's current directory."
+ (let ((init (getcwd))
+ (dir (mkdtemp "tempdir.XXXXXX")))
+ (dynamic-wind
+ (lambda ()
+ (chdir dir))
+ (lambda ()
+ body ...)
+ (lambda ()
+ (chdir init)
+ (delete-file-recursively dir)))))
+
+;;; XXX: Adapted from (guix build utils).
+(define* (delete-file-recursively dir)
+ "Delete DIR recursively, like `rm -rf', without following symlinks."
+ (file-system-fold (const #t) ;enter
+ (lambda (file stat result) ; leaf
+ (delete-file file))
+ (const #t) ; down
+ (lambda (dir stat result) ; up
+ (rmdir dir))
+ (const #t) ; skip
+ (lambda (file stat errno result)
+ (format (current-error-port)
+ "warning: failed to delete ~a: ~a~%"
+ file (strerror errno)))
+ #t
+ dir
+
+ ;; Don't follow symlinks.
+ lstat))
\f
(with-test-prefix "basic"
@@ -434,3 +468,42 @@
(set! proc ((load-thunk-from-memory bytecode)))
(procedure? proc)))
(pass-if-equal "proc executes" 42 (proc))))
+
+(with-test-prefix "compile-file"
+ ;; Setup test library sources in a temporary directory.
+ (let ((top-sexp '(define-library (hello)
+ (import (scheme base)
+ (scheme write))
+ (export hello)
+ (include "hello/hello-impl.scm")))
+ (included-sexp '(define (hello)
+ (display "hello!\n"))))
+ (with-temporary-directory
+ (mkdir "module")
+ (call-with-output-file "module/hello.scm"
+ (lambda (port)
+ (write top-sexp port)))
+ (mkdir "module/hello")
+ (call-with-output-file "module/hello/hello-impl.scm"
+ (lambda (port)
+ (write included-sexp port)))
+ (mkdir "build")
+ (chdir "build")
+
+ (pass-if "relative include works"
+ (compile-file "../module/hello.scm" #:output-file "hello.go")
+ #t)
+
+ ;; This used to fail, because compile-file's #:canonicalization
+ ;; defaults to 'relative, which caused 'scm_relativize_path' to
+ ;; strip the prefix not in the load path, to avoid baking an
+ ;; invalid source file reference in the byte compiled output file
+ ;; (see: https://bugs.gnu.org/66046). This was fixed by having a
+ ;; 'compilation-source-file' fluid that preserves the file name
+ ;; passed to 'compile-file', used by 'include' instead of the file
+ ;; name of the port.
+ (pass-if "relative include works with load path canonicalization"
+ (begin
+ (add-to-load-path (string-append (getcwd) "/../module"))
+ (compile-file "../module/hello.scm" #:output-file "hello.go")
+ #t)))))
--
2.41.0
next prev parent reply other threads:[~2023-11-18 6:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-18 6:05 [PATCH v3 1/6] module: Add srfi-126 Maxim Cournoyer
2023-11-18 6:05 ` Maxim Cournoyer [this message]
2023-11-18 6:05 ` [PATCH v3 3/6] ice-9: Fix 'include' when used in compilation contexts Maxim Cournoyer
2023-11-18 6:05 ` [PATCH v3 4/6] module: Add srfi-128 Maxim Cournoyer
2023-11-18 6:05 ` [PATCH v3 5/6] module: Add srfi-125 Maxim Cournoyer
2023-11-18 6:05 ` [PATCH v3 6/6] module: Add srfi-151 Maxim Cournoyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231118060621.24675-2-maxim.cournoyer@gmail.com \
--to=maxim.cournoyer@gmail.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).