changeset 21601:25fd18a15a6c

version.m: Use more Octave coding standards. * version.m: Improve docstring. Match variables in function prototype to those in documentation. Use parentheses to indicate a function call. Use documented variable names in error messages. Use semicolons to end assert statements when they are within a BIST block. Add input validation tests.
author Rik <rik@octave.org>
date Sun, 10 Apr 2016 20:18:22 -0700
parents 184b85b31e03
children 47c76e56a1de
files scripts/miscellaneous/version.m
diffstat 1 files changed, 33 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/version.m	Sun Apr 10 15:33:43 2016 -0400
+++ b/scripts/miscellaneous/version.m	Sun Apr 10 20:18:22 2016 -0700
@@ -20,19 +20,20 @@
 ## @deftypefn  {} {@var{v} =} version ()
 ## @deftypefnx {} {[@var{v}, @var{d}] =} version ()
 ## @deftypefnx {} {@var{v} =} version (@var{feature})
-## Get version information for Octave
+## Get version information for Octave.
 ##
 ## If called without input argument, the first return value @var{v} gives the
-## version number of Octave as a string. The second return value @var{d} holds
+## version number of Octave as a string.  The second return value @var{d} holds
 ## the release date as a string.
 ##
 ## The following options can be passed for @var{feature}:
+##
 ## @table @asis
 ## @item @qcode{"-date"}
 ## for the release date of the running build,
 ##
 ## @item @qcode{"-description"}
-## for a description of the release (empty string),
+## for a description of the release (always an empty string),
 ##
 ## @item @qcode{"-release"}
 ## for the name of the running build,
@@ -41,13 +42,13 @@
 ## for version information of the Java VM,
 ##
 ## @item @qcode{"-fftw"}
-## for version information for the linked FFTW,
+## for version information for the linked @sc{fftw},
 ##
 ## @item @qcode{"-blas"}
-## for version information for the linked BLAS (not implemented),
+## for version information for the linked @sc{blas} (not implemented),
 ##
 ## @item @qcode{"-lapack"}
-## for version information for the linked LAPACK (not implemented).
+## for version information for the linked @sc{lapack} (not implemented).
 ## @end table
 ##
 ## The variant with no input and output argument is an alias for the function
@@ -57,14 +58,14 @@
 
 ## Author: jwe
 
-function [vs, d] = version (feature)
+function [v, d] = version (feature)
 
   if (nargin > 1 || ((nargin != 0) && ((nargout > 1) || ! ischar (feature))))
     print_usage ();
   endif
 
   if (nargin == 0)
-    vs = OCTAVE_VERSION;
+    v = OCTAVE_VERSION ();
 
     if (nargout > 1)
       d = __octave_config_info__ ("release_date");
@@ -72,11 +73,11 @@
   else
     switch (feature)
       case "-date"
-        vs = __octave_config_info__ ("release_date");
+        v = __octave_config_info__ ("release_date");
       case "-description"
-        vs = "";
+        v = "";
       case "-release"
-        vs = "";
+        v = "";
       case "-java"
         try
           jversion = javaMethod ("getProperty", "java.lang.System", ...
@@ -84,35 +85,43 @@
           jvendor = javaMethod ("getProperty", "java.lang.System", ...
                                 "java.vendor");
           jname = javaMethod ("getProperty", "java.lang.System", ...
-                                "java.vm.name");
+                              "java.vm.name");
           jjitmode = javaMethod ("getProperty", "java.lang.System", ...
-                                "java.vm.info");
-          vs = ["Java " jversion " with " jvendor " " jname " " jjitmode];
+                                 "java.vm.info");
+          v = ["Java " jversion " with " jvendor " " jname " " jjitmode];
         catch
-          vs = "no java available";
+          v = "no java available";
         end_try_catch
       case "-fftw"
-        vs = __octave_config_info__ ("fftw_version");
+        v = __octave_config_info__ ("fftw_version");
       case "-blas"
-        vs = "";
-        warning(["version: option '" feature "' not implemented"])
+        v = "";
+        warning ("version: option '-blas' not implemented");
       case "-lapack"
-        vs = "";
-        warning(["version: option '" feature "' not implemented"])
+        v = "";
+        warning ("version: option '-lapack' not implemented");
       otherwise
-        error ("version: Invalid input argument");
+        error ("version: invalid FEATURE");
     endswitch
   endif
 
 endfunction
 
+
 %!assert (ischar (version ()))
 
 %!test
 %! [v, d] = version ();
-%! assert (v, OCTAVE_VERSION)
-%! assert (d, __octave_config_info__ ("release_date"))
+%! assert (v, OCTAVE_VERSION);
+%! assert (d, __octave_config_info__ ("release_date"));
 
 %!assert (version ("-date"), __octave_config_info__ ("release_date"))
 
-%!error version (1);
+## Test input validation
+%!error version ("-date", "-release")
+%!error [v, d] = version ("-date")
+%!error version (1)
+%!warning <option '-blas' not implemented> version ("-blas"); 
+%!warning <option '-lapack' not implemented> version ("-lapack"); 
+%!error <invalid FEATURE> version ("-foobar")
+