Search in sources :

Example 1 with GoModuleBasedConfiguration

use of com.goide.runconfig.GoModuleBasedConfiguration in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTestRunConfiguration method checkConfiguration.

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
    super.checkConfiguration();
    GoModuleBasedConfiguration configurationModule = getConfigurationModule();
    if (!myTestFramework.isAvailable(configurationModule.getModule())) {
        throw new RuntimeConfigurationError("Framework `" + myTestFramework.getName() + "` is not available in selected module");
    }
    switch(myKind) {
        case DIRECTORY:
            String directoryPath = FileUtil.isAbsolutePlatformIndependent(myDirectoryPath) ? myDirectoryPath : FileUtil.join(getWorkingDirectory(), myDirectoryPath);
            if (!FileUtil.isAncestor(getWorkingDirectory(), directoryPath, false)) {
                throw new RuntimeConfigurationError("Working directory should be ancestor of testing directory");
            }
            VirtualFile testingDirectory = LocalFileSystem.getInstance().findFileByPath(directoryPath);
            if (testingDirectory == null) {
                throw new RuntimeConfigurationError("Testing directory doesn't exist");
            }
            break;
        case PACKAGE:
            Module module = configurationModule.getModule();
            assert module != null;
            VirtualFile packageDirectory = GoPackageUtil.findByImportPath(myPackage, module.getProject(), module);
            if (packageDirectory == null || !packageDirectory.isDirectory()) {
                throw new RuntimeConfigurationError("Cannot find package '" + myPackage + "'");
            }
            for (VirtualFile file : packageDirectory.getChildren()) {
                PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
                if (psiFile != null && myTestFramework.isAvailableOnFile(psiFile)) {
                    return;
                }
            }
            String message = "Cannot find Go test files in '" + myPackage + "' compatible with `" + myTestFramework.getName() + "` framework";
            throw new RuntimeConfigurationError(message);
        case FILE:
            VirtualFile virtualFile = findFile(getFilePath());
            if (virtualFile == null) {
                throw new RuntimeConfigurationError("Test file doesn't exist");
            }
            PsiFile file = PsiManager.getInstance(getProject()).findFile(virtualFile);
            if (file == null || !myTestFramework.isAvailableOnFile(file)) {
                message = "Framework `" + myTestFramework.getName() + "` is not available on file `" + myFilePath + "`";
                throw new RuntimeConfigurationError(message);
            }
            break;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) GoModuleBasedConfiguration(com.goide.runconfig.GoModuleBasedConfiguration) Module(com.intellij.openapi.module.Module)

Aggregations

GoModuleBasedConfiguration (com.goide.runconfig.GoModuleBasedConfiguration)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1