Skip to content

Commit

Permalink
T: disable org.rust.cargo.fetch.actual.stdlib.metadata in test by d…
Browse files Browse the repository at this point in the history
…efault

It significantly slows down tests without actual necessity. Enable this feature only in some tests that actually use/check it
  • Loading branch information
Undin committed Mar 29, 2021
1 parent 965d53e commit bb51918
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/test/kotlin/org/rust/RsTestBase.kt
Expand Up @@ -41,6 +41,7 @@ import org.rust.cargo.project.workspace.FeatureDep
import org.rust.cargo.project.workspace.PackageFeature
import org.rust.cargo.toolchain.RustChannel
import org.rust.cargo.toolchain.impl.RustcVersion
import org.rust.ide.experiments.RsExperiments
import org.rust.lang.core.macros.findExpansionElements
import org.rust.lang.core.macros.macroExpansionManager
import org.rust.lang.core.psi.ext.startOffset
Expand Down Expand Up @@ -81,6 +82,8 @@ abstract class RsTestBase : BasePlatformTestCase(), RsTestCase {
Disposer.register(testRootDisposable, disposable)
}
RecursionManager.disableMissedCacheAssertions(testRootDisposable)
// RsExperiments.FETCH_ACTUAL_STDLIB_METADATA significantly slows down tests
setExperimentalFeatureEnabled(RsExperiments.FETCH_ACTUAL_STDLIB_METADATA, false, testRootDisposable)
tempDirRoot = myFixture.findFileInTempDir(".")
tempDirRootUrl = tempDirRoot?.url
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/org/rust/cargo/RsWithToolchainTestBase.kt
Expand Up @@ -5,6 +5,7 @@

package org.rust.cargo

import com.intellij.openapi.Disposable
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.RecursionManager
import com.intellij.openapi.vfs.VirtualFile
Expand All @@ -16,6 +17,7 @@ import com.intellij.util.ui.UIUtil
import org.rust.*
import org.rust.cargo.project.model.impl.testCargoProjects
import org.rust.cargo.toolchain.tools.rustc
import org.rust.ide.experiments.RsExperiments
import org.rust.lang.core.macros.macroExpansionManager
import org.rust.openapiext.pathAsPath

Expand Down Expand Up @@ -91,6 +93,8 @@ abstract class RsWithToolchainTestBase : CodeInsightFixtureTestCase<ModuleFixtur
)
)
}
// RsExperiments.FETCH_ACTUAL_STDLIB_METADATA significantly slows down tests
setExperimentalFeatureEnabled(RsExperiments.FETCH_ACTUAL_STDLIB_METADATA, false, testRootDisposable)
}

override fun tearDown() {
Expand All @@ -102,6 +106,10 @@ abstract class RsWithToolchainTestBase : CodeInsightFixtureTestCase<ModuleFixtur

protected open fun createRustupFixture(): RustupTestFixture = RustupTestFixture(project)

override fun getTestRootDisposable(): Disposable {
return if (myFixture != null) myFixture.testRootDisposable else super.getTestRootDisposable()
}

protected fun buildProject(builder: FileTreeBuilder.() -> Unit): TestProject =
fileTree { builder() }.create()

Expand Down
10 changes: 10 additions & 0 deletions src/test/kotlin/org/rust/common.kt
Expand Up @@ -5,11 +5,13 @@

package org.rust

import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DataKey
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.ui.TestDialog
import com.intellij.openapi.ui.TestDialogManager
import com.intellij.openapi.util.Disposer
import com.intellij.testFramework.TestApplicationManager
import com.intellij.testFramework.TestDataProvider
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
Expand All @@ -21,6 +23,8 @@ import org.rust.cargo.project.workspace.FeatureName
import org.rust.cargo.project.workspace.FeatureState
import org.rust.lang.core.macros.MACRO_EXPANSION_VFS_ROOT
import org.rust.lang.core.macros.MacroExpansionFileSystem
import org.rust.openapiext.isFeatureEnabled
import org.rust.openapiext.setFeatureEnabled

fun checkMacroExpansionFileSystemAfterTest() {
val vfs = MacroExpansionFileSystem.getInstance()
Expand Down Expand Up @@ -113,3 +117,9 @@ fun <T> withTestDialog(testDialog: TestDialog, action: () -> T): T {
TestDialogManager.setTestDialog(oldDialog)
}
}

fun setExperimentalFeatureEnabled(featureId: String, enabled: Boolean, disposable: Disposable) {
val oldValue = isFeatureEnabled(featureId)
setFeatureEnabled(featureId, enabled)
Disposer.register(disposable) { setFeatureEnabled(featureId, oldValue) }
}
46 changes: 26 additions & 20 deletions src/test/kotlin/org/rustSlowTests/RsProjectViewTestBase.kt
Expand Up @@ -12,6 +12,8 @@ import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.ProjectViewTestUtil
import org.rust.cargo.RsWithToolchainTestBase
import org.rust.cargo.project.model.cargoProjects
import org.rust.ide.experiments.RsExperiments
import org.rust.openapiext.runWithEnabledFeatures
import javax.swing.JTree
import javax.swing.tree.DefaultMutableTreeNode
import javax.swing.tree.TreePath
Expand All @@ -24,15 +26,17 @@ abstract class RsProjectViewTestBase : RsWithToolchainTestBase() {
}

fun `test external library node`() {
buildProject {
toml("Cargo.toml", """
[package]
name = "intellij-rust-test"
version = "0.1.0"
authors = []
""")
dir("src") {
rust("main.rs", "")
runWithEnabledFeatures(RsExperiments.FETCH_ACTUAL_STDLIB_METADATA) {
buildProject {
toml("Cargo.toml", """
[package]
name = "intellij-rust-test"
version = "0.1.0"
authors = []
""")
dir("src") {
rust("main.rs", "")
}
}
}

Expand All @@ -43,18 +47,20 @@ abstract class RsProjectViewTestBase : RsWithToolchainTestBase() {
}

fun `test external library node with external dependencies`() {
buildProject {
toml("Cargo.toml", """
[package]
name = "intellij-rust-test"
version = "0.1.0"
authors = []
runWithEnabledFeatures(RsExperiments.FETCH_ACTUAL_STDLIB_METADATA) {
buildProject {
toml("Cargo.toml", """
[package]
name = "intellij-rust-test"
version = "0.1.0"
authors = []
[dependencies]
code-generation-example = "^0.1.0"
""")
dir("src") {
rust("main.rs", "")
[dependencies]
code-generation-example = "^0.1.0"
""")
dir("src") {
rust("main.rs", "")
}
}
}

Expand Down

0 comments on commit bb51918

Please sign in to comment.