Skip to content

Commit

Permalink
Add tests for run config
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Oct 1, 2020
1 parent d454420 commit 15e3d4f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class LatexRunConfiguration constructor(project: Project,
/**
* Get the content root of the main file.
*/
private fun getMainFileContentRoot(): VirtualFile? {
fun getMainFileContentRoot(): VirtualFile? {
if (mainFile == null) return null
return runReadAction {
return@runReadAction ProjectRootManager.getInstance(project).fileIndex.getContentRootForFile(mainFile!!)
Expand Down
24 changes: 24 additions & 0 deletions test/nl/hannahsten/texifyidea/run/LatexOutputPathTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nl.hannahsten.texifyidea.run

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.latex.LatexOutputPath
import nl.hannahsten.texifyidea.run.latex.LatexRunConfiguration
import nl.hannahsten.texifyidea.run.latex.LatexRunConfigurationProducer

class LatexOutputPathTest : BasePlatformTestCase() {

fun testOutputPathCreate() {
val mainFile = myFixture.addFileToProject("main.tex", """
\documentclass{article}
\begin{document}
main
\end{document}
""".trimIndent())
val runConfig = LatexRunConfiguration(myFixture.project, LatexRunConfigurationProducer().configurationFactory, "Test run config")
runConfig.psiFile = mainFile
runConfig.setMainFile("main.tex")
val outPath = LatexOutputPath("out", runConfig.getMainFileContentRoot(), runConfig.mainFile, project)
// Cannot mkdirs in test, so will default to src
assertEquals("/src", outPath.getAndCreatePath()?.path)
}
}
42 changes: 42 additions & 0 deletions test/nl/hannahsten/texifyidea/run/LatexRunConfigurationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nl.hannahsten.texifyidea.run

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.bibtex.BibtexRunConfiguration
import nl.hannahsten.texifyidea.run.compiler.LatexCompiler
import nl.hannahsten.texifyidea.run.latex.LatexOutputPath
import nl.hannahsten.texifyidea.run.latex.LatexRunConfiguration
import nl.hannahsten.texifyidea.run.latex.LatexRunConfigurationProducer
import org.jdom.Element
import org.jdom.Namespace

class LatexRunConfigurationTest : BasePlatformTestCase() {

fun testWriteRead() {
val runConfig = LatexRunConfiguration(myFixture.project, LatexRunConfigurationProducer().configurationFactory, "Test run config")
val element = Element("configuration", Namespace.getNamespace("", ""))
runConfig.compiler = LatexCompiler.LATEXMK
runConfig.outputPath.pathString = LatexOutputPath.projectDirString + "otherout"
runConfig.writeExternal(element)
runConfig.readExternal(element)
// Not sure if this actually tests anything
assertEquals(runConfig.compiler, LatexCompiler.LATEXMK)
assertEquals(runConfig.outputPath.pathString, LatexOutputPath.projectDirString + "otherout")
}

fun testBibRunConfig() {
val mainFile = myFixture.addFileToProject("main.tex", """
\documentclass{article}
\begin{document}
When you are not looking at it, this sentences stops citing~\cite{knuth1990,goossens1993}.
\bibliography{references}
\bibliographystyle{plain}
\end{document}
""".trimIndent())
val runConfig = LatexRunConfiguration(myFixture.project, LatexRunConfigurationProducer().configurationFactory, "Test run config")
runConfig.psiFile = mainFile
runConfig.setMainFile("main.tex")
runConfig.generateBibRunConfig()
assertTrue(runConfig.bibRunConfigs.isNotEmpty())
assertEquals(mainFile.virtualFile, (runConfig.bibRunConfigs.first().configuration as BibtexRunConfiguration).mainFile)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.hannahsten.texifyidea.run
package nl.hannahsten.texifyidea.run.logtab

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.bibtex.logtab.BibtexLogMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.hannahsten.texifyidea.run
package nl.hannahsten.texifyidea.run.logtab

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.latex.logtab.LatexFileStack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.hannahsten.texifyidea.run
package nl.hannahsten.texifyidea.run.logtab

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.latex.logtab.LatexLogMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.hannahsten.texifyidea.run
package nl.hannahsten.texifyidea.run.logtab

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.bibtex.logtab.BibtexLogMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.hannahsten.texifyidea.run
package nl.hannahsten.texifyidea.run.logtab

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.run.bibtex.logtab.BibtexLogMessage
Expand Down

0 comments on commit 15e3d4f

Please sign in to comment.