0.9.12.10:
[sbcl.git] / tests / compiler.test.sh
index dca23a0..45acaba 100644 (file)
@@ -6,7 +6,7 @@
 # While most of SBCL is derived from the CMU CL system, the test
 # files (like this one) were written from scratch after the fork
 # from CMU CL.
-# 
+#
 # This software is in the public domain and is provided with
 # absolutely no warranty. See the COPYING and CREDITS files for
 # more information.
@@ -39,11 +39,11 @@ expect_failed_compile $tmpfilename
 # having the same name.
 cat > $tmpfilename <<EOF
     (in-package :cl-user)
-    (defun foo (x) 
+    (defun foo (x)
       (flet ((baz (y) (load y)))
         (declare (notinline baz))
         (baz x)))
-    (defun bar (x) 
+    (defun bar (x)
       (flet ((baz (y) (load y)))
         (declare (notinline baz))
         (baz x)))
@@ -93,7 +93,7 @@ expect_clean_compile $tmpfilename
 cat > $tmpfilename <<EOF
     (in-package :cl-user)
     (defun foo (x) (list x))
-    (defun bar (x) 
+    (defun bar (x)
       (declare (notinline foo))
       (1+ (foo x)))
 EOF
@@ -162,12 +162,12 @@ fail_on_compiler_note $tmpfilename
 # been there
 cat > $tmpfilename <<EOF
     (eval-when (:compile-toplevel :load-toplevel :execute)
-      (defstruct buffer-state 
+      (defstruct buffer-state
         (output-index 0)))
-    
+
     (defclass buffered-stream-mixin ()
       ((buffer-state :initform (make-buffer-state))))
-    
+
     (defgeneric frob (stream))
     (defmethod frob ((stream t))
       nil)
@@ -286,8 +286,74 @@ cat > $tmpfilename <<EOF
 EOF
 expect_failed_compile $tmpfilename
 
+# This should be clean
+cat > $tmpfilename <<EOF
+(defvar *string* (make-string 10 :element-type 'base-char))
+EOF
+expect_clean_compile $tmpfilename
+
+# This should style-warn (but not warn or otherwise fail) as the call
+# to FORMAT has too many arguments, which is bad style but not
+# otherwise fatal.
+cat > $tmpfilename <<EOF
+(defun foo (a b)
+  (format nil "abc~~def" a b))
+EOF
+expect_warned_compile $tmpfilename
+
+# Tests that destructive-functions on known-constant data cause
+# compile-time warnings.
+cat > $tmpfilename <<EOF
+(let ((string "foo"))
+  (defun foo ()
+    (setf string "bar")))
+EOF
+expect_clean_compile $tmpfilename
+
+cat > $tmpfilename <<EOF
+(defun foo ()
+  (let (result)
+    (nreverse result)))
+EOF
+expect_clean_compile $tmpfilename
+
+cat > $tmpfilename <<EOF
+(defun bar ()
+  (let ((result ""))
+    (nreverse result)))
+EOF
+expect_clean_compile $tmpfilename
+
+cat > $tmpfilename <<EOF
+(let ((string "foo"))
+  (defun foo ()
+    (replace string "bar")))
+EOF
+expect_failed_compile $tmpfilename
+
+cat > $tmpfilename <<EOF
+(defun foo ()
+  (setf (char "bar" 0) #\1))
+EOF
+expect_failed_compile $tmpfilename
+
+cat > $tmpfilename <<EOF
+(let ((foo '(1 2 3)))
+  (defun foo ()
+    (nconc foo foo)))
+EOF
+expect_failed_compile $tmpfilename
+
+cat > $tmpfilename <<EOF
+(declaim (optimize (speed 3) (space 0) (safety 0)))
+
+(defun foo (bar)
+  (last bar))
+EOF
+expect_clean_compile $tmpfilename
+
 rm $tmpfilename
 rm $compiled_tmpfilename
 
-# success 
+# success
 exit 104