Skip to content

Commit bba8d2d

Browse files
committed
move env vars for snapshot tests to UpdateTest
1 parent 1dcce45 commit bba8d2d

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

crates/ide/src/runnables.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt, ops::Not};
1+
use std::fmt;
22

33
use ast::HasName;
44
use cfg::{CfgAtom, CfgExpr};
@@ -20,7 +20,7 @@ use span::{Edition, TextSize};
2020
use stdx::format_to;
2121
use syntax::{
2222
ast::{self, AstNode},
23-
SmolStr, SyntaxNode, ToSmolStr,
23+
format_smolstr, SmolStr, SyntaxNode, ToSmolStr,
2424
};
2525

2626
use crate::{references, FileId, NavigationTarget, ToNav, TryToNav};
@@ -639,7 +639,25 @@ impl UpdateTest {
639639
}
640640

641641
let res: SmolStr = builder.join(" + ").into();
642-
res.is_empty().not().then_some(res)
642+
if res.is_empty() {
643+
None
644+
} else {
645+
Some(format_smolstr!("↺\u{fe0e} Update Tests ({res})"))
646+
}
647+
}
648+
649+
pub fn env(&self) -> SmallVec<[(&str, &str); 3]> {
650+
let mut env = SmallVec::new();
651+
if self.expect_test {
652+
env.push(("UPDATE_EXPECT", "1"));
653+
}
654+
if self.insta {
655+
env.push(("INSTA_UPDATE", "always"));
656+
}
657+
if self.snapbox {
658+
env.push(("SNAPSHOTS", "overwrite"));
659+
}
660+
env
643661
}
644662
}
645663

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ pub(crate) fn handle_runnables(
943943

944944
let update_test = runnable.update_test;
945945
if let Some(mut runnable) = to_proto::runnable(&snap, runnable)? {
946-
if let Some(runnable) = to_proto::make_update_runnable(&runnable, &update_test.label())
946+
if let Some(runnable) =
947+
to_proto::make_update_runnable(&runnable, &update_test.label(), &update_test.env())
947948
{
948949
res.push(runnable);
949950
}
@@ -2135,10 +2136,7 @@ fn runnable_action_links(
21352136
}
21362137

21372138
let client_commands_config = snap.config.client_commands();
2138-
if !(client_commands_config.run_single
2139-
|| client_commands_config.debug_single
2140-
|| client_commands_config.update_single)
2141-
{
2139+
if !(client_commands_config.run_single || client_commands_config.debug_single) {
21422140
return None;
21432141
}
21442142

@@ -2158,8 +2156,10 @@ fn runnable_action_links(
21582156
group.commands.push(to_command_link(dbg_command, r.label.clone()));
21592157
}
21602158

2161-
if hover_actions_config.update_test && client_commands_config.update_single {
2162-
if let Some(update_command) = to_proto::command::update_single(&r, &update_test.label()) {
2159+
if hover_actions_config.update_test && client_commands_config.run_single {
2160+
let label = update_test.label();
2161+
if let Some(r) = to_proto::make_update_runnable(&r, &label, &update_test.env()) {
2162+
let update_command = to_proto::command::run_single(&r, label.unwrap().as_str());
21632163
group.commands.push(to_command_link(update_command, r.label.clone()));
21642164
}
21652165
}

crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,8 @@ pub(crate) fn code_lens(
16061606
}
16071607
if lens_config.update_test && client_commands_config.run_single {
16081608
let label = update_test.label();
1609-
if let Some(r) = make_update_runnable(&r, &label) {
1609+
let env = update_test.env();
1610+
if let Some(r) = make_update_runnable(&r, &label, &env) {
16101611
let command = command::run_single(&r, label.unwrap().as_str());
16111612
acc.push(lsp_types::CodeLens {
16121613
range: annotation_range,
@@ -1851,9 +1852,10 @@ pub(crate) mod command {
18511852
}
18521853
}
18531854

1854-
fn make_update_runnable(
1855+
pub(crate) fn make_update_runnable(
18551856
runnable: &lsp_ext::Runnable,
18561857
label: &Option<SmolStr>,
1858+
env: &[(&str, &str)],
18571859
) -> Option<lsp_ext::Runnable> {
18581860
if !matches!(runnable.args, lsp_ext::RunnableArgs::Cargo(_)) {
18591861
return None;
@@ -1867,9 +1869,7 @@ fn make_update_runnable(
18671869
unreachable!();
18681870
};
18691871

1870-
let environment_vars =
1871-
[("UPDATE_EXPECT", "1"), ("INSTA_UPDATE", "always"), ("SNAPSHOTS", "overwrite")];
1872-
r.environment.extend(environment_vars.into_iter().map(|(k, v)| (k.to_owned(), v.to_owned())));
1872+
r.environment.extend(env.iter().map(|(k, v)| (k.to_string(), v.to_string())));
18731873

18741874
Some(runnable)
18751875
}

0 commit comments

Comments
 (0)