-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fall back to the default temporary directory for ctags check
fixes #4574
- Loading branch information
Showing
4 changed files
with
45 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,14 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2019, Chris Fraire <[email protected]>. | ||
*/ | ||
package org.opengrok.indexer.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.opengrok.indexer.configuration.RuntimeEnvironment; | ||
|
||
import java.io.IOException; | ||
|
@@ -35,6 +37,9 @@ | |
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.times; | ||
|
||
/** | ||
* Represents a container for tests of {@link CtagsUtil}. | ||
|
@@ -51,19 +56,40 @@ void getLanguages() { | |
} | ||
|
||
@Test | ||
void validate() throws IOException { | ||
void testIsValid() throws IOException { | ||
RuntimeEnvironment env = RuntimeEnvironment.getInstance(); | ||
Path tmpSourceRoot = Files.createTempDirectory("srcRootCtagsValidationTest"); | ||
env.setSourceRoot(tmpSourceRoot.toString()); | ||
assertTrue(env.getSourceRootFile().exists()); | ||
|
||
assertTrue(CtagsUtil.validate(env.getCtags())); | ||
assertTrue(CtagsUtil.isValid(env.getCtags())); | ||
|
||
Files.delete(tmpSourceRoot); | ||
} | ||
|
||
/** | ||
* Simulate non-writable source root and verify that {@link CtagsUtil#isValid(String)} still returns true | ||
* as it should fall back to default temporary directory. | ||
*/ | ||
@Test | ||
void testValidateWithInvalidExtraOptions() throws IOException { | ||
void testIsValidNoWritableSourceRoot() throws IOException { | ||
RuntimeEnvironment env = RuntimeEnvironment.getInstance(); | ||
Path tmpSourceRoot = Files.createTempDirectory("negativeCtagsValidationTest"); | ||
env.setSourceRoot(tmpSourceRoot.toString()); | ||
assertTrue(env.getSourceRootFile().exists()); | ||
|
||
try (MockedStatic<CtagsUtil> mocked = mockStatic(CtagsUtil.class, Mockito.CALLS_REAL_METHODS)) { | ||
mocked.when(() -> CtagsUtil.canProcessFiles(env.getSourceRootFile())).thenReturn(false); | ||
assertTrue(CtagsUtil.isValid(env.getCtags())); | ||
mocked.verify(() -> CtagsUtil.canProcessFiles(eq(env.getSourceRootFile())), | ||
times(2)); // one extra for the lambda call above | ||
} | ||
|
||
Files.delete(tmpSourceRoot); | ||
} | ||
|
||
@Test | ||
void testIsValidWithInvalidExtraOptions() throws IOException { | ||
RuntimeEnvironment env = RuntimeEnvironment.getInstance(); | ||
Path tmpSourceRoot = Files.createTempDirectory("srcRootCtagsValidationTestExtraArgs"); | ||
env.setSourceRoot(tmpSourceRoot.toString()); | ||
|
@@ -74,7 +100,7 @@ void testValidateWithInvalidExtraOptions() throws IOException { | |
String extraOptionsAbsPath = extraOptionsPath.toAbsolutePath().toString(); | ||
|
||
env.setCTagsExtraOptionsFile(extraOptionsAbsPath); | ||
assertFalse(CtagsUtil.validate(env.getCtags())); | ||
assertFalse(CtagsUtil.isValid(env.getCtags())); | ||
|
||
// cleanup | ||
env.setCTagsExtraOptionsFile(null); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected]>. | |
<maven-surefire.version>3.0.0-M5</maven-surefire.version> | ||
<apache-commons-lang3.version>3.13.0</apache-commons-lang3.version> | ||
<micrometer.version>1.11.4</micrometer.version> | ||
<mockito.version>3.12.4</mockito.version> | ||
<mockito.version>5.2.0</mockito.version> | ||
<commons-io.version>2.14.0</commons-io.version> | ||
</properties> | ||
|
||
|