ofbiz-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Heath <doo...@brainfood.com>
Subject Re: [GSoC] Project update test/code separation
Date Thu, 11 Aug 2011 19:17:21 GMT
On 08/11/2011 12:36 PM, Ganath Rathnayake wrote:
> Hi all,
> Sorry for being late for update you. I sent this to the mailing list but
> unfortunately it bounced back.
> 
> Last week of time I was working on creating a bash script which use to
> change the exiting folder structure in to the new test/code separated
> structure.
> 
> Here I had to address few different issues.


Your script should do 'set -e' at the beginning.  It's possible that
your script is buggy, or doesn't handle something on a particular
machine, or the disk runs out of space.  Without that, you would have
to check the return of *every* command(cp, rm, cat, whatever), and
handle the error.  Without such checking, things can sometimes go very
bad.

> 1. Creating the main/java and test/java folders in the src directory and put
> test files in test/java and rest in the main/java
> I did this by putting the tests in the test folders in each module in the
> test/java folder. I used the following code to do that. $test variable is
> the folder structure of each module.

What is $test?  Don't summarize, show code.  I don't understand your
explanation.

> cp main/java/$test/test/*  test/java/$test/

cp -a, preserve timestamps/permissions/ownership.

Your cp will *not* work if there are sub-folders in test, as it would
then copy the .svn files, which is *not* what you want.

rsync main/java/$test/test/ test/java/$test/ -a --exclude '.svn'

> rm -r main/java/$test/test/
> 
> 2. Fixing the paths in the macros.xml file. This was achieved by the
> following piece of code.
> sed 's/@{prefix}src/@{prefix}src\/main\/java/' <macros.xml >temp

sed 's,@{prefix}src,@{prefix}src/main/java,'

Note the use of ',' as the separator; this is easier to read, as you
don't have to escape all the / in the path.

> cat temp >macros.xml
> rm temp
> 
> 3. Fixing the paths in build.xml files. This was achieved by first replacing
> all the paths by adding main/java/ to the baginning of each path and then
> changing it with test/java if it is a test. You can see the code follows.
> Also some package name the files also change when it needed to do so.
> 
> for x in $(ls main/java/$test/test/)
> do
>     echo $x
>     sed 's/\.test;/;/' <main/java/$test/test/$x >temp
> 
>     cat temp >main/java/$test/test/$x
> 
>     j=`expr "$test" : 'org/ofbiz/base'`
>     if [ $j != 0 ];
>     then
>         sed 's/\.test\./\./' <main/java/$test/test/$x >temp
>         cat temp >main/java/$test/test/$x
>     fi

What?  Are we removing the test sub packages?  As in:

package org.ofbiz.entity.test;

becomes

package org.ofbiz.entity;

?

If so, then NO! DO NOT DO THAT.  Test cases should not ever be inside
the same package as the code they are testing.  Bugs might be missed,
as you can call package private/protected methods when in the same
package, that you can't when in another sub-package.

I can *not* stress this enough.  Do *NOT* move the test code out of a
test sub-package.

>     echo $test
>     sed "s#main/java/${test}test/#test/java/${test}#g" <../build.xml >temp
> # ./org/ofbiz does not match
>     cat temp >../build.xml
> 
> done
> rm temp
> 
> 4. Remove the package names which include ".test." from the files. I went
> through all the xml files and found out the places where it needed the
> changes and hard coded since we dont need to go through every files for
> changing small number of files in some of the modules(framework/service,
> framework/minilang, framework/entity, framework/base,
> application/securityext, application/product, application/order,
> application/content, application/accounting). You can find the code follows.

This whole part is not needed, if you don't remove the test sub package.

> 
>                     if [ $dir = 'service' ];
>                     then
>                         sed 's/\.test\./\./'
> <servicedef/services_test_se.xml >temp
>                         cat temp >servicedef/services_test_se.xml
> 
>                         sed 's/\.test\./\./' <testdef/servicetests.xml >temp
>                         cat temp >testdef/servicetests.xml
> 
>                     elif [ $dir = 'minilang' ];
>                     then
>                         sed 's/\.test\./\./' <testdef/MinilangTests.xml
>> temp
>                         cat temp >testdef/MinilangTests.xml
> 
>                     elif [ $dir = 'entity' ];
>                     then
>                         sed 's/\.test\./\./' <testdef/entitytests.xml >temp
>                         cat temp >testdef/entitytests.xml
> 
>                     elif [ $dir = 'base' ];
>                     then
>                         sed 's/\.test\./\./' <build.xml >temp
>                         cat temp >build.xml
> 
>                         sed 's/\.test\./\./' <config/test-containers.xml
>> temp
>                         cat temp >config/test-containers.xml
> 
>                         sed 's/\.test\./\./' <testdef/basetests.xml >temp
>                         cat temp >testdef/basetests.xml
> 
> 
>                     elif [ $dir = 'securityext' ];
>                     then
>                         sed 's/\.test\./\./' <testdef/securitytests.xml
>> temp
>                         cat temp >testdef/securitytests.xml
> 
>                         sed 's/\.test\./\./'
> <testdef/data/SecurityTestData.xml >temp
>                         cat temp >testdef/data/SecurityTestData.xml
> 
>                     elif [ $dir = 'product' ];
>                     then
>                         sed 's/\.test\./\./' <testdef/FacilityTest.xml >temp
>                         cat temp >testdef/FacilityTest.xml
> 
>                     elif [ $dir = 'order' ];
>                     then
>                         sed 's/\.test\./\./' <servicedef/services.xml >temp
>                         cat temp >servicedef/services.xml
> 
>                         sed 's/\.test\./\./' <testdef/OrderTest.xml >temp
>                         cat temp >testdef/OrderTest.xml
> 
>                     elif [ $dir = 'content' ];
>                     then
>                         sed 's/\.test\./\./' <testdef/lucenetests.xml >temp
>                         cat temp >testdef/lucenetests.xml
> 
>                     elif [ $dir = 'accounting' ];
>                     then
>                         sed 's/\.test\./\./' <testdef/accountingtests.xml
>> temp
>                         cat temp >testdef/accountingtests.xml
> 
>                     fi
> 
> 
> 
> If you have any suggestions or any input to improve the script please let me
> know. You can find the full script in [1].
> 
> 


Mime
View raw message