Bug 118083 - Improve useability of standard stream capture for AjcTestCase
Summary: Improve useability of standard stream capture for AjcTestCase
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Testing (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-25 11:59 EST by Matthew Webster CLA
Modified: 2007-10-23 11:37 EDT (History)
0 users

See Also:


Attachments
Enhancement to AjcTestCase (8.41 KB, application/octet-stream)
2005-11-27 07:13 EST, Matthew Webster CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Webster CLA 2005-11-25 11:59:47 EST
The standard err and out streams are captured in several places in the harness to reduce the verbosity of output and allow validation of testcase behavior. Unfortunately this is implemented by switching redirection on and off at the beginning and end of each test which has a number of drawbacks:
1.	Certain AspectJ classes store a static reference to err/out e.g. IMessageHandler.SYSTER_ERR. They may store a reference to a redirected version rendering them useless in later tests
2.	All uses of  System.err/out for debugging are redirected making this debug mechanism largely useless
3.	Using System.err/out can cause tests to fail by changing expected output
4.	Redirected output does not go the screen immediately which means it does not appear while stepping through the code, even in verbose mode, making it largely useless
5.	Redirected output is often not show automatically when a test fails

The answer is to redirect the streams once when the harness starts but leave them permanently connected to their original destinations. To reduces verbosity the destination streams can be switched on and off during test execution. To capture output a second stream is connected and disconnected to/form the redirected. Because the verbose mode decides what goes to the screen not the redirection text will appear while stepping through the code. Finally the original err/out are stored in a public final static to be used when output needs to go to the screen.
Comment 1 Matthew Webster CLA 2005-11-27 07:13:10 EST
Created attachment 30674 [details]
Enhancement to AjcTestCase

Use new DelegatingOutputStream in AjcTestCase to capture and redirect err and out. Behaviour remains the same however verbosity can be controlled with 2 System properties:
- "org.aspectj.tools.ajc.AjcTestCase.verbose.err": err
- "org.aspectj.tools.ajc.AjcTestCase.verbose.out": out
- "org.aspectj.tools.ajc.AjcTestCase.verbose": both

e.g. using "-Dorg.aspectj.tools.ajc.AjcTestCase.verbose.out=true" will ensure all data sent via System.out calls will go the console/screen immediately as well as being captured. A public final static "AjcTestCase.out" is always available to send data to the console, bypassing any capture.

The verbosity of Ajc can also be controlled using 
"-Dorg.aspectj.tools.ajc.Ajc.verbose=false".
Comment 2 Andrew Clement CLA 2005-11-28 03:06:12 EST
Hmmmm... I was expecting that once this was applied the default behaviour is that all I'd see was 'TEST: <testname>' and then no output and I'd have to turn on output if I wished to see it, but I still get the 'command was:' and all the info messages from the compiler.  is that what I should expect Matthew?
Comment 3 Matthew Webster CLA 2005-11-28 04:16:32 EST
The intention was to maintain the status quo but make it more useable. Ajc and AjcTestCase have separate redirection logic. This patch changes the implementation of only the latter. If all is OK I will create a follow-up patch that changes Ajc too.
Comment 4 Andrew Clement CLA 2005-11-28 04:29:43 EST
patches committed.  And I've turned off the verbose output again (I think it was me that accidentally committed it turned 'on' a little while ago).

The main feature I want it for is point (4) from the original post in this bug report - so I can see the output/error as I go along whilst debugging.  I'd like to note that some of these changes are necessary because of the new requirement of properly testing LTW (catching output early enough) - I wouldn't necessarily agree that much of what we've been using up to this point is 'largely useless'.
Comment 5 Andrew Clement CLA 2005-11-29 05:19:56 EST
fixes available.
Comment 6 Andrew Clement CLA 2005-11-29 05:56:31 EST
reopening as there is future work to be done...