Skip to content

Commit 1b08f50

Browse files
committed
throw on buildDirPath and testsDirPath failure
1 parent 5f8bec0 commit 1b08f50

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotAllProjectSettings.kt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package org.utbot.cpp.clion.plugin.settings
33
import com.intellij.openapi.components.Service
44
import com.intellij.openapi.components.service
55
import com.intellij.openapi.project.Project
6-
import com.jetbrains.cidr.cpp.execution.CMakeAppRunConfiguration
6+
import org.utbot.cpp.clion.plugin.UTBot
7+
import org.utbot.cpp.clion.plugin.grpc.IllegalPathException
78
import org.utbot.cpp.clion.plugin.listeners.UTBotSettingsChangedListener
89
import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
910
import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded
1011
import org.utbot.cpp.clion.plugin.utils.isWindows
11-
import org.utbot.cpp.clion.plugin.utils.notifyWarning
1212
import org.utbot.cpp.clion.plugin.utils.path
1313
import java.io.File
14+
import java.nio.file.InvalidPathException
1415
import java.nio.file.Path
1516
import java.nio.file.Paths
1617

@@ -20,10 +21,36 @@ class UTBotAllProjectSettings(val project: Project) {
2021
get() = project.service<UTBotProjectStoredSettings>().state
2122

2223
val buildDirPath: Path
23-
get() = Paths.get(project.path).resolve(storedSettings.buildDirRelativePath)
24+
get() {
25+
try {
26+
return Paths.get(project.path).resolve(storedSettings.buildDirRelativePath)
27+
} catch (e: InvalidPathException) {
28+
throw IllegalPathException(
29+
UTBot.message(
30+
"paths.invalid",
31+
"relative path to build dir",
32+
storedSettings.buildDirRelativePath
33+
),
34+
storedSettings.buildDirRelativePath
35+
)
36+
}
37+
}
2438

2539
val testsDirPath: Path
26-
get() = Paths.get(project.path).resolve(storedSettings.testsDirRelativePath)
40+
get() {
41+
try {
42+
return Paths.get(project.path).resolve(storedSettings.testsDirRelativePath)
43+
} catch (e: InvalidPathException) {
44+
throw IllegalPathException(
45+
storedSettings.testsDirRelativePath,
46+
UTBot.message(
47+
"paths.invalid",
48+
"relative path to tests dir",
49+
storedSettings.testsDirRelativePath
50+
)
51+
)
52+
}
53+
}
2754

2855
val convertedSourcePaths: List<String>
2956
get() = storedSettings.sourceDirs.map { it.convertToRemotePathIfNeeded(project) }
@@ -52,7 +79,7 @@ class UTBotAllProjectSettings(val project: Project) {
5279

5380
fun fireUTBotSettingsChanged() {
5481
project.messageBus.let { bus ->
55-
if(!bus.isDisposed)
82+
if (!bus.isDisposed)
5683
bus.syncPublisher(UTBotSettingsChangedListener.TOPIC).settingsChanged(this)
5784
}
5885
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/testsResults/UTBotTestRunLineMarkerProvider.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import com.intellij.psi.PsiElement
1111
import javax.swing.Icon
1212
import kotlin.io.path.name
1313
import org.utbot.cpp.clion.plugin.actions.generate.RunWithCoverageAction
14+
import org.utbot.cpp.clion.plugin.grpc.IllegalPathException
1415
import org.utbot.cpp.clion.plugin.settings.settings
1516
import org.utbot.cpp.clion.plugin.ui.services.TestsResultsStorage
1617
import org.utbot.cpp.clion.plugin.utils.localPath
18+
import org.utbot.cpp.clion.plugin.utils.logger
1719
import testsgen.Testgen
1820

1921
class UTBotTestRunLineMarkerProvider : LineMarkerProvider {
@@ -57,10 +59,15 @@ class UTBotTestRunLineMarkerProvider : LineMarkerProvider {
5759

5860
private fun isElementInTestFileGeneratedByUTBot(element: PsiElement) =
5961
element.containingFile.virtualFile.localPath.let {
60-
it.toString().startsWith(element.project.settings.testsDirPath.toString()) &&
61-
it.name.contains("test")
62+
try {
63+
it.toString().startsWith(element.project.settings.testsDirPath.toString()) &&
64+
it.name.contains("test")
65+
} catch (e: IllegalPathException) {
66+
return false
67+
}
6268
}
6369

70+
6471
fun getStatusIcon(element: PsiElement): Icon {
6572
// return icon for Running All Tests
6673
if (element.canPlaceAllTestsIcon()) {

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/UiUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.intellij.ui.DocumentAdapter
1010
import com.intellij.ui.RawCommandLineEditor
1111
import com.intellij.ui.dsl.builder.Row
1212
import com.intellij.ui.layout.PropertyBinding
13-
import javax.swing.JSpinner
1413
import javax.swing.JTextField
1514
import javax.swing.event.DocumentEvent
1615

clion-plugin/src/main/resources/messages/UTBot.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ folderPath.wrong.conversion=Could not create relative path from remote path to f
6161
filePath.wrong.conversion=Could not create relative path from remote path to file path! Review your remote path in settings \
6262
and make sure file you generate tests for is under project root.
6363
# hardly it will ever happen
64+
#0 - path name (e.g relative path to ...), #1 - path value
65+
paths.invalid=Invalid {0}: {1}. Please review it in settings!
6466
projectPath.wrong.conversion=Could not convert project path to remote version. Please, report this issue, <a href=https://github.com/UnitTestBot/UTBotCpp/issues>here</a>
6567
testFilePath.wrong.conversion=Could not create relative path from remote path to test file! Please review your remote path in settings \
6668
and make sure test file is under project root.

0 commit comments

Comments
 (0)