jed-users mailing list

[2006 Date Index] [2006 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Jed mode testing


Dear Jed Users,

does anyone have experience or a framework for testing Jed modes?

Would the TESS module work with JED? Is it still up to date or is it
preferable to use SLang 2 try/catch syntax? 


Below is my first attempt for a Jed testing framework. Comments welcome.

Guenter




% unittest.sl: Unit testing of SLang code
% 
% Copyright (c) 2006 Günter Milde
% Released under the terms of the GNU General Public License (ver. 2 or later)
%
% This script needs SLang 2
% 
% Versions:
% 0.1 2006-03-03 proof of concept

_debug_info = 1;

private variable ex, reportbuf = "*test report*";

% A new exception class for Assertions
!if (is_defined("AssertionError"))
  new_exception ("AssertionError", AnyError, "False Assertion");


define assert(a)
{
   !if (a)
     throw AssertionError, sprintf("%S not true", a);
}

define assert_equal(a, b)
{
   if (a != b)
     throw AssertionError, sprintf("%S != %S", a, b);
}


% vinsert the args into a test report buffer
public define testmessage() % (fmt, ...)
{
   variable buf = whatbuf(), args = __pop_args(_NARGS);
   sw2buf(reportbuf);
   set_readonly(0);
   eob;
   vinsert(__push_args(args));
   set_buffer_modified_flag(0);
   % view_mode();
   sw2buf(buf);
}

% evaluate file and report exceptions return no of catched exceptions
public define run_test(file)
{
   testmessage("%s: ", path_basename(file));
   try (ex)
     {
        () = evalfile(file);
        testmessage("OK\n");
        return 0;
     }
   catch AnyError:
     {
        testmessage("%s in %s:%d, %s\n", 
                     ex.descr, ex.file, ex.line, ex.message);
        return 1;
     }
}

% evaluate all *test*.sl files in dir
public define run_tests(dir)
{
   if (file_status(dir) != 2)
     verror("directory '%s' doesnot exist", dir);
   
   variable result, filter, files = listdir(dir);
   
   !if (length(files))
     verror("no files in '%s'", dir);
   
   % filter and sort files
   filter = where(array_map(String_Type, &path_extname, files) == ".sl"
     and array_map(Int_Type, &is_substr, files, "test"));
   % show(files, filter, files[filter]);
   files = files[array_sort(files[filter])];
   files = array_map(String_Type, &path_concat, dir, files);
   % show(files);

   testmessage("\ntesting %d files in '%s'\n\n", length(files), dir);
   flush(sprintf("testing %d files in %s", length(files), dir));

   result = array_map(Int_Type, &run_test, files);

   testmessage("%d exceptions catched\n", length(where(result)));
   vmessage("%d tests, %d exceptions catched\n",
             length(files), length(where(result)));

   return length(where(result));
   
}


#stop

% Test the test:

() = run_tests("test");

() = run_test("test/arraytest.sl");

try (ex)
     {
        assert_equal(1,3.5);
        assert("foo");
     }
catch AnyError:
     {
        testmessage("%S: %s, generated by %s:%d",
                  ex.error, ex.descr, ex.file, ex.line);
        testmessage("   %s", ex.message);
     }

testmessage("end");



--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2006 date index] [2006 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]