From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Cournoyer Newsgroups: gmane.lisp.guile.bugs Subject: bug#66046: [PATCH 1/2] tests: Add new compile-file tests. Date: Thu, 9 Nov 2023 22:36:21 -0500 Message-ID: <20231110033627.26468-1-maxim.cournoyer@gmail.com> References: <878r7akwce.fsf@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33153"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Timothy Sample , Maxim Cournoyer , Daphne Preston-Kendal To: 66046@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Fri Nov 10 04:37:47 2023 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r1IL5-0008QP-Fx for guile-bugs@m.gmane-mx.org; Fri, 10 Nov 2023 04:37:47 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1IKj-00032I-8M; Thu, 09 Nov 2023 22:37:25 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1IKg-00031q-Vx for bug-guile@gnu.org; Thu, 09 Nov 2023 22:37:23 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1IKg-0005I8-NM for bug-guile@gnu.org; Thu, 09 Nov 2023 22:37:22 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r1ILK-0007f6-5L for bug-guile@gnu.org; Thu, 09 Nov 2023 22:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 10 Nov 2023 03:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66046 X-GNU-PR-Package: guile Original-Received: via spool by 66046-submit@debbugs.gnu.org id=B66046.169958744729392 (code B ref 66046); Fri, 10 Nov 2023 03:38:02 +0000 Original-Received: (at 66046) by debbugs.gnu.org; 10 Nov 2023 03:37:27 +0000 Original-Received: from localhost ([127.0.0.1]:49262 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1IKk-0007du-MD for submit@debbugs.gnu.org; Thu, 09 Nov 2023 22:37:27 -0500 Original-Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]:46432) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1IKf-0007dV-1Z for 66046@debbugs.gnu.org; Thu, 09 Nov 2023 22:37:24 -0500 Original-Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-672096e0e89so9850206d6.1 for <66046@debbugs.gnu.org>; Thu, 09 Nov 2023 19:36:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699587395; x=1700192195; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ksId9g+ZHB751VdieHYCNG9b72dLXteLyFJ3PkU90H4=; b=mE2jpv4cYA4YPldSvekCuZTO/+88IbDcu5r5xLTy9fdcbdjchVD1Oi06wVAFTEWNsz Kb9BXciA2PGdy9kqvvcwz71iA+dklka3tr4SMcAJIk1T+8vj7RqrtChoRhqQVoO/5FLl /Nbahm6seJslIsJXEux2TNncNcaYct2sqx0p9wFeue6dMzcH7/tLaAeEdOyIKm+gB1AK xufrKpC/tE5RcZTVTY4gx+n9oYQWvkb+hKX7EeoMIPLW0jzyGdkV4jeygsyI/sFVbo3Y SRCx9QZiT0u4cV3yq93bJTnp3T+d3+EIblRogyPcEQKl47Fo/5rLld3qHSXK/4216YMG aeNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699587395; x=1700192195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ksId9g+ZHB751VdieHYCNG9b72dLXteLyFJ3PkU90H4=; b=fOXG1x0zEUJ8rQDy3MIrr/nujNh4B9hItUzcS620vLOFeVW68tOHrPhSTelzgiGF8z 11wavDd8WWDag3rAisYQB5PFySXgiKaiLKhrqDg0IDjQfA4pi/3OPQNp/SqOkrpxOk// ZAE3PXFitNjgCVVeZ43NIKyWOuRqVy51YzKZqXqD2IVZTnNVGFmce2RddN850EcHPz+8 EANfW8i2QpMU9Tx722ZWzZ4ZtTU7VVlQRdU8DOAKIGoanAFGqYgCZ+Y7lWpVBzP0+5Zz p2jprW/uUYHGs0LA4B7lDGP8tdZMy4zyBG7Zbgnhn6frbj9e3u6juvZS/4ummADRG/BY vAcw== X-Gm-Message-State: AOJu0YxX1Sow1d7KSZSnwrKjtrScdEBv5ED09ZmGmNdh2tunpyOjwpeQ b+RMmGqL9LYR1wWH90M4dK84gQvuV8E= X-Google-Smtp-Source: AGHT+IGBZTWgdzSw5idbGR/9BuLdKLX2eIfJYLKghgB0Gn7UvsEd0bVRjIjBhBybEWrVaYNmhWsQ3A== X-Received: by 2002:ad4:5f8c:0:b0:66d:42d9:fc83 with SMTP id jp12-20020ad45f8c000000b0066d42d9fc83mr7175839qvb.10.1699587395383; Thu, 09 Nov 2023 19:36:35 -0800 (PST) Original-Received: from localhost.localdomain (dsl-10-129-91.b2b2c.ca. [72.10.129.91]) by smtp.gmail.com with ESMTPSA id mn11-20020a0562145ecb00b0065aff6b49afsm2609967qvb.110.2023.11.09.19.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 19:36:35 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <878r7akwce.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10692 Archived-At: 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. --- 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)) (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))))) base-commit: 75cd95060fb1ea7586f0e4b9081694c6d61f1d3b -- 2.41.0