From c144abfa57c3af66048bf5df3df1f407bb80916f Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Wed, 5 May 2021 00:00:09 +0300 Subject: [PATCH] add base tests --- rider-fsharp/src/test/kotlin/Extensions.kt | 17 ++++++-- .../src/test/kotlin/fantomas/FantomasTest.kt | 39 +++++++++++++++++++ .../formatLastFile/gold/formatLastFile.gold | 2 + .../gold/simpleFormatting.gold | 5 +++ .../gold/withEditorConfig.gold | 5 +++ .../solutions/FormatCodeApp/FormatCodeApp.sln | 16 ++++++++ .../FormatCodeApp/Folder/.editorconfig | 2 + .../FormatCodeApp/Folder/EditorConfig.fs | 3 ++ .../FormatCodeApp/FormatCodeApp.fsproj | 15 +++++++ .../FormatCodeApp/FormatCodeApp/Program.fs | 2 + .../FormatCodeApp/FormatCodeApp/Simple.fs | 3 ++ 11 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt create mode 100644 rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold create mode 100644 rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold create mode 100644 rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs diff --git a/rider-fsharp/src/test/kotlin/Extensions.kt b/rider-fsharp/src/test/kotlin/Extensions.kt index f1a6861602..d00fb79990 100644 --- a/rider-fsharp/src/test/kotlin/Extensions.kt +++ b/rider-fsharp/src/test/kotlin/Extensions.kt @@ -1,8 +1,10 @@ +import com.intellij.openapi.project.Project import com.jetbrains.rdclient.protocol.protocolHost import com.jetbrains.rider.inTests.TestHost import com.jetbrains.rider.plugins.fsharp.rdFSharpModel import com.jetbrains.rider.projectView.solution import com.jetbrains.rider.test.base.BaseTestWithSolution +import com.jetbrains.rider.test.base.EditorTestBase import com.jetbrains.rider.test.scriptingApi.dumpSevereHighlighters import java.io.PrintStream @@ -14,12 +16,19 @@ fun com.intellij.openapi.editor.Editor.dumpTypeProviders(stream: PrintStream) { } } -fun BaseTestWithSolution.withTypeProviders(function: () -> Unit) { - val typeProvidersSetting = "FSharp/FSharpOptions/FSharpExperimentalFeatures/OutOfProcessTypeProviders/@EntryValue" - TestHost.getInstance(project.protocolHost).setSetting(typeProvidersSetting, "true") +fun withSetting(project: Project, setting: String, function: () -> Unit) { + TestHost.getInstance(project.protocolHost).setSetting(setting, "true") try { function() } finally { - TestHost.getInstance(project.protocolHost).setSetting(typeProvidersSetting, "false") + TestHost.getInstance(project.protocolHost).setSetting(setting, "false") } } + +fun BaseTestWithSolution.withTypeProviders(function: () -> Unit) { + withSetting(project, "FSharp/FSharpOptions/FSharpExperimentalFeatures/OutOfProcessTypeProviders/@EntryValue", function) +} + +fun withEditorConfig(project: Project, function: () -> Unit) { + withSetting(project, "CodeStyle/EditorConfig/EnableEditorConfigSupport", function) +} diff --git a/rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt b/rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt new file mode 100644 index 0000000000..f4f4c10159 --- /dev/null +++ b/rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt @@ -0,0 +1,39 @@ +package fantomas + +import com.jetbrains.rdclient.testFramework.executeWithGold +import com.jetbrains.rdclient.testFramework.waitForDaemon +import com.jetbrains.rider.test.annotations.TestEnvironment +import com.jetbrains.rider.test.base.EditorTestBase +import com.jetbrains.rider.test.enums.CoreVersion +import com.jetbrains.rider.test.scriptingApi.dumpOpenedDocument +import com.jetbrains.rider.test.scriptingApi.reformatCode +import com.jetbrains.rider.test.scriptingApi.withOpenedEditor +import org.testng.annotations.Test +import withEditorConfig + +@Test +@TestEnvironment(coreVersion = CoreVersion.DEFAULT) +class FantomasTest : EditorTestBase() { + override fun getSolutionDirectoryName() = "FormatCodeApp" + + @Test + fun withEditorConfig() = doTest("EditorConfig.fs") + + @Test + fun simpleFormatting() = doTest("Simple.fs") + + @Test + fun formatLastFile() = doTest("Program.fs") + + private fun doTest(fileName: String) { + withEditorConfig(project) { + withOpenedEditor(fileName) { + waitForDaemon() + reformatCode() + executeWithGold(testGoldFile) { + dumpOpenedDocument(it, project!!, false) + } + } + } + } +} diff --git a/rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold b/rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold new file mode 100644 index 0000000000..5b77edbd9d --- /dev/null +++ b/rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold @@ -0,0 +1,2 @@ +[] +let main argv = 0 diff --git a/rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold b/rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold new file mode 100644 index 0000000000..ed46f25e8d --- /dev/null +++ b/rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold @@ -0,0 +1,5 @@ +module Simple + +type A() = + class + end diff --git a/rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold b/rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold new file mode 100644 index 0000000000..8aea603375 --- /dev/null +++ b/rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold @@ -0,0 +1,5 @@ +module EditorConfig + +type A () = + class + end diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln new file mode 100644 index 0000000000..4994f64918 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FormatCodeApp", "FormatCodeApp\FormatCodeApp.fsproj", "{CB87B1A7-9600-4AE2-986C-4333196C6AFE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig new file mode 100644 index 0000000000..4337b664d0 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig @@ -0,0 +1,2 @@ +[*.fs] +fsharp_space_before_class_constructor=true diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs new file mode 100644 index 0000000000..f226a682d1 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs @@ -0,0 +1,3 @@ +module EditorConfig + + type A() = class end diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj new file mode 100644 index 0000000000..b57bfd3108 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj @@ -0,0 +1,15 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs new file mode 100644 index 0000000000..1caf613841 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs @@ -0,0 +1,2 @@ + [] + let main argv = 0 diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs new file mode 100644 index 0000000000..d3ccaaec1d --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs @@ -0,0 +1,3 @@ +module Simple + + type A() = class end