10000 Merge #4139 · intellij-rust/intellij-rust@aa64fb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa64fb7

Browse files
bors[bot]Paul Emmerich
andauthored
Merge #4139
4139: RUN: enable --show-output when executing tests r=mchernyavsky a=emmericp Fixes #3994 This requires this patch for rust (hopefully in 1.38?): rust-lang/rust#62600 This is work in progress because it doesn't work yet, I'm looking for some help here: The problem is you can't run `rustVersion()` in the UI thread and I'd really like to have this behavior as default if the compiler is new enough. What's the best way to achieve this? Fallback would be to make this an option for the run configuration, but that would be a little bit annoying since virtually everyone would want to enable this? Edit: changed the code to hardcode 1.38 as Rust version passed to `patchArgs` because I'm using this branch ;) Looking for a good way to get the Rust version here. <!-- Hello and thank you for the pull request! We don't have any strict rules about pull requests, but you might check https://github.com/intellij-rust/intellij-rust/blob/master/CONTRIBUTING.md for some hints! Note that we need an electronic CLA for contributions: https://github.com/intellij-rust/intellij-rust/blob/master/CONTRIBUTING.md#cla After you sign the CLA, please add your name to https://github.com/intellij-rust/intellij-rust/blob/master/CONTRIBUTORS.txt :) --> Co-authored-by: Paul Emmerich <paul.emmerich@croit.io>
2 parents 19803ff + 50cc65d commit aa64fb7

File tree

6 files changed

+126
-12
lines changed

6 files changed

+126
-12
lines changed

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ daschl
2828
dem1tris
2929
devurandom
3030
Dimonchik0036
31+
emmericp
3132
Falkenfighter
3233
fan-tom
3334
farodin91

src/main/kotlin/org/rust/cargo/runconfig/CargoTestRunState.kt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,26 @@ import com.intellij.execution.configurations.RunConfiguration
1313
import com.intellij.execution.runners.ExecutionEnvironment
1414
import com.intellij.execution.runners.ProgramRunner
1515
import com.intellij.execution.testframework.autotest.ToggleAutoTestAction
16+
import com.intellij.util.text.SemVer
1617
import org.rust.cargo.runconfig.buildtool.CargoPatch
1718
import org.rust.cargo.runconfig.command.CargoCommandConfiguration
1819
import org.rust.cargo.runconfig.console.CargoTestConsoleBuilder
1920
import org.rust.cargo.toolchain.CargoCommandLine
21+
import org.rust.cargo.toolchain.RustChannel
22+
import org.rust.cargo.toolchain.RustcVersion
23+
import java.time.LocalDate
2024

2125
class CargoTestRunState(
2226
environment: ExecutionEnvironment,
2327
runConfiguration: CargoCommandConfiguration,
2428
config: CargoCommandConfiguration.CleanConfiguration.Ok
2529
) : CargoRunStateBase(environment, runConfiguration, config) {
2630

31+
private val cargoTestPatch: CargoPatch = { commandLine ->
32+
val rustcVer = cargoProject?.rustcInfo?.version
33+
commandLine.copy(additionalArguments = patchArgs(commandLine, rustcVer))
34+
}
35+
2736
init {
2837
consoleBuilder = CargoTestConsoleBuilder(environment.runProfile as RunConfiguration, environment.executor)
2938
addCommandLinePatch(cargoTestPatch)
@@ -38,12 +47,9 @@ class CargoTestRunState(
3847
}
3948

4049
companion object {
41-
val cargoTestPatch: CargoPatch = { commandLine ->
42-
commandLine.copy(additionalArguments = patchArgs(commandLine))
43-
}
4450

4551
@VisibleForTesting
46-
fun patchArgs(commandLine: CargoCommandLine): List<String> {
52+
fun patchArgs(commandLine: CargoCommandLine, rustcVer: RustcVersion?): List<String> {
4753
val (pre, post) = commandLine.splitOnDoubleDash()
4854
.let { (pre, post) -> pre.toMutableList() to post.toMutableList() }
4955

@@ -60,7 +66,24 @@ class CargoTestRunState(
6066

6167
addFormatJsonOption(post, "--format")
6268

69+
if (checkShowOutputSupport(rustcVer)) {
70+
post.add("--show-output")
71+
}
72+
6373
return if (post.isEmpty()) pre else pre + "--" + post
6474
}
75+
76+
private fun checkShowOutputSupport(ver: RustcVersion?): Boolean {
77+
if (ver == null) return false
78+
// --show-output is supported since 1.39.0-nightly/dev with a build date later than 2019-08-27
79+
val minRelease = SemVer.parseFromText("1.39.0")
80+
val commitDate = LocalDate.of(2019, 8, 27)
81+
return when {
82+
ver.semver > minRelease -> true
83+
ver.semver < minRelease -> false
84+
else ->
85+
ver.channel.index <= RustChannel.BETA.index || ver.commitDate?.isAfter(commitDate) ?: false
86+
}
87+
}
6588
}
6689
}

src/main/kotlin/org/rust/cargo/runconfig/test/CargoTestEventsConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class CargoTestEventsConverter(
155155
}
156156
"ok" -> {
157157
val duration = getTestDuration(testMessage.name)
158+
if (!testMessage.stdout.isNullOrEmpty()) messages.add(createTestStdOutMessage(testMessage.name, testMessage.stdout))
158159
messages.add(createTestFinishedMessage(testMessage.name, duration))
159160
recordSuiteChildFinished(testMessage.name)
160161
processFinishedSuites(messages)

src/main/kotlin/org/rust/cargo/toolchain/RustChannel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ enum class RustChannel(val index: Int, val channel: String?) {
99
DEFAULT(0, null),
1010
STABLE(1, "stable"),
1111
BETA(2, "beta"),
12-
NIGHTLY(3, "nightly");
12+
NIGHTLY(3, "nightly"),
13+
DEV(4, "dev");
1314

1415
override fun toString(): String = channel ?: "[default]"
1516

1617
companion object {
17-
fun fromIndex(index: Int) = RustChannel.values().find { it.index == index } ?: RustChannel.DEFAULT
18+
fun fromIndex(index: Int) = values().find { it.index == index } ?: DEFAULT
1819
}
1920
}

src/main/kotlin/org/rust/cargo/toolchain/RustToolchain.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import org.rust.openapiext.*
1414
import java.io.File
1515
import java.nio.file.Files
1616
import java.nio.file.Path
17+
import java.time.LocalDate
18+
import java.time.format.DateTimeParseException
1719

1820
data class RustToolchain(val location: Path) {
1921

@@ -114,7 +116,7 @@ data class RustcVersion(
114116
val host: String,
115117
val channel: RustChannel,
116118
val commitHash: String? = null,
117-
val commitDate: String? = null
119+
val commitDate: LocalDate? = null
118120
)
119121

120122
private fun scrapeRustcVersion(rustc: Path): RustcVersion? {
@@ -144,15 +146,19 @@ private fun scrapeRustcVersion(rustc: Path): RustcVersion? {
144146
val hostText = find(hostRe)?.groups?.get(1)?.value ?: return null
145147
val versionText = releaseMatch.groups[1]?.value ?: return null
146148
val commitHash = find(commitHashRe)?.groups?.get(1)?.value
147-
val commitDate = find(commitDateRe)?.groups?.get(1)?.value
149+
val commitDate = try {
150+
LocalDate.parse(find(commitDateRe)?.groups?.get(1)?.value)
151+
} catch (e: DateTimeParseException) {
152+
null
153+
}
148154

149155
val semVer = SemVer.parseFromText(versionText) ?: return null
150-
151156
val releaseSuffix = releaseMatch.groups[2]?.value.orEmpty()
152157
val channel = when {
153158
releaseSuffix.isEmpty() -> RustChannel.STABLE
154159
releaseSuffix.startsWith("-beta") -> RustChannel.BETA
155160
releaseSuffix.startsWith("-nightly") -> RustChannel.NIGHTLY
161+
releaseSuffix.startsWith("-dev") -> RustChannel.DEV
156162
else -> RustChannel.DEFAULT
157163
}
158164
return RustcVersion(semVer, hostText, channel, commitHash, commitDate)

src/test/kotlin/org/rust/cargo/runconfig/CargoTestRunStateTest.kt

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
package org.rust.cargo.runconfig
77

88
import com.intellij.util.execution.ParametersListUtil
9-
import org.junit.Assert.assertEquals
9+
import com.intellij.util.text.SemVer
10+
import org.junit.Assert.*
1011
import org.junit.Test
1112
import org.junit.runner.RunWith
1213
import org.junit.runners.Parameterized
1314
import org.rust.cargo.toolchain.CargoCommandLine
15+
import org.rust.cargo.toolchain.RustChannel
16+
import org.rust.cargo.toolchain.RustcVersion
1417
import java.nio.file.Path
1518
import java.nio.file.Paths
19+
import java.time.LocalDate
1620

1721
@RunWith(Parameterized::class)
1822
class CargoTestRunStatePatchArgsTest(
@@ -22,9 +26,29 @@ class CargoTestRunStatePatchArgsTest(
2226
private val wd: Path = Paths.get("/my-crate")
2327

2428
@Test
25-
fun test() = assertEquals(
29+
fun `test without show output`() = assertEquals(
2630
ParametersListUtil.parse(expected),
27-
CargoTestRunState.patchArgs(CargoCommandLine("run", wd, ParametersListUtil.parse(input)))
31+
CargoTestRunState.patchArgs(
32+
CargoCommandLine("run", wd, ParametersListUtil.parse(input)),
33+
RustcVersion(
34+
SemVer.parseFromText("1.38.0")!!,
35+
"x86_64-unknown-linux-gnu",
36+
RustChannel.STABLE
37+
)
38+
)
39+
)
40+
41+
@Test
42+
fun `test with show output`() = assertEquals(
43+
ParametersListUtil.parse(expected) + "--show-output",
44+
CargoTestRunState.patchArgs(
45+
CargoCommandLine("run", wd, ParametersListUtil.parse(input)),
46+
RustcVersion(
47+
SemVer.parseFromText("1.39.0")!!,
48+
"x86_64-unknown-linux-gnu",
49+
RustChannel.STABLE
50+
)
51+
)
2852
)
2953

3054
companion object {
@@ -44,3 +68,61 @@ class CargoTestRunStatePatchArgsTest(
4468
)
4569
}
4670
}
71+
72+
class CargoTestRunStatePatchArgsShowOutputEnableTest {
73+
74+
private fun patchArgs(version: String, channel: RustChannel, date: LocalDate) = CargoTestRunState.patchArgs(
75+
CargoCommandLine("run", Paths.get("/my-crate"), ParametersListUtil.parse("")),
76+
RustcVersion(
77+
SemVer.parseFromText(version)!!,
78+
"x86_64-unknown-linux-gnu",
79+
channel,
80+
null,
81+
date
82+
)
83+
)
84+
85+
// --show-output should be enabled on rustc 1.39 nightly and dev builds with a build date >= 2019-08-28
86+
// and on all stable and beta versions >= 1.39
87+
@Test
88+
fun `old versions should never use --show-output`() {
89+
assertFalse(
90+
patchArgs("1.38.0", RustChannel.STABLE, LocalDate.of(2019, 12, 31))
91+
.contains("--show-output")
92+
)
93+
assertFalse(
94+
patchArgs("1.38.0", RustChannel.NIGHTLY, LocalDate.of(2019, 12, 31))
95+
.contains("--show-output")
96+
)
97+
assertFalse(
98+
patchArgs("1.38.0", RustChannel.BETA, LocalDate.of(2019, 12, 31))
99+
.contains("--show-output")
100+
)
101+
assertFalse(
102+
patchArgs("1.39.0", RustChannel.NIGHTLY, LocalDate.of(2019, 8, 27))
103+
.contains("--show-output")
104+
)
105+
}
106+
107+
@Test
108+
fun `new versions should use --show-output`() {
109+
// beta and stable always has the option, ignoring build date
110+
assertTrue(
111+
patchArgs("1.39.0", RustChannel.STABLE, LocalDate.of(2019, 7, 28))
112+
.contains("--show-output")
113+
)
114+
assertTrue(
115+
patchArgs("1.39.0", RustChannel.BETA, LocalDate.of(2019, 7, 28))
116+
.contains("--show-output")
117+
)
118+
// nightly and dev only if it's new enough
119+
assertTrue(
120+
patchArgs("1.39.0", RustChannel.NIGHTLY, LocalDate.of(2019, 8, 28))
121+
.contains("--show-output")
122+
)
123+
assertTrue(
124+
patchArgs("1.39.0", RustChannel.DEV, LocalDate.of(2019, 8, 28))
125+
.contains("--show-output")
126+
)
127+
}
128+
}

0 commit comments

Comments
 (0)
0