Skip to content

Commit

Permalink
Add a setting for using --dump on tests (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
CapCap authored Jan 16, 2024
1 parent ca6aed6 commit d84d0aa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.move.cli.MoveProject
import org.move.cli.runConfigurations.aptos.AptosCommandLine
import org.move.cli.runConfigurations.aptos.AptosConfigurationType
import org.move.cli.runConfigurations.aptos.any.AnyCommandConfigurationFactory
import org.move.cli.settings.dumpStateOnTestFailure
import org.move.cli.settings.skipFetchLatestGitDeps
import org.move.lang.MoveFile
import org.move.lang.core.psi.MvFunction
Expand Down Expand Up @@ -63,6 +64,9 @@ class TestCommandConfigurationProducer : CommandConfigurationProducerBase() {
if (psi.project.skipFetchLatestGitDeps) {
subCommand += " --skip-fetch-latest-git-deps"
}
if (psi.project.dumpStateOnTestFailure) {
subCommand += " --dump"
}

val moveProject = fn.moveProject ?: return null
val rootPath = moveProject.contentRootPath ?: return null
Expand All @@ -84,6 +88,9 @@ class TestCommandConfigurationProducer : CommandConfigurationProducerBase() {
if (psi.project.skipFetchLatestGitDeps) {
subCommand += " --skip-fetch-latest-git-deps"
}
if (psi.project.dumpStateOnTestFailure) {
subCommand += " --dump"
}

val moveProject = mod.moveProject ?: return null
val rootPath = moveProject.contentRootPath ?: return null
Expand All @@ -106,6 +113,10 @@ class TestCommandConfigurationProducer : CommandConfigurationProducerBase() {
if (location.project.skipFetchLatestGitDeps) {
subCommand += " --skip-fetch-latest-git-deps"
}
if (location.project.dumpStateOnTestFailure) {
subCommand += " --dump"
}


return CommandLineFromContext(
location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class MoveProjectSettingsService(private val project: Project): PersistentStateC
var foldSpecs: Boolean = false,
var disableTelemetry: Boolean = true,
var debugMode: Boolean = false,
var skipFetchLatestGitDeps: Boolean = false
var skipFetchLatestGitDeps: Boolean = false,
var dumpStateOnTestFailure: Boolean = false,
) {
fun aptosExec(): AptosExec {
val path = aptosPath
Expand Down Expand Up @@ -177,3 +178,7 @@ fun <T> Project.debugErrorOrFallback(message: String, cause: Throwable?, fallbac
val Project.skipFetchLatestGitDeps: Boolean
get() =
this.moveSettings.state.skipFetchLatestGitDeps

val Project.dumpStateOnTestFailure: Boolean
get() =
this.moveSettings.state.dumpStateOnTestFailure
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class PerProjectMoveConfigurable(val project: Project) : BoundConfigurable("Move
"Adds --skip-fetch-latest-git-deps to the test runs."
)
}
row {
checkBox("Dump storage to console on test failures")
.bindSelected(settingsState::dumpStateOnTestFailure)
comment(
"Adds --dump to the test runs."
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ class TestCommandConfigurationProducerTest : RunConfigurationProducerTestBase("t
checkOnElement<MvFunction>()
}

fun `test test run for function dumping state on test failure`() {
testProject {
namedMoveToml("MyPackage")
tests {
move(
"MoveTests.move", """
#[test_only]
module 0x1::MoveTests {
#[test]
fun /*caret*/test_add() {
1 + 1;
}
#[test]
fun test_mul() {
1 * 1;
}
}
"""
)
}
}
this.project.moveSettings
.modifyTemporary(this.testRootDisposable) {
it.dumpStateOnTestFailure = true
}
checkOnElement<MvFunction>()
}

fun `test no test run if no test functions`() {
testProject {
namedMoveToml("MyPackage")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configurations>
<configuration name="Test MoveTests::test_add" type="AptosCommandConfiguration" factoryName="AnyCommand">
<option name="command" value="move test --filter MoveTests::test_add --dump" />
<option name="workingDirectory" value="file://" />
<envs>
<env name="APTOS_DISABLE_TELEMETRY" value="true" />
</envs>
<method v="2" />
</configuration>
</configurations>

0 comments on commit d84d0aa

Please sign in to comment.