Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCM-989] Tests fail if svn and/or git are not installed #149

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ protected void setUp()

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, "setUp" );
return;
}

CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
checkoutMojo.setWorkingDirectory( new File( getBasedir() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public void testSkipCheckoutWithConnectionUrl()

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

Comment on lines +84 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I see this code fragment duplicated many times. Should we make this into a method that returns a boolean?
  • If svn is missing then this test will pass. Now tests can pass, fail or be skipped. In many of the cases here I would have chosen to mark them as skipped instead of (as I read the code) passed.

Copy link
Member Author

@michael-o michael-o May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem, I have a local branch which uses your new code:

diff --git a/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java b/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java
index ef788478..33d27e7f 100644
--- a/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java
+++ b/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java
@@ -27,6 +27,9 @@

 import java.io.File;

+import static org.apache.maven.scm.provider.svn.SvnScmTestUtils.SVN_COMMAND_LINE;
+import static org.apache.maven.scm.provider.svn.SvnScmTestUtils.SVNADMIN_COMMAND_LINE;
+
 /**
  * @author <a href="mailto:[email protected]">Emmanuel Venisse</a>
  *
@@ -51,11 +54,7 @@ protected void setUp()

         FileUtils.forceDelete( repository );

-        if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
-        {
-            ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp" );
-            return;
-        }
+        ScmTestCase.checkScmPresence( SVNADMIN_COMMAND_LINE );

         SvnScmTestUtils.initializeRepository( repository );

But all of these changes fail with AssertionViolationException. There is some old code in Plugin Testing which does not work with Assume. Therefore, I'd like to move on with this and analyze it in a subsequent ticket: https://issues.apache.org/jira/projects/SCM/issues/SCM-939

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then I fully agree with your current code.

CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
mojo.setWorkingDirectory( new File( getBasedir() ) );
Expand Down Expand Up @@ -119,6 +125,12 @@ public void testSkipCheckoutWithoutConnectionUrl()
public void testUseExport()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

FileUtils.forceDelete( checkoutDir );

checkoutDir.mkdirs();
Expand All @@ -137,12 +149,24 @@ public void testUseExport()
public void testExcludeInclude()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
return;
}

FileUtils.forceDelete( checkoutDir );

checkoutDir.mkdirs();

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

CheckoutMojo mojo = (CheckoutMojo) lookupMojo(
"checkout",
getTestFile( "src/test/resources/mojos/checkout/checkoutWithExcludesIncludes.xml" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
Expand All @@ -18,6 +18,7 @@
import java.io.File;

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
import org.codehaus.plexus.util.FileUtils;

Expand Down Expand Up @@ -46,8 +47,20 @@ protected void setUp()
public void testExport()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
return;
}

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

ExportMojo mojo = (ExportMojo) lookupMojo( "export", getTestFile( "src/test/resources/mojos/export/export.xml" ) );

mojo.setExportDirectory( exportDir.getAbsoluteFile() );
Expand Down Expand Up @@ -77,10 +90,22 @@ public void testSkipExportIfExists()
public void testExcludeInclude()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
return;
}

SvnScmTestUtils.initializeRepository( repository );

exportDir.mkdirs();

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

ExportMojo mojo = (ExportMojo) lookupMojo(
"export",
getTestFile( "src/test/resources/mojos/export/exportWithExcludesIncludes.xml" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.provider.git.GitScmTestUtils;
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
import org.codehaus.plexus.util.FileUtils;
import org.junit.Assume;
Expand Down Expand Up @@ -51,10 +52,20 @@ protected void setUp()

FileUtils.forceDelete( repository );

Assume.assumeTrue( ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) );
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp" );
return;
}

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, "setUp" );
return;
}

CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
checkoutMojo.setWorkingDirectory( new File( getBasedir() ) );
Expand All @@ -77,6 +88,11 @@ private static void setupConnectionUrl( AbstractScmMojo mojo )
public void testTag()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

TagMojo mojo = (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tag.xml" ) );
mojo.setWorkingDirectory( checkoutDir );
Expand Down Expand Up @@ -106,6 +122,11 @@ public void testTag()
public void testTagWithTimestamp()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

TagMojo mojo =
(TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tagWithTimestamp.xml" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.provider.git.GitScmTestUtils;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
Expand All @@ -43,6 +44,11 @@ protected void setUp()

repository = getTestFile( "target/repository" );

if ( !ScmTestCase.isSystemCmd( GitScmTestUtils.GIT_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( GitScmTestUtils.GIT_COMMAND_LINE, "setUp" );
return;
}

GitScmTestUtils.initRepo( "src/test/resources/git", repository, checkoutDir );

Expand All @@ -66,6 +72,12 @@ protected void setUp()
public void testUntag()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( GitScmTestUtils.GIT_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( GitScmTestUtils.GIT_COMMAND_LINE, getName() );
return;
}

TagMojo tagMojo = (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/untag/tag.xml" ) );
tagMojo.setWorkingDirectory( checkoutDir );
tagMojo.setConnectionUrl( getConnectionLocalAddress( tagMojo ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public void testSkipCheckoutWithConnectionUrl()

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import java.io.File;

import static org.apache.maven.scm.provider.git.GitScmTestUtils.GIT_COMMAND_LINE;

import static org.junit.Assert.assertEquals;

/**
Expand All @@ -58,11 +60,8 @@ public void setUp()
public void testCheckinNoBranch()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( "git" ) )
{
ScmTestCase.printSystemCmdUnavail( "git", getName() );
return;
}
checkScmPresence( GIT_COMMAND_LINE );

File repo_orig = new File( "src/test/resources/repository_no_branch" );
File repo = getTestFile( "target/git_copy" );
FileUtils.deleteDirectory( repo );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

import java.io.File;

import static org.apache.maven.scm.provider.git.GitScmTestUtils.GIT_COMMAND_LINE;

import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -102,11 +104,7 @@ public void testCheckinAfterRename() throws Exception {
File repo = getRepositoryRoot();
File checkedOutRepo = getWorkingCopy();

if ( !ScmTestCase.isSystemCmd( "git" ) )
{
ScmTestCase.printSystemCmdUnavail( "git", getName() );
return;
}
checkScmPresence( GIT_COMMAND_LINE );

GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());

Expand Down Expand Up @@ -153,11 +151,7 @@ public void testCheckinWithFileSet() throws Exception {
File repo = getRepositoryRoot();
File checkedOutRepo = getWorkingCopy();

if ( !ScmTestCase.isSystemCmd( "git" ) )
{
ScmTestCase.printSystemCmdUnavail( "git", getName() );
return;
}
checkScmPresence( GIT_COMMAND_LINE );

GitScmTestUtils.initRepo( "src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import java.io.File;

import static org.apache.maven.scm.provider.git.GitScmTestUtils.GIT_COMMAND_LINE;

import static org.junit.Assert.assertEquals;

/**
Expand Down Expand Up @@ -64,11 +66,7 @@ public void setUp()
public void testCheckoutNoBranch()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( "git" ) )
{
ScmTestCase.printSystemCmdUnavail( "git", getName() );
return;
}
checkScmPresence( GIT_COMMAND_LINE );
CheckOutScmResult result = checkoutRepo();
assertEquals( 0, result.getCheckedOutFiles().size() );
}
Expand All @@ -77,11 +75,7 @@ public void testCheckoutNoBranch()
public void testDoubleCheckoutNoBranch()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( "git" ) )
{
ScmTestCase.printSystemCmdUnavail( "git", getName() );
return;
}
checkScmPresence( GIT_COMMAND_LINE );
CheckOutScmResult result = checkoutRepo();
assertEquals( 0, result.getCheckedOutFiles().size() );
CheckOutScmResult result2 = checkoutRepo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import java.io.File;

import static org.apache.maven.scm.provider.git.GitScmTestUtils.GIT_COMMAND_LINE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -46,6 +48,8 @@ public class GitInfoCommandTest
public void testInfoCommand()
throws Exception
{
checkScmPresence( GIT_COMMAND_LINE );

GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );

ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
Expand All @@ -62,6 +66,8 @@ public void testInfoCommand()
public void testInfoCommandWithShortRevision()
throws Exception
{
checkScmPresence( GIT_COMMAND_LINE );

GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );

ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
Expand All @@ -79,6 +85,8 @@ public void testInfoCommandWithShortRevision()
public void testInfoCommandWithNegativeShortRevision()
throws Exception
{
checkScmPresence( GIT_COMMAND_LINE );

GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );

ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
Expand All @@ -96,6 +104,8 @@ public void testInfoCommandWithNegativeShortRevision()
public void testInfoCommandWithZeroShortRevision()
throws Exception
{
checkScmPresence( GIT_COMMAND_LINE );

GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );

ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@

import org.apache.maven.scm.provider.svn.command.list.SvnListCommandTckTest;

import static org.apache.maven.scm.provider.svn.SvnScmTestUtils.SVN_COMMAND_LINE;

/**
* @author <a href="mailto:[email protected]">Carlos Sanchez</a>
*
*/
public class SvnExeListCommandTckTest
extends SvnListCommandTckTest
{
@Override
public String getScmProviderCommand()
{
return SVN_COMMAND_LINE;
}
}
Loading