This is the mail archive of the mauve-discuss@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: patch to improve use with Eclipse


On Wed, 2005-12-21 at 16:07 +0100, Mark Wielaard wrote:
> Hi Raif,
> 
> On Thu, 2005-12-22 at 00:39 +1100, Raif S. Naffah wrote:
> > pls. find attached a patch to improve the use of Mauve with (Native) 
> > Eclipse.
> 
> Could you give some guidance for a newbie like me?
> I installed this and now I have under Run->External Tools a new item
> MauveBatchRun. If I select that (after following almost everything in
> http://developer.classpath.org/mediation/ClasspathHackingWithEclipse) it
> seems to configure mauve and then says:
> [Console output redirected to file:/home/mark/workspace/mauve/mauve.out]
> 
> But there is nothing in that file.
> 
> I did commit it so others can play more easily with it though.

Strangely enough it still doesn't really run for me.

But I did experiment a bit with eclipse and mauve and came up with a
simple SingleTestHarness which can be used with a Runner for quickly
testing a mauve Testlet that you are working on:

2005-12-21  Mark Wielaard  <mark@klomp.org>

        * gnu/testlet/SingleTestHarness.java: New file.

With this you can define a simple runner that uses this class with as
argument ${java_type_name}.

A cool trick here is to do the following:

$ mkdir -p ~/workspace/classpath/install/jre/lib
$ touch ~/workspace/classpath/install/jre/lib/rt.jar

Now you can go to Preferences -> Java -> JRE and add your
workspace/classpath/install as alternative installed jre. Then you can
use this alternative jre for the above runner to get it to test your
mauve Testlets against your the classpath project. Pretty cool :)

Cheers,

Mark
/* SingleTestHarness.java -- Runs one test given on the command line
   Copyright (C) 2005 Mark J. Wielaard
This file is part of Mauve.

Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

Mauve is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/

package gnu.testlet;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

public class SingleTestHarness extends TestHarness
{  
  private int count;
  private String className;
  private String last_check;

  public SingleTestHarness(Testlet t)
  {
    className = t.getClass().getName();
  }

  public void check(boolean result)
  {
    String message = (result ? "PASS" : "FAIL") + ": " + className
                      + ((last_check == null) ? "" : (": " + last_check))
                      + " (number " + count++ + ")";
    System.out.println(message);
  }

  public Reader getResourceReader(String name) throws ResourceNotFoundException
  {
    return new BufferedReader(new InputStreamReader(getResourceStream(name)));
  }

  public InputStream getResourceStream(String name)
      throws ResourceNotFoundException
  {
    // The following code assumes File.separator is a single character.
    if (File.separator.length() > 1)
      throw new Error("File.separator length is greater than 1");
    String realName = name.replace('#', File.separator.charAt(0));
    try
      {
        return new FileInputStream(getSourceDirectory() + File.separator
                                   + realName);
      }
    catch (FileNotFoundException ex)
      {
        throw new ResourceNotFoundException(ex.getLocalizedMessage() + ": "
                                            + getSourceDirectory()
                                            + File.separator + realName);
      }
  }

  public File getResourceFile(String name) throws ResourceNotFoundException
  {
    // The following code assumes File.separator is a single character.
    if (File.separator.length() > 1)
      throw new Error("File.separator length is greater than 1");
    String realName = name.replace('#', File.separator.charAt(0));
    File f = new File(getSourceDirectory() + File.separator + realName);
    if (!f.exists())
      {
        throw new ResourceNotFoundException("cannot find mauve resource file"
                                            + ": " + getSourceDirectory()
                                            + File.separator + realName);
      }
    return f;
  }

  public void checkPoint (String name)
  {
    last_check = name;
    count = 0;
  }
  
  public void verbose (String message)
  {
    System.out.println(message);
  }
  
  public void debug (String message)
  {
    debug(message, true);
  }
  
  public void debug (String message, boolean newline)
  {
    if (newline)
      System.out.println(message);
    else
      System.out.print(message);
  }
  
  public void debug (Throwable ex)
  {
    ex.printStackTrace(System.out);
  }
  
  public void debug (Object[] o, String desc)
  {
    debug("Dumping Object Array: " + desc);
    if (o == null)
      {
        debug("null");
        return;
      }

    for (int i = 0; i < o.length; i++) {
      if (o[i] instanceof Object[])
        debug((Object[]) o[i], desc + " element " + i);
      else
        debug("  Element " + i + ": " + o[i]);
    }
  }

  public static void main(String[] args) throws Exception
  {
    String name = args[0];
    Class k = Class.forName(name);    
    Testlet t = (Testlet) k.newInstance();
    TestHarness h = new SingleTestHarness(t);
    t.test(h);
  }
}

Attachment: signature.asc
Description: This is a digitally signed message part


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]