Browse Source

Zap some testing code

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272458 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
139fb334e7
25 changed files with 0 additions and 1604 deletions
  1. +0
    -217
      proposal/myrmidon/src/test/org/apache/myrmidon/AbstractMyrmidonTest.java
  2. +0
    -113
      proposal/myrmidon/src/test/org/apache/myrmidon/AbstractProjectTest.java
  3. +0
    -59
      proposal/myrmidon/src/test/org/apache/myrmidon/LogMessageTracker.java
  4. +0
    -121
      proposal/myrmidon/src/test/org/apache/myrmidon/TrackingProjectListener.java
  5. +0
    -37
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/AndConditionTestCase.java
  6. +0
    -50
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/ConditionTestTask.java
  7. +0
    -48
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/IsSetConditionTestCase.java
  8. +0
    -51
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/IsTrueConditionTestCase.java
  9. +0
    -39
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/NotConditionTestCase.java
  10. +0
    -37
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/OrConditionTestCase.java
  11. +0
    -57
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/TestCondition.java
  12. +0
    -40
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/and.ant
  13. +0
    -44
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/isset.ant
  14. +0
    -44
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/istrue.ant
  15. +0
    -28
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/not.ant
  16. +0
    -40
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/or.ant
  17. +0
    -120
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/file/test/PathTestCase.java
  18. +0
    -63
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/file/test/TestFileList.java
  19. +0
    -80
      proposal/myrmidon/src/test/org/apache/myrmidon/framework/file/test/path.ant
  20. +0
    -126
      proposal/myrmidon/src/test/org/apache/tools/ant/test/Ant1CompatTestCase.java
  21. +0
    -55
      proposal/myrmidon/src/test/org/apache/tools/ant/test/ant-task-test.xml
  22. +0
    -34
      proposal/myrmidon/src/test/org/apache/tools/ant/test/antcall-task-test.xml
  23. +0
    -21
      proposal/myrmidon/src/test/org/apache/tools/ant/test/basic-test.xml
  24. +0
    -62
      proposal/myrmidon/src/test/org/apache/tools/ant/test/if-unless-test.xml
  25. +0
    -18
      proposal/myrmidon/src/test/org/apache/tools/ant/test/subdir/build.xml

+ 0
- 217
proposal/myrmidon/src/test/org/apache/myrmidon/AbstractMyrmidonTest.java View File

@@ -1,217 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon;

import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.avalon.framework.logger.Logger;
import org.apache.myrmidon.frontends.BasicLogger;

/**
* A base class for Myrmidon tests. Provides utility methods for locating
* test resources.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*/
public abstract class AbstractMyrmidonTest
extends TestCase
{
private final File m_testBaseDir;
private final File m_baseDir;
private Logger m_logger;

public AbstractMyrmidonTest( final String name )
{
super( name );
final String baseDirProp = System.getProperty( "test.basedir" );
m_baseDir = getCanonicalFile( new File( baseDirProp ) );
final String packagePath = getPackageName( getClass() ).replace( '.', File.separatorChar );
m_testBaseDir = getCanonicalFile( new File( m_baseDir, packagePath ) );
}

/**
* Locates the error message resources for a class.
*/
protected static final Resources getResourcesForTested( final Class clazz )
{
String baseName = getPackageName( clazz );
if( baseName.endsWith( ".test" ) )
{
baseName = baseName.substring( 0, baseName.length() - 5 );
}

return ResourceManager.getBaseResources( baseName + ".Resources", AbstractMyrmidonTest.class.getClassLoader() );
}

/**
* Returns the name of the package containing a class.
*
* @return The . delimited package name, or an empty string if the class
* is in the default package.
*/
protected static String getPackageName( final Class clazz )
{
final Package pkg = clazz.getPackage();
if( null != pkg )
{
return pkg.getName();
}

final String name = clazz.getName();
if( -1 == name.lastIndexOf( "." ) )
{
return "";
}
else
{
return name.substring( 0, name.lastIndexOf( "." ) );
}
}

/**
* Locates a test resource, and asserts that the resource exists
*
* @param name path of the resource, relative to this test's base directory.
*/
protected File getTestResource( final String name )
{
return getTestResource( name, true );
}

/**
* Locates a test resource.
*
* @param name path of the resource, relative to this test's base directory.
*/
protected File getTestResource( final String name, final boolean mustExist )
{
File file = new File( m_testBaseDir, name );
file = getCanonicalFile( file );
if( mustExist )
{
assertTrue( "Test file \"" + file + "\" does not exist.", file.exists() );
}
else
{
assertTrue( "Test file \"" + file + "\" should not exist.", !file.exists() );
}

return file;
}

/**
* Locates the base directory for this test.
*/
protected File getTestDirectory()
{
return m_testBaseDir;
}

/**
* Locates a test directory, creating it if it does not exist.
*
* @param name path of the directory, relative to this test's base directory.
*/
protected File getTestDirectory( final String name )
{
File file = new File( m_testBaseDir, name );
file = getCanonicalFile( file );
assertTrue( "Test directory \"" + file + "\" does not exist or is not a directory.",
file.isDirectory() || file.mkdirs() );
return file;
}

/**
* Returns the directory containing a Myrmidon install.
*/
protected File getInstallDirectory()
{
final File file = new File( m_baseDir, "dist" );
return getCanonicalFile( file );
}

/**
* Makes a file canonical
*/
private File getCanonicalFile( final File file )
{
try
{
return file.getCanonicalFile();
}
catch( IOException e )
{
return file.getAbsoluteFile();
}
}

/**
* Creates a logger.
*/
protected Logger getLogger()
{
if( m_logger == null )
{
m_logger = new BasicLogger( "[test]", BasicLogger.LEVEL_WARN );
}
return m_logger;
}

/**
* Asserts that an exception chain contains the expected messages.
*
* @param messages The messages, in order. A null entry in this array
* indicates that the message should be ignored.
*/
protected void assertSameMessage( final String[] messages, final Throwable throwable )
{
Throwable current = throwable;
for( int i = 0; i < messages.length; i++ )
{
String message = messages[ i ];
assertNotNull( current );
if( message != null )
{
assertEquals( message, current.getMessage() );
}

// Get the next exception in the chain
current = ExceptionUtil.getCause( current, true );
}
}

/**
* Asserts that an exception contains the expected message.
*/
protected void assertSameMessage( final String message, final Throwable throwable )
{
assertSameMessage( new String[]{message}, throwable );
}

/**
* Compares 2 objects for equality, nulls are equal. Used by the test
* classes' equals() methods.
*/
public static boolean equals( final Object o1, final Object o2 )
{
if( o1 == null && o2 == null )
{
return true;
}
if( o1 == null || o2 == null )
{
return false;
}
return o1.equals( o2 );
}

}

+ 0
- 113
proposal/myrmidon/src/test/org/apache/myrmidon/AbstractProjectTest.java View File

@@ -1,113 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon;

import java.io.File;
import org.apache.myrmidon.frontends.EmbeddedAnt;
import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.avalon.framework.ExceptionUtil;

/**
* A base class for test cases which need to execute projects.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class AbstractProjectTest
extends AbstractMyrmidonTest
{
public AbstractProjectTest( final String name )
{
super( name );
}

/**
* Executes a target in a project, and asserts that it fails with the
* given error message.
*/
protected void executeTargetExpectError( final File projectFile,
final String targetName,
final String message )
{
executeTargetExpectError( projectFile, targetName, new String[]{message} );
}

/**
* Executes a target in a project, and asserts that it fails with the
* given error messages.
*/
protected void executeTargetExpectError( final File projectFile,
final String targetName,
final String[] messages )
{
try
{
executeTarget( projectFile, targetName, null );
fail( "target execution did not fail" );
}
catch( Exception e )
{
assertSameMessage( messages, e );
}
}

/**
* Executes a target in a project, and asserts that it does not fail.
*/
protected void executeTarget( final File projectFile, final String targetName )
throws Exception
{
executeTarget( projectFile, targetName, null );
}

/**
* Executes a target in a project, and asserts that it does not fail.
*/
protected void executeTarget( final File projectFile,
final String targetName,
final ProjectListener listener )
throws Exception
{
final EmbeddedAnt embeddor = new EmbeddedAnt();
final TrackingProjectListener tracker = new TrackingProjectListener();

try
{
// Configure embeddor
embeddor.setHomeDirectory( getInstallDirectory() );
embeddor.enableLogging( getLogger() );
embeddor.setSharedClassLoader( getClass().getClassLoader() );
embeddor.setProjectFile( projectFile.getAbsolutePath() );
embeddor.setProjectListener( null );

// Add a listener to make sure all is good
embeddor.addProjectListener( tracker );

// Add supplied listener
if( listener != null )
{
embeddor.addProjectListener( listener );
}

// Now execute the target
embeddor.executeTargets( new String[] { targetName } );
}
finally
{
embeddor.stop();
}


// Make sure all expected events were delivered
tracker.assertComplete();
if( listener instanceof TrackingProjectListener )
{
( (TrackingProjectListener)listener ).assertComplete();
}
}
}

+ 0
- 59
proposal/myrmidon/src/test/org/apache/myrmidon/LogMessageTracker.java View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon;

import java.util.ArrayList;
import java.util.List;
import org.apache.myrmidon.listeners.LogEvent;

/**
* Asserts that log messages are delivered in the correct order.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class LogMessageTracker
extends TrackingProjectListener
{
private List m_targets = new ArrayList();
private List m_messages = new ArrayList();

/**
* Handles a log message.
*/
public void log( final LogEvent event )
{
super.log( event );

// Pop the next expected message off the list, and make sure it
// matches the message in the event
assertTrue( "Unexpected log message", m_targets.size() > 0 && m_messages.size() > 0 );
assertEquals( "Unexpected log message", m_targets.remove( 0 ), event.getTargetName() );
assertEquals( "Unexpected log message", m_messages.remove( 0 ), event.getMessage() );
}

/**
* Asserts that all the log messages were delivered.
*/
public void assertComplete()
{
super.assertComplete();

// Make sure that all log messages were delivered
assertTrue( "Log message not delivered", m_targets.size() == 0 && m_messages.size() == 0 );
}

/**
* Adds an expected log message.
*/
public void addExpectedMessage( String target, String message )
{
m_targets.add( target );
m_messages.add( message );
}
}

+ 0
- 121
proposal/myrmidon/src/test/org/apache/myrmidon/TrackingProjectListener.java View File

@@ -1,121 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon;

import junit.framework.Assert;
import org.apache.myrmidon.listeners.LogEvent;
import org.apache.myrmidon.listeners.ProjectEvent;
import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.myrmidon.listeners.TargetEvent;
import org.apache.myrmidon.listeners.TaskEvent;

/**
* A project listener that asserts that it receives a particular sequence of
* events.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class TrackingProjectListener
extends Assert
implements ProjectListener
{
private String m_rootProject;
private String m_currentProject;
private String m_currentTarget;
private String m_currentTask;

/**
* Notify the listener that a project is about to start.
*/
public void projectStarted( final ProjectEvent event )
{
assertNull( "Project already started", m_rootProject );
m_rootProject = event.getProjectName();
}

/**
* Notify the listener that a project has finished.
*/
public void projectFinished( final ProjectEvent event )
{
assertEquals( "Mismatched project name", m_rootProject, event.getProjectName() );
m_rootProject = null;

assertNull( "Target not started", m_currentTarget );
}

/**
* Notify the listener that a target is about to start.
*/
public void targetStarted( final TargetEvent event )
{
assertNotNull( "Project not started", m_rootProject );
assertNull( "Target already started", m_currentTarget );
m_currentProject = event.getProjectName();
m_currentTarget = event.getTargetName();
}

/**
* Notify the listener that a target has finished.
*/
public void targetFinished( final TargetEvent event )
{
assertEquals( "Mismatched project name", m_currentProject, event.getProjectName() );
assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
m_currentProject = null;
m_currentTarget = null;

assertNull( "Task not finished", m_currentTask );
}

/**
* Notify the listener that a task is about to start.
*/
public void taskStarted( final TaskEvent event )
{
assertEquals( "Mismatched project name", m_currentProject, event.getProjectName() );
assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );

assertNull( "Task already started", m_currentTask );
m_currentTask = event.getTaskName();
}

/**
* Notify the listener that a task has finished.
*/
public void taskFinished( final TaskEvent event )
{
assertEquals( "Mismatched project name", m_currentProject, event.getProjectName() );
assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
assertEquals( "Mismatched task name", m_currentTask, event.getTaskName() );
m_currentTask = null;
}

/**
* Notify listener of log message event.
*/
public void log( final LogEvent event )
{
assertEquals( "Mismatched project name", m_currentProject, event.getProjectName() );
assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
assertEquals( "Mismatched task name", m_currentTask, event.getTaskName() );
assertNull( "Unexpected build error", event.getThrowable() );
}

/**
* Asserts that the listener has finished.
*/
public void assertComplete()
{
assertNull( "Task not finished", m_currentTask );
assertNull( "Target not finished", m_currentTarget );
assertNull( "Target not finished", m_currentProject );
assertNull( "Project not finished", m_rootProject );
}
}

+ 0
- 37
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/AndConditionTestCase.java View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;

/**
* Test cases for the <and> condition.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class AndConditionTestCase
extends AbstractProjectTest
{
public AndConditionTestCase( final String name )
{
super( name );
}

/**
* Tests evaluation of the <and> condition.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "and.ant" );
executeTarget( projectFile, "empty" );
executeTarget( projectFile, "truth-table" );
executeTarget( projectFile, "lazy" );
}
}

+ 0
- 50
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/ConditionTestTask.java View File

@@ -1,50 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.conditions.Condition;

/**
* A simple assert task, used for testing conditions.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant.task name="assert"
*/
public class ConditionTestTask
extends AbstractTask
{
private boolean m_expected = true;
private Condition m_condition;

public void setExpected( final boolean expected )
{
m_expected = expected;
}

public void add( final Condition condition )
{
m_condition = condition;
}

/**
* Execute task.
*/
public void execute()
throws TaskException
{
final boolean result = m_condition.evaluate( getContext() );
if( result != m_expected )
{
throw new TaskException( "Expected " + m_expected + ", got " + result );
}
}
}

+ 0
- 48
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/IsSetConditionTestCase.java View File

@@ -1,48 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import java.io.File;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.framework.conditions.IsSetCondition;

/**
* Test cases for the <is-set> condition.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class IsSetConditionTestCase
extends AbstractProjectTest
{
public IsSetConditionTestCase( final String name )
{
super( name );
}

/**
* Test cases for <is-set> evaluation.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "isset.ant" );
executeTarget( projectFile, "set" );
executeTarget( projectFile, "set2true" );
executeTarget( projectFile, "set2false" );
executeTarget( projectFile, "not-set" );

Resources res = getResourcesForTested( IsSetCondition.class );
final String[] messages = {
null,
res.getString( "isset.no-property.error" )
};
executeTargetExpectError( projectFile, "no-prop-name", messages );
}

}

+ 0
- 51
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/IsTrueConditionTestCase.java View File

@@ -1,51 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import java.io.File;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.framework.conditions.IsTrueCondition;

/**
* Test cases for the <is-true> condition.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class IsTrueConditionTestCase
extends AbstractProjectTest
{
public IsTrueConditionTestCase( final String name )
{
super( name );
}

/**
* Test cases for <is-true> evaluation.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "istrue.ant" );
executeTarget( projectFile, "set2true" );
executeTarget( projectFile, "set2false" );
executeTarget( projectFile, "not-set" );

// TODO - check error message
String[] messages = {};
executeTargetExpectError( projectFile, "set", messages );

final Resources res = getResourcesForTested( IsTrueCondition.class );
messages = new String[] {
null,
res.getString( "istrue.no-property.error" )
};
executeTargetExpectError( projectFile, "no-prop-name", messages );
}

}

+ 0
- 39
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/NotConditionTestCase.java View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import org.apache.myrmidon.AbstractProjectTest;
import java.io.File;

/**
* Test cases for the <not> condition.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class NotConditionTestCase
extends AbstractProjectTest
{
public NotConditionTestCase( final String name )
{
super( name );
}

/**
* Tests evaluation of <not>.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "not.ant" );
executeTarget( projectFile, "truth-table" );

// TODO - check error messages
executeTargetExpectError( projectFile, "empty", new String[0] );
executeTargetExpectError( projectFile, "too-many-nested", new String[0] );
}
}

+ 0
- 37
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/OrConditionTestCase.java View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;

/**
* Test cases for the <or> condition.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class OrConditionTestCase
extends AbstractProjectTest
{
public OrConditionTestCase( final String name )
{
super( name );
}

/**
* Tests evaluation of the <or> condition.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "or.ant" );
executeTarget( projectFile, "empty" );
executeTarget( projectFile, "truth-table" );
executeTarget( projectFile, "lazy" );
}
}

+ 0
- 57
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/TestCondition.java View File

@@ -1,57 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.conditions.test;

import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;

/**
* A condition used for testing.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant.type type="condition" name="true"
* @ant.type type="condition" name="false"
* @ant.type type="condition" name="fail"
*/
public class TestCondition
implements Condition, Configurable
{
private String m_action;

public void configure( final Configuration configuration )
throws ConfigurationException
{
m_action = configuration.getName();
}

/**
* Evaluates this condition.
*/
public boolean evaluate( final TaskContext context )
throws TaskException
{
if( m_action.equalsIgnoreCase( "true" ) )
{
return true;
}
else if( m_action.equalsIgnoreCase( "false" ) )
{
return false;
}
else
{
throw new TaskException( "Fail." );
}
}
}

+ 0
- 40
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/and.ant View File

@@ -1,40 +0,0 @@
<!-- Tests for the <and> condition. -->
<project version="2.0">

<!-- An empty <and> condition -->
<target name="empty">
<assert>
<and/>
</assert>
</target>

<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<and><false/></and>
</assert>
<assert>
<and><true/></and>
</assert>
<assert expected="false">
<and><false/><false/></and>
</assert>
<assert expected="false">
<and><true/><false/></and>
</assert>
<assert expected="false">
<and><false/><true/></and>
</assert>
<assert>
<and><true/><true/></and>
</assert>
</target>

<!-- Check lazy evaluation -->
<target name="lazy">
<assert expected="false">
<and><false/><fail/></and>
</assert>
</target>

</project>

+ 0
- 44
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/isset.ant View File

@@ -1,44 +0,0 @@
<!-- Tests for the <is-set> condition. -->
<project version="2.0">

<!-- Set to some arbirary value -->
<target name="set">
<property name="test-prop">
<path location="some-location"/>
</property>
<assert>
<is-set property="test-prop"/>
</assert>
</target>

<!-- Set to true -->
<target name="set2true">
<property name="test-prop" value="true"/>
<assert>
<is-set property="test-prop"/>
</assert>
</target>

<!-- Set to false -->
<target name="set2false">
<property name="test-prop" value="false"/>
<assert>
<is-set property="test-prop"/>
</assert>
</target>

<!-- Not set -->
<target name="not-set">
<assert expected="false">
<is-set property="test-prop"/>
</assert>
</target>

<!-- No property name -->
<target name="no-prop-name">
<assert>
<is-set/>
</assert>
</target>

</project>

+ 0
- 44
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/istrue.ant View File

@@ -1,44 +0,0 @@
<!-- Tests for the <is-true> condition. -->
<project version="2.0">

<!-- Set to some arbirary value -->
<target name="set">
<property name="test-prop">
<path location="some-location"/>
</property>
<assert>
<is-true property="test-prop"/>
</assert>
</target>

<!-- Set to true -->
<target name="set2true">
<property name="test-prop" value="true"/>
<assert>
<is-true property="test-prop"/>
</assert>
</target>

<!-- Set to false -->
<target name="set2false">
<property name="test-prop" value="false"/>
<assert expected="false">
<is-true property="test-prop"/>
</assert>
</target>

<!-- Not set -->
<target name="not-set">
<assert expected="false">
<is-true property="test-prop"/>
</assert>
</target>

<!-- No property name -->
<target name="no-prop-name">
<assert>
<is-true/>
</assert>
</target>

</project>

+ 0
- 28
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/not.ant View File

@@ -1,28 +0,0 @@
<!-- Tests for the <not> condition. -->
<project version="2.0">

<!-- An empty <or> condition -->
<target name="empty">
<assert>
<not/>
</assert>
</target>

<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<not><true/></not>
</assert>
<assert>
<not><false/></not>
</assert>
</target>

<!-- Too many nested conditions -->
<target name="too-many-nested">
<assert>
<not><true/><false/></not>
</assert>
</target>

</project>

+ 0
- 40
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/or.ant View File

@@ -1,40 +0,0 @@
<!-- Tests for the <or> condition. -->
<project version="2.0">

<!-- An empty <or> condition -->
<target name="empty">
<assert>
<or/>
</assert>
</target>

<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<or><false/></or>
</assert>
<assert>
<or><true/></or>
</assert>
<assert expected="false">
<or><false/><false/></or>
</assert>
<assert>
<or><true/><false/></or>
</assert>
<assert>
<or><false/><true/></or>
</assert>
<assert>
<or><true/><true/></or>
</assert>
</target>

<!-- Check lazy evaluation -->
<target name="lazy">
<assert>
<or><true/><fail/></or>
</assert>
</target>

</project>

+ 0
- 120
proposal/myrmidon/src/test/org/apache/myrmidon/framework/file/test/PathTestCase.java View File

@@ -1,120 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.file.test;

import java.io.File;
import org.apache.aut.nativelib.PathUtil;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;

/**
* Test-cases for the <path> data type.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class PathTestCase
extends AbstractProjectTest
{
public PathTestCase( final String name )
{
super( name );
}

/**
* Tests setting the location attribute.
*/
public void testLocationAttribute() throws Exception
{
testPathContent( "set-location", new String[]{"location"} );
}

/**
* Tests setting the path attribute.
*/
public void testPathAttribute() throws Exception
{
// Test a path with a single file
testPathContent( "set-path", new String[]{"single-file"} );

// Test a path with several files, using ; separator
testPathContent( "set-multi-path", new String[]{"file1", "file2", ".."} );

// Test a path with several files, using : separator
testPathContent( "set-multi-path2", new String[]{"file1", "file2", ".."} );
}

/**
* Test using nested <path> elements.
*/
public void testPathElement() throws Exception
{
testPathContent( "nested-path", new String[]{"some-file"} );
testPathContent( "mixed-path", new String[]{"file1", "file2", "file3", "file4", "file5"} );
}

/**
* Test using nested <fileset> elements.
*/
public void testFilesetElement() throws Exception
{
testPathContent( "set-fileset", new String[]{"path.ant"} );
}

/**
* Test using a nested custom file list implementation.
*/
public void testCustomFileList() throws Exception
{
testPathContent( "test-custom-file-list", new String[]{"file1"} );
}

/**
* Test converting between string and path.
*/
public void testConvert() throws Exception
{
testPathContent( "convert-string-to-path", new String[]{"file1", "file2"} );

// Test conversion from path -> string
final File[] files = {
getTestResource( "file1", false ),
getTestResource( "file2", false )
};
final String path = PathUtil.formatPath( files );
final LogMessageTracker listener = new LogMessageTracker();
listener.addExpectedMessage( "convert-path-to-string", "test-path = " + path );

final File projectFile = getTestResource( "path.ant" );
executeTarget( projectFile, "convert-path-to-string", listener );
}

/**
* Executes a target, and asserts that a particular list of file names
* is logged.
*/
private void testPathContent( final String targetName,
final String[] files ) throws Exception
{
final File projectFile = getTestResource( "path.ant" );
final File baseDir = projectFile.getParentFile();

// Add each of the expected file names
final LogMessageTracker listener = new LogMessageTracker();
for( int i = 0; i < files.length; i++ )
{
final String fileName = files[ i ];
final File file = FileUtil.resolveFile( baseDir, fileName );
listener.addExpectedMessage( targetName, file.getAbsolutePath() );
}

// Execute the target
executeTarget( projectFile, targetName, listener );
}
}

+ 0
- 63
proposal/myrmidon/src/test/org/apache/myrmidon/framework/file/test/TestFileList.java View File

@@ -1,63 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.file.test;

import java.io.File;
import java.util.ArrayList;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.file.FileList;
import org.apache.myrmidon.framework.file.Path;

/**
* A test FileList implementation.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant.type type="path" name="test-file-list"
*/
public class TestFileList
implements FileList
{
private String m_name;
private Path m_path;

public void setName( final String name )
{
m_name = name;
}

public void setPath( final Path path )
{
m_path = path;
}

/**
* Returns the files in this list.
*/
public String[] listFiles( final TaskContext context )
throws TaskException
{
final ArrayList files = new ArrayList();
if( m_name != null )
{
final File file = context.resolveFile( m_name );
files.add( file.getAbsolutePath() );
}
if( m_path != null )
{
final String[] fileNames = m_path.listFiles( context );
for( int i = 0; i < fileNames.length; i++ )
{
files.add( fileNames[ i ] );
}
}
return (String[])files.toArray( new String[ files.size() ] );
}
}

+ 0
- 80
proposal/myrmidon/src/test/org/apache/myrmidon/framework/file/test/path.ant View File

@@ -1,80 +0,0 @@
<project version="2.0">
<!-- Test setting the location attribute -->
<target name="set-location">
<list-path>
<path location="location"/>
</list-path>
</target>

<!-- Test setting the path attribute -->
<target name="set-path">
<list-path>
<path path="single-file"/>
</list-path>
</target>

<!-- Test setting the path attribute with ; delims -->
<target name="set-multi-path">
<list-path>
<path path="file1;file2;.."/>
</list-path>
</target>

<!-- Test setting the path attribute with : delims -->
<target name="set-multi-path2">
<list-path>
<path path="file1:file2:.."/>
</list-path>
</target>

<!-- Test using a nested <path> element -->
<target name="nested-path">
<list-path>
<path>
<path location="some-file"/>
</path>
</list-path>
</target>

<!-- Test using a mix of attributes and nested <path> elements -->
<target name="mixed-path">
<list-path>
<path location="file1" path="file2;file3">
<path location="file4"/>
<path location="file5"/>
</path>
</list-path>
</target>

<!-- Test using a nested fileset -->
<target name="set-fileset">
<list-path>
<path>
<fileset dir="." includes="**/path.ant"/>
</path>
</list-path>
</target>

<!-- Test using a custom file list implementation -->
<target name="test-custom-file-list">
<list-path>
<path>
<test-file-list name="file1"/>
</path>
</list-path>
</target>

<!-- Test converting a string to a path -->
<target name="convert-string-to-path">
<list-path>
<test-file-list path="file1;file2"/>
</list-path>
</target>

<!-- Test converting a path to a string -->
<target name="convert-path-to-string">
<path id="test-path" path="file1:file2"/>
<log>test-path = ${test-path}</log>
</target>

</project>

+ 0
- 126
proposal/myrmidon/src/test/org/apache/tools/ant/test/Ant1CompatTestCase.java View File

@@ -1,126 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.test;

import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;

/**
* Simple tests for the Ant1 Compatibility layer.
*
* @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
* @version $Revision$ $Date$
*/
public class Ant1CompatTestCase
extends AbstractProjectTest
{
public Ant1CompatTestCase( final String name )
{
super( name );
}

public void testBasic() throws Exception
{
final File projectFile = getTestResource( "basic-test.xml" );

// <echo> test
LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage( "echo-test", "Hello, hello, hello" );
executeTarget( projectFile, "echo-test", tracker );

// Property resolution tests
tracker = new LogMessageTracker();
tracker.addExpectedMessage( "property-test", "prop-1 = [value-1]" );
tracker.addExpectedMessage( "property-test", "prop-2 = [value-2]" );
tracker.addExpectedMessage( "property-test", "prop-undefined = [${prop-undefined}]" );
tracker.addExpectedMessage( "property-test", "Omit, replace$, but keep ${} and $" );
executeTarget( projectFile, "property-test", tracker );
}

public void testIfUnless() throws Exception
{
final File projectFile = getTestResource( "if-unless-test.xml" );

// if/unless tests.
LogMessageTracker tracker = new LogMessageTracker();
// Should pass if for "set", "true" and "false"
tracker.addExpectedMessage( "if-set-test", "Ran target: if-set-test" );
tracker.addExpectedMessage( "if-true-test", "Ran target: if-true-test" );
tracker.addExpectedMessage( "if-false-test", "Ran target: if-false-test" );

// Should only pass unless, when not defined.
tracker.addExpectedMessage( "unless-unset-test",
"Ran target: unless-unset-test" );

// If combined with unless on a single target.
tracker.addExpectedMessage( "if-with-unless-test-1",
"Ran target: if-with-unless-test-1" );

executeTarget( projectFile, "if-unless-tests", tracker );
}

public void testAntTask() throws Exception
{
final File projectFile = getTestResource( "ant-task-test.xml" );

// TODO - Get the <ant> project listeners working, so we can test log messages.

LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage( "default-target", "In default target." );
tracker.addExpectedMessage( "echo-test", "Hello, hello, hello" );
// executeTarget( projectFile, "ant-samefile-test", tracker );
executeTarget( projectFile, "ant-samefile-test" );

tracker = new LogMessageTracker();
tracker.addExpectedMessage( "main",
"Executed subdir/build.xml (default target)" );
tracker.addExpectedMessage( "main",
"Executed subdir/build.xml (default target)" );
tracker.addExpectedMessage( "main",
"Executed subdir/build.xml (default target)" );
tracker.addExpectedMessage( "echo",
"Executed subdir/build.xml (echo target)" );
// executeTarget( projectFile, "ant-otherfile-test", tracker );
executeTarget( projectFile, "ant-otherfile-test" );

tracker = new LogMessageTracker();
tracker.addExpectedMessage( "property-test",
"test-prop = [test-value]" );
tracker.addExpectedMessage( "property-test",
"test-prop = [set in calling task]" );
tracker.addExpectedMessage( "property-test",
"test-prop = [set in calling target]" );
tracker.addExpectedMessage( "property-test",
"test-prop = [test-value]" );
// executeTarget( projectFile, "ant-setprops-test", tracker );
executeTarget( projectFile, "ant-setprops-test" );
}

public void testAntcallTask() throws Exception
{
final File projectFile = getTestResource( "antcall-task-test.xml" );

// TODO - Get the <ant> project listeners working, so we can test log messages.

LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage( "default-target",
"In default target." );
tracker.addExpectedMessage( "antcall-target",
"In antcall-target: test-prop = [test-value]" );
tracker.addExpectedMessage( "antcall-target",
"In antcall-target: test-prop = [set in calling task]" );
tracker.addExpectedMessage( "antcall-target",
"In antcall-target: test-prop = [set in calling target]" );
tracker.addExpectedMessage( "antcall-target",
"In antcall-target: test-prop = [test-value]" );
// executeTarget( projectFile, "ant-samefile-test", tracker );
executeTarget( projectFile, "antcall-test" );
}

}

+ 0
- 55
proposal/myrmidon/src/test/org/apache/tools/ant/test/ant-task-test.xml View File

@@ -1,55 +0,0 @@
<project name="ant-task-test"
default="default-target">

<target name="default-target">
<echo message="In default target."/>
</target>

<target name="echo-test">
<echo message="Hello, hello, hello"/>
</target>

<!-- Test <ant> on this build file. -->
<target name="ant-samefile-test">
<!-- Default target -->
<ant antfile="ant-task-test.xml"/>

<!-- Named target -->
<ant antfile="ant-task-test.xml" target="echo-test"/>
</target>

<!-- Test <ant> on another build file. -->
<target name="ant-otherfile-test">
<!-- Full path to file. -->
<ant antfile="subdir/build.xml"/>

<!-- Dir and file specified -->
<ant dir="subdir" antfile="build.xml"/>

<!-- Dir with default filename -->
<ant dir="subdir"/>

<!-- Call named target -->
<ant antfile="subdir/build.xml" target="echo"/>
</target>

<!-- Test <ant> with property overrides -->
<target name="ant-setprops-test">
<!-- No property overrides -->
<ant antfile="subdir/build.xml" target="property-test"/>

<!-- Override property within task def -->
<ant antfile="subdir/build.xml" target="property-test">
<property name="test-prop" value="set in calling task"/>
</ant>

<!-- Override property in containing project -->
<property name="test-prop" value="set in calling target"/>
<ant antfile="subdir/build.xml" target="property-test"/>

<!-- Test inherit-all = false -->
<ant antfile="subdir/build.xml" target="property-test"
inheritall="false"/>
</target>

</project>

+ 0
- 34
proposal/myrmidon/src/test/org/apache/tools/ant/test/antcall-task-test.xml View File

@@ -1,34 +0,0 @@
<project name="antcall-task-test"
default="default-target">

<target name="default-target">
<echo message="In default target."/>
</target>

<target name="antcall-target">
<property name="test-prop" value="test-value"/>
<echo message="In antcall-target: test-prop = [${test-prop}]"/>
</target>

<!-- Basic <antcall> -->
<target name="antcall-test">
<!-- <antcall with default target -->
<antcall/>

<!-- <antcall> with defined target (No property overrides) -->
<antcall target="antcall-target"/>

<!-- Override property within task def -->
<antcall target="antcall-target">
<param name="test-prop" value="set in calling task"/>
</antcall>

<!-- Override property in containing project -->
<property name="test-prop" value="set in calling target"/>
<antcall target="antcall-target"/>

<!-- Test inherit-all = false -->
<antcall target="antcall-target" inheritall="false"/>
</target>

</project>

+ 0
- 21
proposal/myrmidon/src/test/org/apache/tools/ant/test/basic-test.xml View File

@@ -1,21 +0,0 @@
<project name="ant1compat-test"
default="echo-test">

<property name="prop-1" value="value-1"/>

<target name="main" depends="echo-test, property-test"/>

<target name="echo-test">
<echo message="Hello, hello, hello"/>
</target>

<target name="property-test">
<property name="prop-2" value="value-2"/>

<echo message="prop-1 = [${prop-1}]"/>
<echo message="prop-2 = [${prop-2}]"/>
<echo message="prop-undefined = [${prop-undefined}]"/>
<echo message="Omit$, replace$$, but keep ${} and $"/>
</target>

</project>

+ 0
- 62
proposal/myrmidon/src/test/org/apache/tools/ant/test/if-unless-test.xml View File

@@ -1,62 +0,0 @@
<project name="if-unless-test"
default="if-unless-tests">

<target name="if-unless-tests"
depends="setup-props,
if-set-test, if-unset-test,
if-true-test, if-false-test,
unless-set-test, unless-unset-test,
unless-true-test, unless-false-test,
if-with-unless-test-1, if-with-unless-test-2,
if-with-unless-test-3"/>

<target name="setup-props">
<property name="prop-set" value="set"/>
<property name="prop-true" value="true"/>
<property name="prop-false" value="false"/>
</target>

<target name="if-set-test" if="prop-set">
<echo message="Ran target: if-set-test"/>
</target>

<target name="if-unset-test" if="prop-unset">
<echo message="Ran target: if-unset-test"/>
</target>

<target name="if-true-test" if="prop-true">
<echo message="Ran target: if-true-test"/>
</target>

<target name="if-false-test" if="prop-false">
<echo message="Ran target: if-false-test"/>
</target>

<target name="unless-set-test" unless="prop-set">
<echo message="Ran target: unless-set-test"/>
</target>

<target name="unless-unset-test" unless="prop-unset">
<echo message="Ran target: unless-unset-test"/>
</target>

<target name="unless-true-test" unless="prop-true">
<echo message="Ran target: unless-true-test"/>
</target>

<target name="unless-false-test" unless="prop-false">
<echo message="Ran target: unless-false-test"/>
</target>

<target name="if-with-unless-test-1" if="prop-set" unless="prop-unset">
<echo message="Ran target: if-with-unless-test-1"/>
</target>

<target name="if-with-unless-test-2" if="prop-unset" unless="prop-unset">
<echo message="Ran target: if-with-unless-test-2"/>
</target>

<target name="if-with-unless-test-3" if="prop-set" unless="prop-set">
<echo message="Ran target: if-with-unless-test-3"/>
</target>
</project>

+ 0
- 18
proposal/myrmidon/src/test/org/apache/tools/ant/test/subdir/build.xml View File

@@ -1,18 +0,0 @@
<project name="call-target"
description="Simple build for testing ant and antcall tasks."
default="main">

<property name="test-prop" value="test-value"/>

<target name="main">
<echo message="Executed subdir/build.xml (default target)"/>
</target>

<target name="echo">
<echo message="Executed subdir/build.xml (echo target)"/>
</target>

<target name="property-test">
<echo message="test-prop = [${test-prop}]"/>
</target>
</project>

Loading…
Cancel
Save