Raymond Toy pushed to branch issue-139-filename-encoding-utf8 at cmucl / cmucl

Commits:

19 changed files:

Changes:

  • .gitlab-ci.yml
    ... ... @@ -80,7 +80,8 @@ linux:ansi-test:
    80 80
       script:
    
    81 81
         - cd ansi-test
    
    82 82
         - make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
    
    83
    -    - grep 'No unexpected \(successes\|failures\)' test.out
    
    83
    +    # There should be no unexpected successes or failures; check these separately.
    
    84
    +    - grep -a 'No unexpected successes' test.out && grep -a 'No unexpected failures' test.out
    
    84 85
         
    
    85 86
     linux:benchmark:
    
    86 87
       stage: benchmark
    
    ... ... @@ -166,7 +167,8 @@ osx:ansi-test:
    166 167
       script:
    
    167 168
         - cd ansi-test
    
    168 169
         - make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
    
    169
    -    - grep 'No unexpected \(successes\|failures\)' test.out 
    
    170
    +    # There should be no unexpected successes or failures; check these separately.
    
    171
    +    - grep -a 'No unexpected successes' test.out && grep -a 'No unexpected failures' test.out
    
    170 172
       
    
    171 173
     osx:benchmark:
    
    172 174
       stage: benchmark
    

  • src/code/commandline.lisp
    ... ... @@ -339,16 +339,54 @@
    339 339
     (defun help-switch-demon (switch)
    
    340 340
       (declare (ignore switch))
    
    341 341
       (format t (intl:gettext "~&Usage: ~A <options>~2%") *command-line-utility-name*)
    
    342
    -  (dolist (s (sort *legal-cmd-line-switches* #'string<
    
    343
    -		   :key #'car))
    
    344
    -    (destructuring-bind (name doc arg)
    
    345
    -	s
    
    346
    -      (format t "    -~A ~@[~A~]~%" name (if arg (intl:gettext arg)))
    
    347
    -      ;; Poor man's formatting of the help string
    
    348
    -      (with-input-from-string (stream (intl:gettext doc))
    
    349
    -	(loop for line = (read-line stream nil nil)
    
    350
    -	   while line
    
    351
    -	   do (format t "~8T~A~%" line)))))
    
    342
    +  (flet
    
    343
    +      ((get-words (s)
    
    344
    +	 (declare (string s))
    
    345
    +	 ;; Return a list of all the words from S.  A word is defined
    
    346
    +	 ;; as any sequence of characters separated from others by
    
    347
    +	 ;; whitespace consisting of space, newline, tab, formfeed, or
    
    348
    +	 ;; carriage return.
    
    349
    +	 (let ((end (length s)))
    
    350
    +	   (loop for left = 0 then (+ right 1)
    
    351
    +		 for right = (or
    
    352
    +			      (position-if #'(lambda (c)
    
    353
    +					       (member c
    
    354
    +						       '(#\space #\newline #\tab #\ff #\cr)))
    
    355
    +					   s
    
    356
    +					   :start left)
    
    357
    +			      end)
    
    358
    +		 ;; Collect the word bounded by left and right in a list.
    
    359
    +		 unless (and (= right left))
    
    360
    +		   collect (subseq s left right) into subseqs
    
    361
    +		 ;; Keep going until we reach the end of the string.
    
    362
    +		 until (>= right end)
    
    363
    +		 finally (return subseqs)))))
    
    364
    +
    
    365
    +    (dolist (s (sort *legal-cmd-line-switches* #'string<
    
    366
    +		     :key #'car))
    
    367
    +      (destructuring-bind (name doc arg)
    
    368
    +	  s
    
    369
    +	(format t "    -~A ~@[~A~]~%" name (if arg (intl:gettext arg)))
    
    370
    +	;; Poor man's formatting of the help string
    
    371
    +	(let ((*print-right-margin* 80))
    
    372
    +	  ;; Extract all the words from the string and print them out
    
    373
    +	  ;; one by one with a space between each, wrapping the output
    
    374
    +	  ;; if needed.  Each line is indented by 8 spaces.
    
    375
    +	  ;;
    
    376
    +	  ;; "~@<       ~@;"
    
    377
    +	  ;;    per-line prefix of spaces and pass the whole arg list
    
    378
    +	  ;;    to this directive.
    
    379
    +	  ;;
    
    380
    +	  ;; "~{~A~^ ~}"
    
    381
    +	  ;;    loop over each word and print out the word followed by
    
    382
    +	  ;;    a space.
    
    383
    +	  ;;
    
    384
    +	  ;; "~:@>"
    
    385
    +	  ;;    No suffix, and insert conditional newline after each
    
    386
    +	  ;;    group of blanks if needed.
    
    387
    +	  (format t "~@<        ~@;~{~A~^ ~}~:@>"
    
    388
    +		  (get-words (intl:gettext doc))))
    
    389
    +	(terpri))))
    
    352 390
       (ext:quit))
    
    353 391
       
    
    354 392
     (defswitch "help" #'help-switch-demon
    

  • src/code/extfmts.lisp
    ... ... @@ -22,8 +22,7 @@
    22 22
     	  describe-external-format))
    
    23 23
     
    
    24 24
     (defvar *default-external-format*
    
    25
    -  #-unicode :iso8859-1
    
    26
    -  #+unicode :utf-8
    
    25
    +  :utf-8
    
    27 26
       "The default external format to use if no other external format is
    
    28 27
       specified")
    
    29 28
     
    

  • src/code/filesys.lisp
    ... ... @@ -950,7 +950,11 @@
    950 950
       File after it was renamed."
    
    951 951
       (let* ((original (truename file))
    
    952 952
     	 (original-namestring (unix-namestring original t))
    
    953
    -	 (new-name (merge-pathnames new-name file))
    
    953
    +	 ;; First, merge NEW-FILE-NAME with *DEFAULT-PATHNAME-DEFAULTS* to
    
    954
    +	 ;; fill in the missing components and then merge again with
    
    955
    +	 ;; the FILE to get any missing components from FILE.
    
    956
    +	 (new-name (merge-pathnames (merge-pathnames new-name)
    
    957
    +				    file))
    
    954 958
     	 (new-namestring (unix-namestring new-name nil)))
    
    955 959
         (unless new-namestring
    
    956 960
           (error 'simple-file-error
    
    ... ... @@ -1075,13 +1079,21 @@ optionally keeping some of the most recent old versions."
    1075 1079
     		 :pathname file
    
    1076 1080
     		 :format-control (intl:gettext "~S doesn't exist.")
    
    1077 1081
     		 :format-arguments (list file)))
    
    1078
    -	(multiple-value-bind (winp dev ino mode nlink uid)
    
    1079
    -			     (unix:unix-stat name)
    
    1080
    -	  (declare (ignore dev ino mode nlink))
    
    1081
    -	  (when winp
    
    1082
    -            (let ((user-info (unix:unix-getpwuid uid)))
    
    1083
    -              (when user-info
    
    1084
    -                (unix:user-info-name user-info))))))))
    
    1082
    +	;; unix-namestring converts "." to "".  Convert it back to
    
    1083
    +	;; "." so we can stat the current directory.  (Perhaps
    
    1084
    +	;; that's a bug in unix-namestring?)
    
    1085
    +	(when (zerop (length name))
    
    1086
    +	  (setf name "."))
    
    1087
    +	(let (author)
    
    1088
    +	  (unwind-protect
    
    1089
    +	       (progn
    
    1090
    +		 (setf author (alien:alien-funcall
    
    1091
    +			       (alien:extern-alien "os_file_author"
    
    1092
    +						   (function (alien:* c-call:c-string) c-call:c-string))
    
    1093
    +			       (unix::%name->file name)))
    
    1094
    +		 (unless (alien:null-alien author)
    
    1095
    +		   (alien:cast author c-call:c-string)))
    
    1096
    +	    (alien:free-alien author))))))
    
    1085 1097
     
    
    1086 1098
     
    
    1087 1099
     ;;;; DIRECTORY.
    
    ... ... @@ -1474,4 +1486,4 @@ optionally keeping some of the most recent old versions."
    1474 1486
     			 (retry () :report "Try to create the directory again"
    
    1475 1487
     				(go retry))))))
    
    1476 1488
     	 ;; Only the first path in a search-list is considered.
    
    1477
    -	 (return (values pathname created-p))))))
    1489
    +	 (return (values pathspec created-p))))))

  • src/code/intl.lisp
    ... ... @@ -105,7 +105,7 @@
    105 105
     
    
    106 106
     (defun find-encoding (domain)
    
    107 107
       (when (null (domain-entry-encoding domain))
    
    108
    -    (setf (domain-entry-encoding domain) :iso-8859-1)
    
    108
    +    (setf (domain-entry-encoding domain) :iso8859-1)
    
    109 109
         ;; Domain lookup can call the compiler, so set the locale to "C"
    
    110 110
         ;; so things work.
    
    111 111
         (let* ((*locale* "C")
    
    ... ... @@ -520,10 +520,7 @@
    520 520
     
    
    521 521
     (defun setlocale (&optional locale)
    
    522 522
       (setf *locale* (or locale
    
    523
    -		     (getenv "LANGUAGE")
    
    524
    -		     (getenv "LC_ALL")
    
    525
    -		     (getenv "LC_MESSAGES")
    
    526
    -		     (getenv "LANG")
    
    523
    +		     (unix::unix-get-lc-messages)
    
    527 524
     		     *locale*)))
    
    528 525
     
    
    529 526
     (defmacro textdomain (domain)
    

  • src/code/irrat.lisp
    ... ... @@ -510,12 +510,12 @@
    510 510
     	     (* base power)
    
    511 511
     	     (exp (* power (* (log2 base 1w0) (log 2w0))))))
    
    512 512
     	(((foreach fixnum (or bignum ratio) single-float)
    
    513
    -	  (foreach (complex single-float)))
    
    513
    +	  (foreach (complex rational) (complex single-float)))
    
    514 514
     	 (if (and (zerop base) (plusp (realpart power)))
    
    515 515
     	     (* base power)
    
    516 516
     	     (exp (* power (log base)))))
    
    517 517
     	(((foreach (complex rational) (complex single-float))
    
    518
    -	  (foreach single-float (complex single-float)))
    
    518
    +	  (foreach single-float (complex rational) (complex single-float)))
    
    519 519
     	 (if (and (zerop base) (plusp (realpart power)))
    
    520 520
     	     (* base power)
    
    521 521
     	     (or (expt-xfrm (coerce base '(complex single-float)) power)
    
    ... ... @@ -537,7 +537,7 @@
    537 537
     		 (exp (* power (log (coerce base '(complex double-double-float))))))))
    
    538 538
     	(((foreach (complex double-float))
    
    539 539
     	  (foreach single-float double-float
    
    540
    -		   (complex single-float) (complex double-float)))
    
    540
    +		   (complex rational) (complex single-float) (complex double-float)))
    
    541 541
     	 (if (and (zerop base) (plusp (realpart power)))
    
    542 542
     	     (* base power)
    
    543 543
     	     (or (expt-xfrm base power)
    
    ... ... @@ -552,7 +552,7 @@
    552 552
     		 (exp (* power (log (coerce base '(complex double-double-float))))))))
    
    553 553
     	#+double-double
    
    554 554
     	(((foreach (complex double-double-float))
    
    555
    -	  (foreach float (complex float)))
    
    555
    +	  (foreach float (complex float) (complex rational)))
    
    556 556
     	 (if (and (zerop base) (plusp (realpart power)))
    
    557 557
     	     (* base power)
    
    558 558
     	     (or (expt-xfrm base power)
    

  • src/code/rand-xoroshiro.lisp
    ... ... @@ -491,8 +491,8 @@
    491 491
         (t
    
    492 492
          (error 'simple-type-error
    
    493 493
     	    :expected-type '(or (integer 1) (float (0.0))) :datum arg
    
    494
    -	    :format-control _"Argument is not a positive integer or a positive float: ~S")
    
    495
    -	    :format-arguments (list arg))))
    
    494
    +	    :format-control _"Argument is not a positive integer or a positive float: ~S"
    
    495
    +	    :format-arguments (list arg)))))
    
    496 496
     
    
    497 497
     ;; Jump function for the generator.  See the jump function in
    
    498 498
     ;; http://xoroshiro.di.unimi.it/xoroshiro128plus.c
    

  • src/code/save.lisp
    ... ... @@ -249,6 +249,10 @@
    249 249
     	     (reinit)
    
    250 250
     	     (environment-init)
    
    251 251
     	     (dolist (f *after-save-initializations*) (funcall f))
    
    252
    +	     ;; Set the runtime locale
    
    253
    +	     (unless (zerop (unix::unix-setlocale))
    
    254
    +	       (warn "os_setlocale failed"))
    
    255
    +	     ;; Set the locale for lisp
    
    252 256
     	     (intl::setlocale)
    
    253 257
     	     (ext::process-command-strings process-command-line)
    
    254 258
     	     (setf *editor-lisp-p* nil)
    

  • src/code/unix.lisp
    ... ... @@ -2896,3 +2896,25 @@
    2896 2896
        of the child in the parent if it works, or NIL and an error number if it
    
    2897 2897
        doesn't work."
    
    2898 2898
       (int-syscall ("fork")))
    
    2899
    +
    
    2900
    +(defun unix-setlocale ()
    
    2901
    +  _N"Call setlocale(3c) with fixed args.  Returns 0 on success."
    
    2902
    +  (alien:alien-funcall
    
    2903
    +   (alien:extern-alien "os_setlocale"
    
    2904
    +		       (function c-call:int))))
    
    2905
    +
    
    2906
    +(defun unix-get-lc-messages ()
    
    2907
    +  _N"Get LC_MESSAGES from the current locale.  If we can't, return
    
    2908
    +  NIL.  A call to UNIX-SETLOCALE must have been done previously before
    
    2909
    +  calling this so that the correct locale is returned."
    
    2910
    +  (with-alien ((buf (array c-call:char 256)))
    
    2911
    +    (let ((result
    
    2912
    +	    (alien-funcall
    
    2913
    +	     (extern-alien "os_get_lc_messages"
    
    2914
    +			   (function c-call:int
    
    2915
    +				     (* c-call:char)
    
    2916
    +				     c-call:int))
    
    2917
    +	     (cast buf (* c-call:char))
    
    2918
    +	     256)))
    
    2919
    +      (when (zerop result)
    
    2920
    +	(cast buf c-call:c-string)))))

  • src/general-info/release-21e.md
    ... ... @@ -22,6 +22,7 @@ public domain.
    22 22
       * Feature enhancements
    
    23 23
       * Changes
    
    24 24
         * Update to ASDF 3.3.6
    
    25
    +    * The default external format is `:utf-8` instead of `:iso8859-1`
    
    25 26
       * ANSI compliance fixes:
    
    26 27
       * Bug fixes:
    
    27 28
         * ~~#97~~ Fixes stepping through the source forms in the debugger.  This has been broken for quite some time, but it works now.
    
    ... ... @@ -50,8 +51,20 @@ public domain.
    50 51
         * ~~#113~~ REQUIRE on contribs can pull in the wrong things via ASDF.
    
    51 52
         * ~~#121~~ Wrong column index in FILL-POINTER-OUTPUT-STREAM
    
    52 53
         * ~~#122~~ gcc 11 can't build cmucl
    
    54
    +    * ~~#124~~ directory with `:wild-inferiors` doesn't descend subdirectories 
    
    55
    +    * ~~#125~~ Linux `unix-stat` returning incorrect values
    
    53 56
         * ~~#127~~ Linux unix-getpwuid segfaults when given non-existent uid.
    
    54 57
         * ~~#128~~ `QUIT` accepts an exit code
    
    58
    +    * ~~#130~~ Move file-author to C 
    
    59
    +    * ~~#132~~ Ansi test `RENAME-FILE.1` no fails
    
    60
    +    * ~~#134~~ Handle the case of `(expt complex complex-rational)`
    
    61
    +    * ~~#136~~ `ensure-directories-exist` should return the given pathspec
    
    62
    +    * #139 `*default-external-format*` defaults to `:utf-8`
    
    63
    +    * ~~#141~~ Disallow locales that are pathnames to a localedef file
    
    64
    +    * ~~#142~~ `(random 0)` signals incorrect error
    
    65
    +    * ~~#147~~ `stream-line-column` method missing for `fundamental-character-output-stream`
    
    66
    +    * ~~#149~~ Call setlocale(3C) on startup
    
    67
    +    * ~~#155~~ Wrap help strings neatly
    
    55 68
       * Other changes:
    
    56 69
       * Improvements to the PCL implementation of CLOS:
    
    57 70
       * Changes to building procedure:
    

  • src/i18n/locale/cmucl-unix.pot
    ... ... @@ -1424,3 +1424,14 @@ msgid ""
    1424 1424
     "   doesn't work."
    
    1425 1425
     msgstr ""
    
    1426 1426
     
    
    1427
    +#: src/code/unix.lisp
    
    1428
    +msgid "Call setlocale(3c) with fixed args.  Returns 0 on success."
    
    1429
    +msgstr ""
    
    1430
    +
    
    1431
    +#: src/code/unix.lisp
    
    1432
    +msgid ""
    
    1433
    +"Get LC_MESSAGES from the current locale.  If we can't, return\n"
    
    1434
    +"  NIL.  A call to UNIX-SETLOCALE must have been done previously before\n"
    
    1435
    +"  calling this so that the correct locale is returned."
    
    1436
    +msgstr ""
    
    1437
    +

  • src/lisp/os-common.c
    ... ... @@ -5,12 +5,17 @@
    5 5
     
    
    6 6
     */
    
    7 7
     
    
    8
    +#include <assert.h>
    
    8 9
     #include <errno.h>
    
    10
    +#include <locale.h>
    
    9 11
     #include <math.h>
    
    10 12
     #include <netdb.h>
    
    13
    +#include <pwd.h>
    
    11 14
     #include <stdio.h>
    
    15
    +#include <stdlib.h>
    
    12 16
     #include <string.h>
    
    13 17
     #include <sys/stat.h>
    
    18
    +#include <unistd.h>
    
    14 19
     #include <time.h>
    
    15 20
     
    
    16 21
     #include "os.h"
    
    ... ... @@ -715,3 +720,79 @@ os_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u
    715 720
     
    
    716 721
         return rc;
    
    717 722
     }
    
    723
    +
    
    724
    +/*
    
    725
    + * Interface for file-author.  Given a pathname, returns a new string
    
    726
    + * holding the author of the file or NULL if some error occurred.  The
    
    727
    + * caller is responsible for freeing the memory used by the string.
    
    728
    + */
    
    729
    +char *
    
    730
    +os_file_author(const char *path)
    
    731
    +{
    
    732
    +    struct stat sb;
    
    733
    +    char initial[1024];
    
    734
    +    char *buffer, *obuffer;
    
    735
    +    size_t size;
    
    736
    +    struct passwd pwd;
    
    737
    +    struct passwd *ppwd;
    
    738
    +    char *result;
    
    739
    +
    
    740
    +    if (stat(path, &sb) != 0) {
    
    741
    +        return NULL;
    
    742
    +    }
    
    743
    +
    
    744
    +    result = NULL;
    
    745
    +    buffer = initial;
    
    746
    +    obuffer = NULL;
    
    747
    +    size = sizeof(initial) / sizeof(initial[0]);
    
    748
    +
    
    749
    +    /*
    
    750
    +     * Keep trying with larger buffers until a maximum is reached.  We
    
    751
    +     * assume (1 << 20) is large enough for any OS.
    
    752
    +     */
    
    753
    +    while (size <= (1 << 20)) {
    
    754
    +        switch (getpwuid_r(sb.st_uid, &pwd, buffer, size, &ppwd)) {
    
    755
    +          case 0:
    
    756
    +              /* Success, though we might not have a matching entry */
    
    757
    +              result = (ppwd == NULL) ? NULL : strdup(pwd.pw_name);
    
    758
    +              goto exit;
    
    759
    +          case ERANGE:
    
    760
    +              /* Buffer is too small, double its size and try again */
    
    761
    +              size *= 2;
    
    762
    +              obuffer = (buffer == initial) ? NULL : buffer;
    
    763
    +              if ((buffer = realloc(obuffer, size)) == NULL) {
    
    764
    +                  goto exit;
    
    765
    +              }
    
    766
    +              continue;
    
    767
    +          default:
    
    768
    +              /* All other errors */
    
    769
    +              goto exit;
    
    770
    +        }
    
    771
    +    }
    
    772
    +exit:
    
    773
    +    free(obuffer);
    
    774
    +    
    
    775
    +    return result;
    
    776
    +}
    
    777
    +
    
    778
    +int
    
    779
    +os_setlocale(void)
    
    780
    +{
    
    781
    +    char *result = setlocale(LC_ALL, "");
    
    782
    +
    
    783
    +    /* Return 0 if setlocale suceeded; otherwise -1. */
    
    784
    +    return result != NULL ? 0 : -1;
    
    785
    +}
    
    786
    +
    
    787
    +int
    
    788
    +os_get_lc_messages(char *buf, int len)
    
    789
    +{
    
    790
    +    char *locale = setlocale(LC_MESSAGES, NULL);
    
    791
    +    if (locale) {
    
    792
    +        strncpy(buf, locale, len - 1);
    
    793
    +        buf[len - 1] = '\0';
    
    794
    +    }
    
    795
    +
    
    796
    +    /* Return -1 if setlocale failed. */
    
    797
    +    return locale ? 0 : -1;
    
    798
    +}

  • src/pcl/gray-streams.lisp
    ... ... @@ -235,6 +235,9 @@
    235 235
       defined for this function, although it is permissible for it to
    
    236 236
       always return NIL."))
    
    237 237
     
    
    238
    +(defmethod stream-line-column ((stream fundamental-character-output-stream))
    
    239
    +  nil)
    
    240
    +
    
    238 241
     ;;; Stream-line-length is a CMUCL extension to Gray streams.
    
    239 242
     (defgeneric stream-line-length (stream)
    
    240 243
       (:documentation _N"Return the stream line length or Nil."))
    

  • src/pcl/simple-streams/external-formats/aliases
    ... ... @@ -223,6 +223,8 @@ windows-cp1252 cp1252
    223 223
     windows-latin1	cp1252
    
    224 224
     ms-ansi		cp1252
    
    225 225
     
    
    226
    +euckr		euc-kr
    
    227
    +cp949		euc-kr
    
    226 228
     ;; These are not yet implemented
    
    227 229
     ;;iso-2022-jp	iso2022-jp
    
    228 230
     ;;iso2022jp	iso2022-jp
    

  • tests/.gitignore
    1
    +/out-utf8.txt

  • tests/filesys.lisp
    ... ... @@ -10,7 +10,7 @@
    10 10
     
    
    11 11
     (define-test unix-namestring.1.exists
    
    12 12
       ;; Make sure the desired directories exist.
    
    13
    -  (assert-equal #P"/tmp/foo/bar/hello.txt"
    
    13
    +  (assert-equal "/tmp/foo/bar/hello.txt"
    
    14 14
     		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
    
    15 15
       (dolist (path '("/tmp/hello.txt"
    
    16 16
     		  "/tmp/foo/"
    
    ... ... @@ -27,7 +27,7 @@
    27 27
     
    
    28 28
     (define-test unix-namestring.1.non-existent
    
    29 29
       ;; Make sure the desired directories exist.
    
    30
    -  (assert-equal #P"/tmp/foo/bar/hello.txt"
    
    30
    +  (assert-equal "/tmp/foo/bar/hello.txt"
    
    31 31
     		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
    
    32 32
       ;; These paths contain directories that don't exist.
    
    33 33
       (dolist (path '("/tmp/oops/"
    
    ... ... @@ -42,7 +42,7 @@
    42 42
     
    
    43 43
     (define-test unix-namestring.2
    
    44 44
       ;; Make sure the desired directories exist.
    
    45
    -  (assert-equal #P"/tmp/foo/bar/hello.txt"
    
    45
    +  (assert-equal "/tmp/foo/bar/hello.txt"
    
    46 46
     		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
    
    47 47
       (unwind-protect
    
    48 48
            (progn
    

  • tests/issues.lisp
    ... ... @@ -5,6 +5,12 @@
    5 5
     
    
    6 6
     (in-package "ISSUES-TESTS")
    
    7 7
     
    
    8
    +(defparameter *test-path*
    
    9
    +  (merge-pathnames (make-pathname :name :unspecific :type :unspecific
    
    10
    +                                  :version :unspecific)
    
    11
    +                   *load-truename*)
    
    12
    +  "Path to where this file is.")
    
    13
    +
    
    8 14
     (defun square (x)
    
    9 15
       (expt x 2))
    
    10 16
     
    
    ... ... @@ -580,6 +586,96 @@
    580 586
     	while user-info
    
    581 587
     	finally (assert-false user-info)))
    
    582 588
     
    
    589
    +(define-test issue.132.1
    
    590
    +    (:tag :issues)
    
    591
    +  ;; From a message on cmucl-imp 2008/06/01.  If "d1" is a directory,
    
    592
    +  ;; (rename "d1" "d2") should rename the directory "d1" to "d2".
    
    593
    +  ;; Previously that produced an error trying to rename "d1" to
    
    594
    +  ;; "d1/d2".
    
    595
    +  ;;
    
    596
    +  ;; Create the test directory (that is a subdirectory of "dir").
    
    597
    +  (assert-true (ensure-directories-exist "dir/orig-dir/"))
    
    598
    +  (let ((*default-pathname-defaults* (merge-pathnames "dir/" (ext:default-directory))))
    
    599
    +    (multiple-value-bind (defaulted-new-name old-truename new-truename)
    
    600
    +	;; Rename "dir/orig-dir" to "orig/new-dir".
    
    601
    +	(rename-file "orig-dir/" "new-dir")
    
    602
    +      (let ((orig (merge-pathnames
    
    603
    +		   (make-pathname :directory '(:relative "orig-dir"))))
    
    604
    +	    (new (merge-pathnames
    
    605
    +		  (make-pathname :directory '(:relative "new-dir")))))
    
    606
    +	;; Ensure that the rename worked and that the returned values
    
    607
    +	;; have the expected values.
    
    608
    +	(assert-true defaulted-new-name)
    
    609
    +	(assert-equalp old-truename orig)
    
    610
    +	(assert-equalp new-truename new)))))
    
    611
    +
    
    612
    +(define-test issue.132.2
    
    613
    +    (:tag :issues)
    
    614
    +  (assert-true (ensure-directories-exist "dir/orig.dir/"))
    
    615
    +  (let ((*default-pathname-defaults* (merge-pathnames "dir/" (ext:default-directory))))
    
    616
    +    (multiple-value-bind (defaulted-new-name old-truename new-truename)
    
    617
    +	;; Rename "dir/orig.dir" to "orig/new-dir".  Since the
    
    618
    +	;; original name has a pathname-name of "orig" and a
    
    619
    +	;; pathname-type of "dir", the new file name is merged to
    
    620
    +	;; produce a pathname-name of "new" with a pathname-type of
    
    621
    +	;; "dir".
    
    622
    +	(rename-file "orig.dir" "new")
    
    623
    +      (let ((orig (merge-pathnames
    
    624
    +		   (make-pathname :directory '(:relative "orig.dir"))))
    
    625
    +	    (new (merge-pathnames
    
    626
    +		  (make-pathname :directory '(:relative "new.dir")))))
    
    627
    +	;; Ensure that the rename worked and that the returned values
    
    628
    +	;; have the expected values.
    
    629
    +	(assert-true defaulted-new-name)
    
    630
    +	(assert-equalp old-truename orig)
    
    631
    +	(assert-equalp new-truename new)))))
    
    632
    +
    
    633
    +(define-test issue.132.3
    
    634
    +    (:tag :issues)
    
    635
    +  (assert-true (ensure-directories-exist "dir/orig.dir/"))
    
    636
    +  (let ((*default-pathname-defaults* (merge-pathnames "dir/" (ext:default-directory))))
    
    637
    +    (multiple-value-bind (defaulted-new-name old-truename new-truename)
    
    638
    +	;; Rename "dir/orig.dir/" to "orig/new".  Note that the
    
    639
    +	;; original name is "orig.dir/" which marks a directory so
    
    640
    +	;; that when we merge the new name with the old to fill in
    
    641
    +	;; missing components, there are none because the old name is
    
    642
    +	;; a directory with no pathname-name or pathname-type, so the
    
    643
    +	;; new name stays the same.
    
    644
    +	(rename-file "orig.dir/" "new")
    
    645
    +      (let ((orig (merge-pathnames
    
    646
    +		   (make-pathname :directory '(:relative "orig.dir"))))
    
    647
    +	    (new (merge-pathnames
    
    648
    +		  (make-pathname :directory '(:relative "new")))))
    
    649
    +	;; Ensure that the rename worked and that the returned values
    
    650
    +	;; have the expected values.
    
    651
    +	(assert-true defaulted-new-name)
    
    652
    +	(assert-equalp old-truename orig)
    
    653
    +	(assert-equalp new-truename new)))))
    
    654
    +
    
    655
    +(define-test issue.134
    
    656
    +    (:tag :issues)
    
    657
    +  ;; Verify that we can compute (3+4*%i)^%i (in Maxima format).  This
    
    658
    +  ;; can be written analytically as
    
    659
    +  ;; %i*%e^-atan(4/3)*sin(log(5))+%e^-atan(4/3)*cos(log(5)), so use
    
    660
    +  ;; %this as the reference value.
    
    661
    +  (let ((answer (complex (* (cos (log 5w0))
    
    662
    +			    (exp (- (atan (float (/ 4 3) 0w0)))))
    
    663
    +			 (* (sin (log 5w0))
    
    664
    +			    (exp (- (atan (float (/ 4 3) 0w0))))))))
    
    665
    +    (flet ((relerr (actual true)
    
    666
    +	     ;; Return the relative error between ACTUAL and TRUE
    
    667
    +	     (/ (abs (- actual true))
    
    668
    +		(abs true))))
    
    669
    +      (dolist (test '((#c(3 4) 3.5918w-8)
    
    670
    +		      (#c(3.0 4) 3.5918w-8)
    
    671
    +		      (#c(3d0 4) 9.2977w-17)
    
    672
    +		      (#c(3w0 4) 0w0)))
    
    673
    +	(destructuring-bind (base eps)
    
    674
    +	    test
    
    675
    +	  (let* ((value (expt base #c(0 1)))
    
    676
    +		 (err (relerr value answer)))
    
    677
    +	    (assert-true (<= err eps) base err eps)))))))
    
    678
    +
    
    583 679
     (define-test issue-139.1
    
    584 680
         (:tag :issues)
    
    585 681
       ;; Verify the value of the default external format and that system streams use :utf-8.
    
    ... ... @@ -600,3 +696,80 @@
    600 696
       (with-open-file (s "test-format.txt" :direction :input)
    
    601 697
         (let ((c (read-char s)))
    
    602 698
           (assert-equal #\u+3b1 c))))
    
    699
    +
    
    700
    +(define-test issue.130
    
    701
    +    (:tag :issues)
    
    702
    +  ;; Just verify that file-author works.  In particular "." should
    
    703
    +  ;; work and not return NIL.
    
    704
    +  (assert-true (file-author "."))
    
    705
    +  (assert-true (file-author "bin/build.sh"))
    
    706
    +  (let ((unix::*filename-encoding* :utf-8))
    
    707
    +    ;; Set filename encoding to utf-8 so that we can encode the
    
    708
    +    ;; filename properly.
    
    709
    +    (assert-true
    
    710
    +   (file-author
    
    711
    +    (merge-pathnames 
    
    712
    +     (concatenate 'string
    
    713
    +		  ;; Write the test file name this way so
    
    714
    +		  ;; that it's independent of the encoding
    
    715
    +		  ;; used to load this file.  The name is
    
    716
    +		  ;; "안녕하십니까".
    
    717
    +		  '(#\Hangul_Syllable_An #\Hangul_Syllable_Nyeong #\Hangul_Syllable_Ha
    
    718
    +		    #\Hangul_Syllable_Sib #\Hangul_Syllable_Ni #\Hangul_Syllable_Gga)
    
    719
    +		  ".txt")
    
    720
    +     *test-path*)))))
    
    721
    +
    
    722
    +(define-test issue.139-default-external-format
    
    723
    +    (:tag :issues)
    
    724
    +  (assert-eq :utf-8 stream:*default-external-format*))
    
    725
    +
    
    726
    +(define-test issue.139-default-external-format-read-file
    
    727
    +    (:tag :issues)
    
    728
    +  (let ((string (concatenate 'string
    
    729
    +			     ;; This is "hello" in Korean
    
    730
    +			     '(#\Hangul_syllable_an
    
    731
    +			       #\Hangul_Syllable_Nyeong
    
    732
    +			       #\Hangul_Syllable_Ha
    
    733
    +			       #\Hangul_Syllable_Se
    
    734
    +			       #\Hangul_Syllable_Yo))))
    
    735
    +    ;; Test that opening a file for reading uses the the default :utf8
    
    736
    +    ;; encoding.
    
    737
    +    (with-open-file (s (merge-pathnames "utf8.txt"
    
    738
    +					*test-path*)
    
    739
    +		       :direction :input)
    
    740
    +      ;; The first line should be "hello" in Hangul.
    
    741
    +      (assert-equal (map 'list #'char-name string)
    
    742
    +		    (map 'list #'char-name (read-line s))))))
    
    743
    +
    
    744
    +(define-test issue.139-default-external-format-write-file
    
    745
    +    (:tag :issues)
    
    746
    +  ;; Test that opening a file for writing uses the default :utf8.
    
    747
    +  ;; First write something out to the file.  Then read it back in
    
    748
    +  ;; using an explicit format of utf8 and verifying that we got the
    
    749
    +  ;; right contents.
    
    750
    +  (let ((string (concatenate 'string
    
    751
    +			     ;; This is "hello" in Korean
    
    752
    +			     '(#\Hangul_syllable_an
    
    753
    +			       #\Hangul_Syllable_Nyeong
    
    754
    +			       #\Hangul_Syllable_Ha
    
    755
    +			       #\Hangul_Syllable_Se
    
    756
    +			       #\Hangul_Syllable_Yo))))
    
    757
    +    (with-open-file (s (merge-pathnames "out-utf8.txt"
    
    758
    +					*test-path*)
    
    759
    +		       :direction :output
    
    760
    +		       :if-exists :supersede)
    
    761
    +      (write-line string s))
    
    762
    +    (with-open-file (s (merge-pathnames "out-utf8.txt"
    
    763
    +					*test-path*)
    
    764
    +		       :direction :input
    
    765
    +		       :external-format :utf-8)
    
    766
    +      (assert-equal (map 'list #'char-name string)
    
    767
    +		    (map 'list #'char-name (read-line s))))))
    
    768
    +  
    
    769
    +
    
    770
    +(define-test issue.150
    
    771
    +    (:tag :issues)
    
    772
    +  (let ((ext:*gc-verbose* nil)
    
    773
    +	(*compile-print* nil))
    
    774
    +    (assert-true (stream::find-external-format :euckr))
    
    775
    +    (assert-true (stream::find-external-format :cp949))))

  • tests/utf8.txt
    1
    +안녕하세요
    
    2
    +UTF8 test.  The above line is "Hello" in Hangul.

  • tests/안녕하십니까.txt
    1
    +The file name of this file is "안녕하십니까.txt" ("Hello" in Korean.)
    
    2
    +
    
    3
    +