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.devel Subject: [PATCH 1/2] tests: Add new compile-file tests. Date: Thu, 9 Nov 2023 22:32:22 -0500 Message-ID: <20231110033247.25803-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="10636"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxim Cournoyer To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Nov 10 04:33:27 2023 Return-path: Envelope-to: guile-devel@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 1r1IGs-0002YJ-6C for guile-devel@m.gmane-mx.org; Fri, 10 Nov 2023 04:33:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1IGX-0000qa-EX; Thu, 09 Nov 2023 22:33:05 -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 1r1IGW-0000o7-1S for guile-devel@gnu.org; Thu, 09 Nov 2023 22:33:04 -0500 Original-Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1IGU-0004m6-7w for guile-devel@gnu.org; Thu, 09 Nov 2023 22:33:03 -0500 Original-Received: by mail-qt1-x82e.google.com with SMTP id d75a77b69052e-41cb615c6fbso10293201cf.1 for ; Thu, 09 Nov 2023 19:33:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699587180; x=1700191980; darn=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=N9kzA+pXz4V0z3QB7IcFOsruT4ylOrO3x2wOMr5eYIqf/nUmcJ9cgFehMg6OEszMVe scvzkZatZfF+/8NfH3LY8ge1mP0Cf2Gjji/7RNKA5eZ/m13B/bjv7AbMTMgUye87q7jm K+GBXyth59U9S3BbHhn0T9FZArAVB0wAupIvaP56eWpdOpdgAU84SBPTHPVE502msxYZ odbz9uh6qDmCmvOhlx9Ik2NoSmYGQeaed32ekONf2c6tbrNHKd9c/U0wY7sLbzZRmhlX pMar4q7RvVCHZO1RzqfPWTsbwNednWq8lmVobmI+UV6YOB1g5sza3LfUX028LCCIe1iE slLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699587180; x=1700191980; 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=aConZVuPBw/X+tHPchhX4SM+iOwP2lqP4mTfzxkG/27x0VSIQwvOmaxYQ5Vr8ZOYyS iYXtb3DoygnUldODBIi8Xy/IEz8OZT0Bm5nNf3cSNwh8GsLZCFbwLwVyT8lMqbMtepoG +iYNi1tKnf/ZBL7YHCFI/NT40NyNn+7eSSNiNLl4WEe5gDwmgvi08mPhUFLckpHh5K3z iL2fZhXwj4qjpBqNoay0zwerPVc+mKVBt9f+zHvL+aopFB8Tljt8aeefAQl+QF/xYI0A lPzpj7t+PYPhJ/4WeY4SBgtp8ZIReAe+8RDumEWMC1gVjRItHWtZqr5YAdEmyHLIKb2Z uNQQ== X-Gm-Message-State: AOJu0Yw4yId2VKUoqbebo1NtZeDK634Eoo9y7lZglYqDerRg4zjlFXMT +i8nP8nei7mBkdUvm/s2jSjPZ5owFm8= X-Google-Smtp-Source: AGHT+IFKShAQ1XEV7GD4KOnDu5Vh6pD2zosTu5Xfor0vClbohs8iXAA2aExl0rdZdz9efleWb1X9hQ== X-Received: by 2002:ac8:5755:0:b0:41c:e92a:c604 with SMTP id 21-20020ac85755000000b0041ce92ac604mr7593319qtx.59.1699587180379; Thu, 09 Nov 2023 19:33:00 -0800 (PST) Original-Received: from localhost.localdomain (dsl-10-129-91.b2b2c.ca. [72.10.129.91]) by smtp.gmail.com with ESMTPSA id j16-20020ac84f90000000b0041b7f89ad19sm2504438qtw.53.2023.11.09.19.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 19:32:59 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <878r7akwce.fsf@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=maxim.cournoyer@gmail.com; helo=mail-qt1-x82e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22073 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