Implement test-library-standard and fix bugs.
authorChris Hanson <org/chris-hanson/cph>
Fri, 5 Oct 2018 03:35:45 +0000 (20:35 -0700)
committerChris Hanson <org/chris-hanson/cph>
Fri, 5 Oct 2018 03:35:45 +0000 (20:35 -0700)
src/runtime/library-database.scm
src/runtime/library-standard.scm
src/runtime/runtime.pkg
tests/check.scm
tests/runtime/test-library-standard.scm [new file with mode: 0644]

index b0bc923336c6682a3faaee803d8cf8162dce1337..813c89b21346b471d660eb2864d8ef20d0c2ae70 100644 (file)
@@ -148,7 +148,7 @@ USA.
        (cdr p)))))
 
 (define-record-type <loaded-library>
-    (%make-loaded-library name exports environment exporter)
+    (%make-loaded-library name exports exporter environment)
     loaded-library?
   (name loaded-library-name)
   (exports loaded-library-exports)
index db0042f70bcd523570939582d172a84e71bc268d..6d459017f0f7237f60a922935751ff1a0291c8af 100644 (file)
@@ -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 '())
-
+\f
 (define-standard-library '(scheme base)
   '(*
     +
@@ -310,7 +316,7 @@ USA.
     write-string
     write-u8
     zero?))
-
+\f
 (define-standard-library '(scheme case-lambda)
   '(case-lambda))
 
@@ -375,7 +381,7 @@ USA.
 (define-standard-library '(scheme eval)
   '(environment
     eval))
-
+\f
 (define-standard-library '(scheme file)
   '(call-with-input-file
        call-with-output-file
@@ -435,7 +441,7 @@ USA.
     write
     write-shared
     write-simple))
-
+\f
 (define-standard-library '(scheme r5rs)
   '(*
     +
index 3dfe25cf68a035f61a97bbe369a4b1081f65ea1b..0bcfb7c1b6690b2108da6546fde62a2d5f7787ba 100644 (file)
@@ -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")
index e9472720b5716597427cb5e5294317d9ae1d9c06..ed766d51f0ef86b371175df512297dc42bc68280 100644 (file)
@@ -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 (file)
index 0000000..9a1d7d7
--- /dev/null
@@ -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))
+\f
+(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