octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Changeset] new bzip2 function


From: Thorsten Meyer
Subject: Re: [Changeset] new bzip2 function
Date: Thu, 01 Jan 2009 11:32:22 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Hi,

John W. Eaton wrote:
> +      error (sprintf("%s: extension has to be a string with finite length",
> +                     commandname));
>
> There's no need to use sprintf here since error already understands
> format strings.  So you should write
>
>   error ("%s: extension has to be a string with finite length", commandname);
>   
Thanks for the hint.

Attached, you will find a little patch which fixes the error messages in
__xzip__ and adds a few tests of the error handling.

regards

Thorsten
# HG changeset patch
# User Thorsten Meyer <address@hidden>
# Date 1230805458 -3600
# Node ID 8f1edcf346b6e2f00b44becaffb62304ed53fab0
# Parent  628b6973b9fe1460dd88176f837d48bb39e07f3d
Fix error messages in __xzip__

diff -r 628b6973b9fe -r 8f1edcf346b6 scripts/ChangeLog
--- a/scripts/ChangeLog Mon Dec 29 11:21:42 2008 +0100
+++ b/scripts/ChangeLog Thu Jan 01 11:24:18 2009 +0100
@@ -0,0 +1,4 @@
+2009-01-01  Thorsten Meyer  <address@hidden>
+
+       * miscellaneous/__xzip__.m: Fix error messages, add tests.
+       
diff -r 628b6973b9fe -r 8f1edcf346b6 scripts/miscellaneous/__xzip__.m
--- a/scripts/miscellaneous/__xzip__.m  Mon Dec 29 11:21:42 2008 +0100
+++ b/scripts/miscellaneous/__xzip__.m  Thu Jan 01 11:24:18 2009 +0100
@@ -34,8 +34,7 @@
 
   if (nargin == 4 || nargin == 5)
     if (! ischar (extension) || length (extension) == 0)
-      error (sprintf("%s: extension has to be a string with finite length",
-                     commandname));
+      error ("__xzip__: extension has to be a string with finite length");
     endif
     
     if (nargin == 5 && ! exist (outdir, "dir"))
@@ -83,15 +82,15 @@
           ## FIXME this does not work when you try to compress directories
 
           compressed_files  = cellfun(@(x) sprintf ("%s.%s", x, extension), 
-                            files, "UniformOutput", false);
+                                      files, "UniformOutput", false);
         endif
 
         if (nargout > 0)
           entries = compressed_files;
         endif
       else
-        error (sprintf("%s command failed with exit status = %d", 
-                       commandname, status));
+        error ("%s command failed with exit status = %d",
+               commandname, status);
       endif
     unwind_protect_cleanup
       cd(cwd);
@@ -119,3 +118,22 @@
   d(idx) = "";
   f(idx) = files(idx);
 endfunction
+
+%!error <extension has to be a string with finite length> 
+%!  __xzip__("gzip", "", "gzip -r %s", "bla");
+%!error <no files to move>
+%!  __xzip__("gzip", ".gz", "gzip -r %s", tmpnam);
+%!error <command failed with exit status>
+%!  # test __xzip__ with invalid compression command
+%!  unwind_protect
+%!    filename = tmpnam;
+%!    dummy    = 1;
+%!    save(filename, "dummy");
+%!    dirname  = tmpnam;
+%!    mkdir(dirname);
+%!    entry = __xzip__("gzip", ".gz", "xxxzipxxx -r %s 2>/dev/null", 
+%!                     filename, dirname);
+%!  unwind_protect_cleanup
+%!    delete(filename);
+%!    rmdir(dirname);
+%!  end_unwind_protect

reply via email to

[Prev in Thread] Current Thread [Next in Thread]