Skip to content

Commit

Permalink
add base tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed May 11, 2021
1 parent ab1047d commit c144abf
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 4 deletions.
17 changes: 13 additions & 4 deletions rider-fsharp/src/test/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
}
39 changes: 39 additions & 0 deletions rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[<EntryPoint>]
let main argv = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Simple

type A() =
class
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module EditorConfig

type A () =
class
end
16 changes: 16 additions & 0 deletions rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.fs]
fsharp_space_before_class_constructor=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module EditorConfig

type A() = class end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Folder\EditorConfig.fs" />
<Content Include="Folder\.editorconfig" />
<Compile Include="Simple.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[<EntryPoint>]
let main argv = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Simple

type A() = class end

0 comments on commit c144abf

Please sign in to comment.