Skip to content

Commit 07e2747

Browse files
committed
Use temp dir implementation from cli tests
1 parent 80cf850 commit 07e2747

File tree

6 files changed

+115
-68
lines changed

6 files changed

+115
-68
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty_server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ tracing = { workspace = true }
3838
tracing-subscriber = { workspace = true, features = ["chrono"] }
3939

4040
[dev-dependencies]
41+
dunce = { workspace = true }
4142
insta = { workspace = true, features = ["filters", "json"] }
4243
regex = { workspace = true }
4344
tempfile = { workspace = true }

crates/ty_server/src/server.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -306,49 +306,35 @@ impl Drop for ServerPanicHookHandler {
306306
mod tests {
307307
use anyhow::Result;
308308
use lsp_types::notification::PublishDiagnostics;
309-
use regex::escape;
310309
use ruff_db::system::SystemPath;
311-
use tempfile::TempDir;
312310

313311
use crate::session::ClientOptions;
314312
use crate::test::TestServerBuilder;
315313

316-
fn tempdir_filter(temp_dir: &TempDir) -> String {
317-
format!(r"{}\\?/?", escape(temp_dir.path().to_str().unwrap()))
318-
}
319-
320314
#[test]
321315
fn initialization() -> Result<()> {
322-
let server = TestServerBuilder::new()
316+
let server = TestServerBuilder::new()?
323317
.build()?
324318
.wait_until_workspaces_are_initialized()?;
325319

326320
let initialization_result = server.initialization_result().unwrap();
327321

328-
insta::with_settings!({
329-
filters => vec![(tempdir_filter(server.temp_dir()).as_str(), "[TMP]/")]
330-
}, {
331322
insta::assert_json_snapshot!("initialization", initialization_result);
332-
});
333323

334324
Ok(())
335325
}
336326

337327
#[test]
338328
fn initialization_with_workspace() -> Result<()> {
339329
let workspace_root = SystemPath::new("foo");
340-
let server = TestServerBuilder::new()
330+
let server = TestServerBuilder::new()?
341331
.with_workspace(workspace_root, ClientOptions::default())?
342332
.build()?
343333
.wait_until_workspaces_are_initialized()?;
344334

345335
let initialization_result = server.initialization_result().unwrap();
346336

347-
insta::with_settings!({
348-
filters => vec![(tempdir_filter(server.temp_dir()).as_str(), "[TMP]/")]
349-
}, {
350337
insta::assert_json_snapshot!("initialization_with_workspace", initialization_result);
351-
});
352338

353339
Ok(())
354340
}
@@ -362,21 +348,17 @@ def foo() -> str:
362348
return 42
363349
";
364350

365-
let mut server = TestServerBuilder::new()
351+
let mut server = TestServerBuilder::new()?
366352
.with_workspace(workspace_root, ClientOptions::default())?
367-
.write_file(foo, foo_content)?
353+
.with_file(foo, foo_content)?
368354
.enable_pull_diagnostics(false)
369355
.build()?
370356
.wait_until_workspaces_are_initialized()?;
371357

372358
server.open_text_document(foo, &foo_content);
373359
let diagnostics = server.await_notification::<PublishDiagnostics>()?;
374360

375-
insta::with_settings!({
376-
filters => vec![(tempdir_filter(server.temp_dir()).as_str(), "[TMP]/")]
377-
}, {
378-
insta::assert_debug_snapshot!(diagnostics);
379-
});
361+
insta::assert_debug_snapshot!(diagnostics);
380362

381363
Ok(())
382364
}
@@ -390,21 +372,17 @@ def foo() -> str:
390372
return 42
391373
";
392374

393-
let mut server = TestServerBuilder::new()
394-
.write_file(foo, foo_content)?
375+
let mut server = TestServerBuilder::new()?
395376
.with_workspace(workspace_root, ClientOptions::default())?
377+
.with_file(foo, foo_content)?
396378
.enable_pull_diagnostics(true)
397379
.build()?
398380
.wait_until_workspaces_are_initialized()?;
399381

400382
server.open_text_document(foo, &foo_content);
401383
let diagnostics = server.document_diagnostic_request(foo)?;
402384

403-
insta::with_settings!({
404-
filters => vec![(tempdir_filter(server.temp_dir()).as_str(), "[TMP]/")]
405-
}, {
406385
insta::assert_debug_snapshot!(diagnostics);
407-
});
408386

409387
Ok(())
410388
}

crates/ty_server/src/snapshots/ty_server__server__tests__publish_diagnostics_on_did_open.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PublishDiagnosticsParams {
1010
password: None,
1111
host: None,
1212
port: None,
13-
path: "[TMP]/src/foo.py",
13+
path: "<temp_dir>/src/foo.py",
1414
query: None,
1515
fragment: None,
1616
},
@@ -70,7 +70,7 @@ PublishDiagnosticsParams {
7070
password: None,
7171
host: None,
7272
port: None,
73-
path: "[TMP]/src/foo.py",
73+
path: "<temp_dir>/src/foo.py",
7474
query: None,
7575
fragment: None,
7676
},

crates/ty_server/src/snapshots/ty_server__server__tests__pull_diagnostics_on_did_open.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Report(
6464
password: None,
6565
host: None,
6666
port: None,
67-
path: "[TMP]/src/foo.py",
67+
path: "<temp_dir>/src/foo.py",
6868
query: None,
6969
fragment: None,
7070
},

0 commit comments

Comments
 (0)