I have been working on a cross platform permission task and in the
process I realized that that was no way to ensure backwards
compatibility. So I wrote a test case for <chmod>
I have tested it on the following platforms.
Passed on:
Linux 1.1.8 IBM
Linux 1.3.0 IBM
Linux 1.3.1 Sun
Linux 1.3.1 Blackdown
Linux 1.4.0 Sun
Linux 1.4.1 Sun
Solaris 1.1.8
Solaris 1.2.2 Sun
Solaris 1.3.1 Sun
Mac OSX 1.3.1 with Java update
Failed on:
OSX Server build 1.3.1-root-020219-20:07
Would someone be kind enough to verify my results and commit the test
case if it's of use and returns valid results.
Thanks
Jesse
--
Jesse Stockall | Tel: 1+ 613.599.2441 ext. 243
CRYPTOCard Corporation | Fax: 1+ 613.599.2442
Suite 304, 300 March Rd. | email: [EMAIL PROTECTED]
Ottawa, ON, Canada K2K 2E2 | web: www.cryptocard.com
---------------------------------------------------------------------
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs;
import java.io.File;
import org.apache.tools.ant.BuildFileTest;
/**
* A test class for the 'chmod' task, used for changing file and directory
* permissions<p>
*
* Passed on:
* <li> Linux 1.1.8 IBM
* <li> Linux 1.3.0 IBM
* <li> Linux 1.3.1 Sun
* <li> Linux 1.3.1 Blackdown
* <li> Linux 1.4.0 Sun
* <li> Linux 1.4.1 Sun
* <li> Solaris 1.1.8
* <li> Solaris 1.2.2 Sun
* <li> Solaris 1.3.1 Sun
* <li> Mac OSX 1.3.1 with Java update Tests 3 and 4 failed on Mac OSX Server
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jesse Stockall</a>
*/
public class ChmodTest extends BuildFileTest {
/** The name of the temporary file. */
private static final String TEMP_FILE = "chmod.tmp";
/** The name of the temporary directory. */
private static final String TEMP_DIR = "chmod.tmp.dir";
/**
* Required constructor.
*
* @param name name of the testcase
* @param name name of the testcase
*/
public ChmodTest(String name) {
super(name);
}
/**
* Test set up, called by the unit test framework prior to each test.
*/
public void setUp() {
configureProject("src/etc/testcases/taskdefs/chmod.xml");
project.setUserProperty("ant.home", System.getProperty("user.dir")
+ File.separator + "bootstrap");
}
/**
* Test tear down, called by the unit test framework after each test.
*/
public void tearDown() {
// Remove temporary files.
File file = new File(getProjectDir(), TEMP_FILE);
if (file.exists()) {
file.delete();
}
File dir = new File(getProjectDir(), TEMP_DIR);
file = new File(getProjectDir(), TEMP_DIR + File.separator + TEMP_FILE);
if (file.exists()) {
file.delete();
}
if (dir.exists()) {
dir.delete();
}
}
/** Expect an exception when insufficient information is provided. */
public void testMissingInfo() {
expectBuildException("test1", "Required attribute perm not set in chmod");
}
/** Expect an exception when the permission string is missing. */
public void testInvalidPerm() {
expectBuildException("test2", "Required attribute perm not set in chmod");
}
/** File should not be readable or writable */
public void testNoReadWrite() {
File file = new File(getProjectDir(), TEMP_FILE);
executeTarget("test3");
assertTrue("File should not be writable", ! file.canWrite());
assertTrue("File should not be readable", ! file.canRead());
}
/** Tests for an Ant 1.1 compat issue */
public void testAnt11Compat() {
File dir = new File(getProjectDir(), TEMP_DIR);
File file = new File(getProjectDir(), TEMP_DIR + File.separator + TEMP_FILE);
executeTarget("test4");
assertTrue("File should be readable", file.canRead());
assertTrue("File should be writable", file.canWrite());
assertTrue("Directory should be writable", dir.canWrite());
}
/** Tests for the invalid attributes */
public void testExceptions() {
expectBuildException("test5", "chmod doesn\'t support the executable attribute");
expectBuildException("test6", "chmod doesn\'t support the command attribute");
expectBuildException("test7", "chmod doesn\'t support the skipemptyfilesets attribute");
}
}
<?xml version="1.0"?>
<project name="chmod-test" basedir="." default="test1">
<target name="prep-file">
<touch file="chmod.tmp"/>
</target>
<target name="prep-dir">
<mkdir dir="chmod.tmp.dir"/>
<touch file="chmod.tmp.dir/chmod.tmp"/>
</target>
<target name="test1" depends="prep-file">
<chmod>
</chmod>
</target>
<target name="test2" depends="prep-file">
<chmod file="chmod.tmp"/>
</target>
<target name="test3" depends="prep-file">
<chmod file="chmod.tmp" perm="ugo-rw"/>
</target>
<target name="test4" depends="prep-dir">
<chmod dir="chmod.tmp.dir" perm="a-r,og-x"/>
</target>
<target name="test5" depends="prep-dir">
<chmod dir="chmod.tmp.dir" perm="123" executable="testExe"/>
</target>
<target name="test6" depends="prep-dir">
<chmod dir="chmod.tmp.dir" perm="a-r,og-x" command="TestCom,ane"/>
</target>
<target name="test7" depends="prep-dir">
<chmod dir="chmod.tmp.dir" perm="a-r,og-x" skipemptyfilesets="true"/>
</target>
</project>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>