<commit_before>/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.rustSlowTests

import com.intellij.codeInspection.ex.InspectionToolRegistrar
import org.junit.ComparisonFailure
import org.rust.ide.inspections.RsLocalInspectionTool
import org.rust.lang.RsFileType
import org.rust.lang.core.psi.RsFile
import org.rust.lang.core.psi.ext.cargoWorkspace
import org.rust.openapiext.toPsiFile
import java.lang.reflect.Field

class RsRealProjectAnalysisTest : RsRealProjectTestBase() {

    /** Don't run it on Rustc! It's a kind of stress-test */
    fun `test analyze rustc`() = doTest(RUSTC)

    fun `test analyze Cargo`() = doTest(CARGO)
    fun `test analyze mysql_async`() = doTest(MYSQL_ASYNC)
    fun `test analyze tokio`() = doTest(TOKIO)

    private fun doTest(info: RealProjectInfo, failOnFirstFileWithErrors: Boolean = false) {
        val inspections = InspectionToolRegistrar.getInstance().createTools()
            .map { it.tool }
            .filter { it is RsLocalInspectionTool }
        myFixture.enableInspections(*inspections.toTypedArray())

        println("Opening the project")
        val base = openRealProject(info) ?: return

        println("Collecting files to analyze")
        val filesToCheck = base.findDescendants {
            it.fileType == RsFileType && run {
                val file = it.toPsiFile(project)
                file is RsFile && file.crateRoot != null && file.cargoWorkspace != null
            }
        }

        if (failOnFirstFileWithErrors) {
            println("Analyzing...")
            myFixture.testHighlightingAllFiles(<commit_msg>T: enable the new macro expansion engine for real project tests<commit_after>/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.rustSlowTests

import com.intellij.codeInspection.ex.InspectionToolRegistrar
import com.intellij.openapi.util.Disposer
import org.junit.ComparisonFailure
import org.rust.ide.inspections.RsLocalInspectionTool
import org.rust.lang.RsFileType
import org.rust.lang.core.macros.MacroExpansionScope
import org.rust.lang.core.macros.macroExpansionManager
import org.rust.lang.core.psi.RsFile
import org.rust.lang.core.psi.ext.cargoWorkspace
import org.rust.openapiext.toPsiFile
import java.lang.reflect.Field

class RsRealProjectAnalysisTest : RsRealProjectTestBase() {

    /** Don't run it on Rustc! It's a kind of stress-test */
    fun `test analyze rustc`() = doTest(RUSTC)

    fun `test analyze Cargo`() = doTest(CARGO)
    fun `test analyze mysql_async`() = doTest(MYSQL_ASYNC)
    fun `test analyze tokio`() = doTest(TOKIO)

    private fun doTest(info: RealProjectInfo, failOnFirstFileWithErrors: Boolean = false) {
        Disposer.register(
            testRootDisposable,
            project.macroExpansionManager.setUnitTestExpansionModeAndDirectory(MacroExpansionScope.ALL, name)
        )
        val inspections = InspectionToolRegistrar.getInstance().createTools()
            .map { it.tool }
            .filter { it is RsLocalInspectionTool }
        myFixture.enableInspections(*inspections.toTypedArray())

        println("Opening the project")
        val base = openRealProject(info) ?: return

        println("Collecting files to analyze")
        val filesToCheck = base.findDescendants {
            it.fileType == RsFileType && run {
                val file = it.toPsiFile(project)
                file is RsFile && file.crateRoot != null && file.cargoWorkspace != null
            }
        }

        if (failOnFirstFileWithErrors) {
            println("Analyzing...")
            myFixture.testHighlightingAllFiles(
{'fraction_non_alphanumeric': 0.09316770186335403, 'fraction_numerical': 0.0, 'mean_word_length': 3.1339285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6438972', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1068, 'n_words': 257}