Skip to content

Commit 3194f63

Browse files
committed
#24 : Check if symlinks test resources are present and correct
Minor change: Display output in Assert of 'Maven -version' for CommandlineTest
1 parent a9bc91d commit 3194f63

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.net.URI;
2222
import java.net.URISyntaxException;
2323
import java.net.URL;
24+
import java.nio.file.Files;
25+
import java.nio.file.Paths;
2426
import java.util.ArrayList;
2527
import java.util.Arrays;
2628
import java.util.List;
@@ -33,6 +35,7 @@
3335
public class DirectoryScannerTest
3436
extends FileBasedTestCase
3537
{
38+
3639
private static String testDir = getTestDirectory().getPath();
3740

3841
public void testCrossPlatformIncludesString()
@@ -110,6 +113,44 @@ private void createTestFiles()
110113
this.createFile( new File( testDir + "/scanner5.dat" ), 0 );
111114
}
112115

116+
/**
117+
* Check if 'src/test/resources/symlinks/src/sym*' test files (start with 'sym') exist and are symlinks.<br>
118+
* On some OS (like Windows 10), the 'git clone' requires to be executed with admin permissions and the
119+
* 'core.symlinks=true' git option.
120+
*
121+
* @return true If files here and symlinks, false otherwise
122+
*/
123+
private boolean checkTestFilesSymlinks()
124+
{
125+
File symlinksDirectory = new File( "src/test/resources/symlinks/src" );
126+
try
127+
{
128+
List<String> symlinks =
129+
FileUtils.getFileAndDirectoryNames( symlinksDirectory, "sym*", null, true, true, true, true );
130+
if ( symlinks.isEmpty() )
131+
{
132+
throw new IOException( "Symlinks files/directories are not present" );
133+
}
134+
for ( String symLink : symlinks )
135+
{
136+
if ( !Files.isSymbolicLink( Paths.get( symLink ) ) )
137+
{
138+
throw new IOException( String.format( "Path is not a symlink: %s", symLink ) );
139+
}
140+
}
141+
return true;
142+
}
143+
catch ( IOException e )
144+
{
145+
System.err.println( String.format( "The unit test '%s.%s' will be skipped, reason: %s",
146+
this.getClass().getSimpleName(), this.getName(), e.getMessage() ) );
147+
System.out.println( String.format( "This test requires symlinks files in '%s' directory.",
148+
symlinksDirectory.getPath() ) );
149+
System.out.println( "On some OS (like Windows 10), files are present only if the clone/checkout is done in administrator mode, and correct (symlinks and not flat file/directory) if symlinks option are used (for git: git clone -c core.symlinks=true [url])" );
150+
return false;
151+
}
152+
}
153+
113154
public void testGeneral()
114155
throws IOException
115156
{
@@ -146,6 +187,10 @@ public void testIncludesExcludesWithWhiteSpaces()
146187

147188
public void testFollowSymlinksFalse()
148189
{
190+
if ( !checkTestFilesSymlinks() )
191+
{
192+
return;
193+
}
149194
DirectoryScanner ds = new DirectoryScanner();
150195
ds.setBasedir( new File( "src/test/resources/symlinks/src/" ) );
151196
ds.setFollowSymlinks( false );
@@ -177,6 +222,10 @@ private void assertAlwaysIncluded( List<String> included )
177222

178223
public void testFollowSymlinks()
179224
{
225+
if ( !checkTestFilesSymlinks() )
226+
{
227+
return;
228+
}
180229
DirectoryScanner ds = new DirectoryScanner();
181230
ds.setBasedir( new File( "src/test/resources/symlinks/src/" ) );
182231
ds.setFollowSymlinks( true );
@@ -446,8 +495,7 @@ private void assertInclusionsAndExclusions( String[] files, String[] excludedPat
446495
StringBuilder buffer = new StringBuilder();
447496
if ( !failedToExclude.isEmpty() )
448497
{
449-
buffer.append( "Should NOT have included:\n" ).append(
450-
StringUtils.join( failedToExclude.iterator(),
498+
buffer.append( "Should NOT have included:\n" ).append( StringUtils.join( failedToExclude.iterator(),
451499
"\n\t- " ) );
452500
}
453501

@@ -458,8 +506,8 @@ private void assertInclusionsAndExclusions( String[] files, String[] excludedPat
458506
buffer.append( "\n\n" );
459507
}
460508

461-
buffer.append( "Should have included:\n" )
462-
.append( StringUtils.join( failedToInclude.iterator(), "\n\t- " ) );
509+
buffer.append( "Should have included:\n" ).append( StringUtils.join( failedToInclude.iterator(),
510+
"\n\t- " ) );
463511
}
464512

465513
if ( buffer.length() > 0 )

src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ public void testExecuteBinaryOnPath()
100100
cmd.createArg().setValue( "-version" );
101101
Process process = cmd.execute();
102102
String out = IOUtil.toString( process.getInputStream() );
103-
assertTrue( out.contains( "Apache Maven" ) );
104-
assertTrue( out.contains( "Maven home:" ) );
105-
assertTrue( out.contains( "Java version:" ) );
106-
assertTrue( out.contains( "Java home:" ) );
103+
final String msg = String.format( "Maven seems not in PATH, 'mvn -version' result is: %s", out );
104+
assertTrue( msg, out.contains( "Apache Maven" ) );
105+
assertTrue( msg, out.contains( "Maven home:" ) );
106+
assertTrue( msg, out.contains( "Java version:" ) );
107+
assertTrue( msg, out.contains( "Java home:" ) );
107108
}
108109
catch ( Exception e )
109110
{

0 commit comments

Comments
 (0)