From 11dcd292d4bc2139406293cf09eea1a3dfb2167b Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Thu, 4 Oct 2018 20:35:45 -0700 Subject: [PATCH] Implement test-library-standard and fix bugs. --- src/runtime/library-database.scm | 2 +- src/runtime/library-standard.scm | 14 ++++-- src/runtime/runtime.pkg | 4 +- tests/check.scm | 1 + tests/runtime/test-library-standard.scm | 58 +++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 tests/runtime/test-library-standard.scm diff --git a/src/runtime/library-database.scm b/src/runtime/library-database.scm index b0bc92333..813c89b21 100644 --- a/src/runtime/library-database.scm +++ b/src/runtime/library-database.scm @@ -148,7 +148,7 @@ USA. (cdr p))))) (define-record-type - (%make-loaded-library name exports environment exporter) + (%make-loaded-library name exports exporter environment) loaded-library? (name loaded-library-name) (exports loaded-library-exports) diff --git a/src/runtime/library-standard.scm b/src/runtime/library-standard.scm index db0042f70..6d459017f 100644 --- a/src/runtime/library-standard.scm +++ b/src/runtime/library-standard.scm @@ -58,6 +58,12 @@ USA. (if (pair? missing) (warn "Missing definitions for library:" name missing)))) +(define (standard-library-names) + (map car standard-libraries)) + +(define (standard-library-exports name) + (cdr (assoc name standard-libraries))) + (define (define-standard-library name exports) (let ((p (assoc name standard-libraries))) (if p @@ -70,7 +76,7 @@ USA. name) (define standard-libraries '()) - + (define-standard-library '(scheme base) '(* + @@ -310,7 +316,7 @@ USA. write-string write-u8 zero?)) - + (define-standard-library '(scheme case-lambda) '(case-lambda)) @@ -375,7 +381,7 @@ USA. (define-standard-library '(scheme eval) '(environment eval)) - + (define-standard-library '(scheme file) '(call-with-input-file call-with-output-file @@ -435,7 +441,7 @@ USA. write write-shared write-simple)) - + (define-standard-library '(scheme r5rs) '(* + diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 3dfe25cf6..0bcfb7c1b 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -5885,7 +5885,9 @@ USA. (parent (runtime library)) (export (runtime library) add-standard-libraries! - check-standard-libraries!)) + check-standard-libraries! + standard-library-exports + standard-library-names)) (define-package (runtime library imports) (files "library-imports") diff --git a/tests/check.scm b/tests/check.scm index e9472720b..ed766d51f 100644 --- a/tests/check.scm +++ b/tests/check.scm @@ -64,6 +64,7 @@ USA. "runtime/test-hash-table" "runtime/test-integer-bits" ("runtime/test-library-parser" (runtime library)) + ("runtime/test-library-standard" (runtime library)) ("runtime/test-library-imports" (runtime library)) "runtime/test-md5" "runtime/test-mime-codec" diff --git a/tests/runtime/test-library-standard.scm b/tests/runtime/test-library-standard.scm new file mode 100644 index 000000000..9a1d7d7d2 --- /dev/null +++ b/tests/runtime/test-library-standard.scm @@ -0,0 +1,58 @@ +#| -*-Scheme-*- + +Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, + 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, + 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, + 2017, 2018 Massachusetts Institute of Technology + +This file is part of MIT/GNU Scheme. + +MIT/GNU Scheme is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +MIT/GNU Scheme is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with MIT/GNU Scheme; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, +USA. + +|# + +;;;; Tests for standard libraries + +(declare (usual-integrations)) + +(define-test 'check-standard-libraries! + (lambda () + (check-standard-libraries!))) + +(define-test 'add-standard-libraries! + (let ((db (make-library-db))) + (add-standard-libraries! db) + (map (lambda (name) + (lambda () + (assert-true (db 'metadata? name)) + (assert-false (db 'compiled? name)) + (assert-true (db 'loaded? name)) + (let ((exports (standard-library-exports name))) + (let ((metadata (db 'get-metadata name))) + (assert-equal (library-metadata-name metadata) name) + (assert-null (library-metadata-imports metadata)) + (assert-lset= eq? + (library-metadata-exports metadata) + exports) + (assert-false (library-metadata-pathname metadata))) + (let ((loaded (db 'get-loaded name))) + (assert-equal (loaded-library-name loaded) name) + (assert-lset= eq? + (loaded-library-exports loaded) + exports) + (assert-eqv (loaded-library-environment loaded) + system-global-environment))))) + (standard-library-names)))) \ No newline at end of file -- 2.25.1