f



(assert-error) tests errors and error messages

I wrote (assert-error) to make sure that a function generates an
error, and verify the error message. What do you think? Below is the
definition and a few test cases, for Emacs 22.1.50.

(require 'cl)

(defmacro assert-error (form &optional regexp)
  "FORM must signal an error. Signal an error otherwise.
Additionally, the error message must match REGEXP.
Case is ignored while matching REGEXP."
  (let ((msg (make-symbol "msg"))
        (ok (make-symbol "ok"))
        (res (make-symbol "res")))
    `(let ((,ok nil))
       (condition-case err
           ;; Evaluate FORM and save the result.
           (set ',res ,form)
         (error
          ;; This runs when FORM signals an error of any kind.
          (set ',ok t)
          (set ',msg (error-message-string err))))
       (unless ,ok
         (error "Did not signal an error: %s (returned %s)"
',form ,res))
       (when ,regexp
         ;; Here we know that FORM signaled an error, and that the
         ;; caller wants to check the error message.
         (unless
             (let ((case-fold-search t))
               (string-match ,regexp ,msg))
           (error "Error message does not match \"%s\": \"%s\""
                  ,regexp ,msg))))))

;; Test assert-error, mostly by running it against itself.
(assert-error (assert-error nil) "did not signal.*nil")
(assert-error (assert-error t) "\\bt\\b")
(assert-error (assert-error (+ 100 200)) "did not.*100.*200.*300")
(assert-error (assert-error (+ 1 2) "something"))
(assert-error (error "Ups"))
;; Verify regexp matching.
(assert-error (error "Ups") "Ups")
(assert-error (error "Ups") "UPS")
(assert-error (error "Ups") "u.?S")
(assert-error (assert-error (error "Ups") "^ps")
              "does not match.*^ps.*Ups")
(assert-error (error "Ups") "")
(assert-error (assert nil))
(assert-error (assert nil) "assert.*fail")
;; Verify the error message generated by assert-error.
(assert-error (assert-error (assert-error nil) "foo"))
(assert-error (assert-error (assert-error nil) "foo")
              "error message.*foo.*did not signal.*nil")
;; Verify nested assert-error.
(assert-error (assert-error (assert-error (assert-error nil) "foo")
"bar")
              "bar.*foo.*nil")
;; Verify that the uninterned symbols used by assert-error cannot be
;; modified by FORM.
(assert-error (let ((ok t)) (assert-error (set 'ok t))))
(assert-error (let ((err nil)) (assert-error (set 'err nil) "foo")))
;; Verify that an invalid REGEXP signals an error.
(assert-error (assert-error (assert nil) t) "wrong type")
0
engeler (56)
12/24/2007 4:33:52 PM
comp.emacs 4822 articles. 1 followers. Post Follow

0 Replies
1398 Views

Similar Articles

[PageSpeed] 13

Reply:

Similar Artilces:

When is an error not an error?
When it's OSS slopware, of course. http://www.angelfire.com/planet/dfs0/Knode_send_error.png On 2006-09-12 02:42, * DFS wrote: > When it's OSS slopware, of course. > > http://www.angelfire.com/planet/dfs0/Knode_send_error.png > Well, some time ago I had a problem with OE - too long reference line to other posts, and OE of course refused to send... then crashed. Should I name it a feature? -- Andrea On Tue, 12 Sep 2006 03:25:29 +0200, Andrea wrote: > On 2006-09-12 02:42, * DFS wrote: >> When it's OSS slopware, of course. >> >> http:/...

When is an error not an error?
The Java language specification claims in: 8.8.7.1 Explicit Constructor Invocations .... "If an anonymous class instance creation expression appears within an explicit constructor invocation statement, then the anonymous class may not refer to any of the enclosing instances of the class whose constructor is being invoked." Helpfully it gives an example: "For example: class Top { int x; class Dummy { Dummy(Object o) {} } class Inside extends Dummy { Inside() { super(new Object() { int r = x; }); // err...

error or not an error ...
I was just testing out the R4 REXX thingy, and it found an error in the following program. My question is this, is it an error or not? My PC/REXX and Regina don't barf on it, but I thought they should've. _____________________________________________ /**/ ?.='' ?.z='batman' trace i if ?.z\==''then do; say '?.z=' ?.z; end ______________________________________________ Note that there is space before the THEN. I'm not sure of the exact rules for parsing an IF statement, I know that THEN is a "reserved" keyword when an IF statement is...

Objc Nubie: Errors Errors Errors
I've been toying with learning ObjC/Cocoa for sometime and finally got over the hump of "brackets vs. braces" but am wondering why my little test throws so many warnings when run: // gcc FileTest.m -o FileTest -ObjC -framework Cocoa #include <Cocoa/Cocoa.h> #include <Foundation/Foundation.h> int main( void ) { NSString * str = [ [NSStringalloc] initWithString:@"~/samplefromcocoa.txt" ]; NSString * full = [ NSString stringWithString: [str stringByExpandingTildeInPath ] ]; if( [ [NSFileManager defaultManager] fileExistsAtPath:full ] ) { NSLog( @"File %@ exists", str ); } else { NSString * contents = [ [NSString alloc] initWithString:@"Created by FileTest.m" ]; BOOL didWrite = [contents writeToFile:full atomically:NO]; if( didWrite ) { NSLog( @"Creating File %@", str ); } else { NSLog( @"Unable to create file %@", str ); } } return 0; } when run and it has to write the string to disk> 2004-02-11 08:27:03.882 FileTest[2082] *** _NSAutoreleaseNoPool(): Object 0x50d6f0 of class NSCFString autoreleased with no pool in place - just leaking 2004-02-11 08:27:03.885 FileTest[2082] *** _NSAutoreleaseNoPool(): Object 0x50dc80 of class NSPathStore2 autoreleased with no pool in place - just leaking 2004-02-11 08:27:03.887 FileTest[2082] ...

error vb : 3000 : Reserved error (-5400) there is no message for this error
Hello, i have a problem when i connect an access 97 database with an text file "3000 Reserved error (-5400); there is no message for this error." The attachment is an example of a textfile that i want to connect through vb 6.0 vb code : strtable = "FileName" strconnect = "Text;HDR=NO;IMEX=2;FMT=Fixed;Database=c:\temp" strSourcetable = "MAILGV2939.TXT" Set tdfLinked = dbsTemp.CreateTableDef(strTable) tdfLinked.Connect = strConnect tdfLinked.SourceTableName = strSourceTable dbsTemp.TableDefs.Append tdfLinked what is the solution to this pro...

When using "error" should the error message and error information be the same?
I wrote a Tcl package for a proprietary product which makes heavy usage of the "error" command. To this time when I return an error I use the command set errMsg "An Error Message" error $errMsg $errMsg I was wondering if maybe I was using the arguments incorrectly here or if in reality there is no real difference between the two other than when it is available to the user (along with the returned stack when using $errorInfo). Eddie Borjas wrote: > I wrote a Tcl package for a proprietary product which makes heavy > usage of the "error" command. To this time when I return an error I > use the command > > set errMsg "An Error Message" > error $errMsg $errMsg > > I was wondering if maybe I was using the arguments incorrectly here or > if in reality there is no real difference between the two other than > when it is available to the user (along with the returned stack when > using $errorInfo). First off, consider using the newer [return -error] construct instead of [error]. Now to answer your question, IMHO no they should not be the same. The return value should be a nice user level error message. The errorInfo part should also be human readable, but aimed at a programmer. Lastly, IMHO you should always be giving the errorCode value, which should be a list that is designed to be more "program" friendly. -- +------------------------------------------------------------------------+ | G...

Error Number 3000: Reserved Error (-3002); there is no message for this error
Help... I've been moving code about to tidy it up and this error is occuring. I have tracked it down to a set querydef command, i have properly specified a database and am using correct syntax for the set command but this error is popping up. Any ideas why? Please help....... Rob. Try to decompile the database (command-line switch /decompile) dkintheuk wrote: > Help... > > I've been moving code about to tidy it up and this error is occuring. > > I have tracked it down to a set querydef command, i have properly > specified a database and am using correct syn...

Error: AgentSocketPullInput error message
Hello all... I'm getting the following message repeated in the /var/adm/snmpd.log on HP-UX 11.11 server: AgentSocketPullInput: short read pending on socket close, data discarded at line 491 in file ../common.c I've been surfing around for the info but haven't had any luck finding a reference to this error message and what it might mean? I've done a stare 'n compare against a working snmpd.conf that's working just fine. Would anybody have a cluegram as to where I can look for some idea what this message is telling me...? ...

Error returned with no error message
Hi All, I am trying to access a Transform Data Task in a DTS by double clicking it. When I do, I get a message similar to "HResult of 0x80004005 (-2147467259) returned Unexpected error occurred. An error was returned without an error message" and the properties screen does not appear. Firstly this has got to be the most useless alert ever to appear on my screen, but more importantly what can I do about it? I cannot execute the step either as I get the same message. I thought that the DTS may have become corrupted but it is also happening when I create new DTS packages. Can...

Error directing BCP In errors to error file
Greetings, I am trying to bcp in data to a table which is in different server . Though the bcp in works fine but the error file is not being created and rejected records are not being directyd to the error file. Query looks like: bcp <db>..test_b_plan_cp in /home/file_out.txt -c -t '|' -S *****-U ****** -P ******-I /home/bcp2db_sql.ini -e /home/bcp2db.error. Can someone please help? TIA. Regards, Rajpreet ...

error C2106: error C2057 :error C3304:
I have faced intrinsic errors "error C2106 / error C2057 / error C3304" in Visual studio 2008. Though the source files have included with header files like "math.h" and "ctype.h", compilation gives error as given below. 2>c:\apps\microsoft visual studio 9.0\vc\include\string.h(48) : error C2106: '=' : left operand must be l-value 2>c:\apps\microsoft visual studio 9.0\vc\include\string.h(48) : error C2057: expected constant expression 2>c:\apps\microsoft visual studio 9.0\vc\include\string.h(48) : error C3304: 'PreAttribute': at...

Error Directing BCP In Errors to error file
Greetings, I am trying to bcp in data to a table which is in different server. Though the bcp in works fine but the error file is not being created and rejected records are not being directyd to the error file. Query looks like: bcp <db>..test_b_plan_cp in /home/file_out.txt -c -t '|' -S *****-U ****** -P ******-I /home/bcp2db_sql.ini -e /home/bcp2db.error. Can someone please help? TIA. Regards, Rajpreet ...

Error 8 Compilation Error. File permission error or DMA hardware error detected
I just upgraded my Labview code to Labview 8.5 from LV8.2.1 Then I tried to compile&nbsp;my code to get an .exe file I keep getting the following error, &nbsp; Visit the Request Support page at ni.com/ask to learn more about resolving this problem. Use the following information as a reference: Error 8 occurred at Write to Text File in AB_Engine_Update_INI_Header.vi-&gt;AB_Application.lvclass:Create_INI_File.vi-&gt;AB_Application.lvclass:Copy_Files.vi-&gt;AB_Build.lvclass:Build.vi-&gt;AB_EXE.lvclass:Build.vi-&gt;AB_Build.lvclass:Build_from_Wizard.vi-&gt;AB_UI_FR...

"Oracle error occurred, but error message could not be retrieved from Oracle" error when restarting application
Hi, we're using Oracle 10g, in combination with Delphi (7). Application uses Oracle client dll (oraociei10.dll). Quick explenation about the structure (All files are on the network): - A launcher application is started by the client. The launcher application checks an .ini file for the current application versie (.exe filename with a version postfix, e.g. "Application_112.exe"). The launcher starts the executable specified in the .ini file. In this way we can "release" by putting a new .exe file and updating the .ini file. The problem: In our application we've ...

Robust error handling, an error while handling another error
I've been having this discussion a lot with my colleagues at work. A buffered file writer is the classic example. #include <fstream> int main() { std::ofstream fout("foo.txt"); if ( ! fout) return 1; //write important data to file //let the destructor implicitly close the file handle } The ofstream destructor will call flush then free the file handle, return it to the operating system. However, flush can fail. The disk can be full, for example. When flush fails, it sets a state flag, but there is no opportunity for the user to examine this state fl...

error in, error out clusters.
Dear all, &nbsp; I am new user for Labview software. I try to create a Visa Configuration Serial Port but, the error occurred, message&nbsp;as: &nbsp; "You have two or more cluster data types wired together, but the clusters have different kinds or numbers of elements.Cluster Cluster 2, a cluster of 1 element, conflicts with cluster error in (no error), a cluster of 3 elements." &nbsp; My cluster include the function of: 1) boolean Properties 2) Numeric Properties 3) String Properties &nbsp; Q:&nbsp;how to create these 3 function in&nbsp;cluster? ...

SQL Errors: Where is the error?
I have just finished -- I hope I have finished -- some changes to one program of mine that has some hairy SQL. One of the SQL statments is 40 lines long. Granted it could be shorter vertically, but it is still 852 characters long. Occasionally -- read "All too often" -- while wrestling with this program, there would be an error in my SQL syntax. VFP is not terribly helpful with such error messages as Syntax error. Command is missing required clause. These are not terribly useful. Sometimes, I have hunted for minutes before realising that...

timemachine error 11 (Error: (-36), Error: (-50))
I have a problem with Time machine exiting with error 11 rcently. > 6/8/09 3:26:32 PM /System/Library/CoreServices/backupd[795] Starting standard backup > 6/8/09 3:26:32 PM /System/Library/CoreServices/backupd[795] Backing up to: /Volumes/Time Machine Backups/Backups.backupdb > 6/8/09 3:27:37 PM /System/Library/CoreServices/backupd[795] No pre-backup thinning needed: 52.59 GB requested (including padding), 87.39 GB available > 6/8/09 3:28:57 PM /System/Library/CoreServices/backupd[795] Copied 1543 files (65.7 MB) from volume VadeMACum BootHD. > 6/8/09 3:48:09 PM /System/Library/CoreServices/backupd[795] Error: (-36) SrcErr:YES Copying /Volumes/HD3/Virtual Machines/Windows XP Professional.vmwarevm/Windows XP Professional.vmdk to (null) > 6/8/09 3:48:09 PM /System/Library/CoreServices/backupd[795] Error: (-50) SrcErr:NO Copying /Volumes/HD3/Virtual Machines/Windows XP Professional.vmwarevm/Windows XP Professional.vmdk to /Volumes/Time Machine Backups/Backups.backupdb/vademacum/2009-07-30-163253.inProgress/4AE47B8C-446F-494C-A823-F38BDA3C3F11/HD3/Virtual Machines/Windows XP Professional.vmwarevm > 6/8/09 3:48:09 PM /System/Library/CoreServices/backupd[795] Stopping backup. > 6/8/09 3:48:09 PM /System/Library/CoreServices/backupd[795] Error: (-8062) SrcErr:NO Copying /Volumes/HD3/Virtual Machines/Windows XP Professional.vmwarevm/Windows XP Professional.vmdk to /Volumes/Time Machine Backups/Backups.backupdb/vademacum/2009-07-30-163253.inProgress/4A...

@@Error not catching error.
Hi all, I want to catch error in stored procedure and return error message. I want to catch error 'Syntax error converting the varchar value 'a' to a column of data type int.' Means error occuring if i enter wrong value. Say suppose i have statment like select * from emp where rowid = 'a' PRINT @@ERROR print 'reach' here rowid is integer value so i am getting above mention error. So what i am expecting is it should print error and then print 'reach' which is not happening. can anyone tell me reason behind this and how to overcome this problem. than...

error: error sending
Hi, I hope somebody can help me. For sending mail I configured alpine with the following line: smtp.web.de/tls/user=xxxxxxx@web.de . But every time I tried the message "error sending" occured. To figure out more details I added the parameter debug, but there was no file .pine-debug. After reading the manual I tried: alpine -d 5 and got the message: Argument Error: unknown flag "d", debugging not compiled in Before downloading the source and compile it by my self, I thought I should ask you guys for help. My pine version: alpine-2.00-5.fc11.i586 Best regards Chris...

Error code when there is no error??
In my source I have: wndclass.hIcon = LoadIcon (hInstance, "test") ; test.ico is a valid icon. file. Everythig works ok. But when I test for an error like this: ShowLastError(); // no problems here wndclass.hIcon = LoadIcon (hInstance, "test") ; ShowLastError(); // I get "The system cannot find the file specidied" wndclass.hIcon get a valid handle. Here is my ShowLastError program: VOID ShowLastError(void) { LPVOID lpMsgBuf; DWORD error_code; int status; char sa1[1024]; error_code = Get...

Error upon Error...
anyone seen this error before: > Can't load '/usr/local/lib/perl5/5.8.0/PA-RISC2.0/auto/DB_File/DB_File.sl' for module DB_File: No such file or directory at /usr/local/lib/perl5/5.8.0/PA-RISC2.0/XSLoader.pm line 83. > at /usr/local/lib/perl5/5.8.0/PA-RISC2.0/DB_File.pm line 236 I'm just trying to run this script: #!/usr/bin/perl -w use strict; use DB_File; print "Hello World!\n" all three of the files exist on the system....why is it saying this. (there are a few scripts that I have that want to use DB_File and they all say this.... that's why I j...

error with ERROR function
Hi all, I'm getting an error when I use the "error" function. Here is the error message: ---------------------------------------- ??? Index exceeds matrix dimensions. Error in ==> C:\MATLAB6p5p1\mese\user_functions\ssave.m On line 765 ==> error('ERROR e43: Initial Operating Point file cannot be found'); ---------------------------------------- What matrix is it refering to? thanks, SK "Saif K" <buckeyeforever2001@yahoo.com> wrote in message news:eee53de.-1@webx.raydaftYaTP... > Hi all, > > I'm getting an error when I use the &quo...

error C2197 error
Hello I am getting this error: error C2197: 'long (__stdcall *)(void)' : too many actual parameters Error executing cl.exe. The offending line is: if ((lResult = (*pfnGetProviderList)(0x00020000, pProviderList)) != 0) // this one { goto ProviderInstall_freeProviderList; } I am converting this C code into C++. Is the problem that compiler does not understand the parameters required for pfnGetProviderList? How can I fix? Angus wrote: > Hello > > I am getting this error: > > error C2197: 'long (__stdcall *)(void)' : too m...

Web resources about - (assert-error) tests errors and error messages - comp.emacs

Apple Concedes Its Errors in Maps Application; Asserts 'Working Hard' To Improve Experience; Expert Rules ...
As users continue to rant over misgivings in iOS6 Maps application and with iPhone 5 launching commercially today, Apple has conceded to errors ...

Resources last updated: 3/7/2016 7:43:42 PM