From 6435669274178f26e1fe9260355595595a2de9fe Mon Sep 17 00:00:00 2001 From: CapCap Date: Tue, 19 Dec 2023 16:10:25 -0800 Subject: [PATCH] Add a setting for using --dump on tests --- .../TestCommandConfigurationProducer.kt | 11 ++++++++ .../settings/MoveProjectSettingsService.kt | 7 ++++- .../settings/PerProjectMoveConfigurable.kt | 7 +++++ .../TestCommandConfigurationProducerTest.kt | 28 +++++++++++++++++++ ...function_dumping_state_on_test_failure.xml | 10 +++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/org/move/cli/producers.fixtures/test/test_run_for_function_dumping_state_on_test_failure.xml diff --git a/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducer.kt b/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducer.kt index 950ff99f4..a7b8c9ea5 100644 --- a/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducer.kt +++ b/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducer.kt @@ -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 @@ -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 @@ -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 @@ -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, diff --git a/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt b/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt index 238eabba1..52e14731a 100644 --- a/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt +++ b/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt @@ -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 @@ -177,3 +178,7 @@ fun 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 diff --git a/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt b/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt index 32082fdf6..35b5e74da 100644 --- a/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt +++ b/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt @@ -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." + ) + } } } } diff --git a/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt b/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt index 88172bc85..cdd38dbdc 100644 --- a/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt +++ b/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt @@ -59,6 +59,34 @@ class TestCommandConfigurationProducerTest : RunConfigurationProducerTestBase("t checkOnElement() } + 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() + } + fun `test no test run if no test functions`() { testProject { namedMoveToml("MyPackage") diff --git a/src/test/resources/org/move/cli/producers.fixtures/test/test_run_for_function_dumping_state_on_test_failure.xml b/src/test/resources/org/move/cli/producers.fixtures/test/test_run_for_function_dumping_state_on_test_failure.xml new file mode 100644 index 000000000..1bac8873f --- /dev/null +++ b/src/test/resources/org/move/cli/producers.fixtures/test/test_run_for_function_dumping_state_on_test_failure.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file