Skip to content

Commit 9a8d9f8

Browse files
authored
Merge pull request #17491 from github/redsun82/rust-integration-test
Rust: add basic integration tests and fix archiving on Windows
2 parents e43d39a + 9f8c3c5 commit 9a8d9f8

34 files changed

+167
-51
lines changed

Cargo.lock

Lines changed: 22 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/extractor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ triomphe = "0.1.13"
2525
argfile = "0.2.1"
2626
codeql-extractor = { path = "../../shared/tree-sitter-extractor" }
2727
rust-extractor-macros = { path = "macros" }
28+
itertools = "0.13.0"

rust/extractor/src/archive.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::path;
1+
use codeql_extractor::file_paths;
22
use log::{debug, warn};
33
use std::fs;
44
use std::path::{Path, PathBuf};
@@ -15,12 +15,11 @@ impl Archiver {
1515
}
1616

1717
fn try_archive(&self, source: &Path) -> std::io::Result<()> {
18-
let mut dest = self.root.clone();
19-
dest.push(path::key(source));
20-
let parent = dest.parent().unwrap();
18+
let dest = file_paths::path_for(&self.root, source, "");
2119
if fs::metadata(&dest).is_ok() {
2220
return Ok(());
2321
}
22+
let parent = dest.parent().unwrap();
2423
fs::create_dir_all(parent)?;
2524
fs::copy(source, dest)?;
2625
debug!("archived {}", source.display());

rust/extractor/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::trap::TrapId;
22
use anyhow::Context;
3+
use itertools::Itertools;
4+
use log::info;
35
use ra_ap_hir::db::DefDatabase;
46
use ra_ap_hir::Crate;
57
use ra_ap_load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
@@ -11,7 +13,6 @@ use std::path::PathBuf;
1113
mod archive;
1214
mod config;
1315
pub mod generated;
14-
pub mod path;
1516
mod translate;
1617
pub mod trap;
1718

@@ -23,9 +24,12 @@ fn find_project_manifests(
2324
.iter()
2425
.map(|path| AbsPathBuf::assert_utf8(current.join(path)))
2526
.collect();
26-
Ok(ra_ap_project_model::ProjectManifest::discover_all(
27-
&abs_files,
28-
))
27+
let ret = ra_ap_project_model::ProjectManifest::discover_all(&abs_files);
28+
info!(
29+
"found manifests: {}",
30+
ret.iter().map(|m| format!("{m}")).join(", ")
31+
);
32+
Ok(ret)
2933
}
3034

3135
fn main() -> anyhow::Result<()> {

rust/extractor/src/path.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

rust/extractor/src/trap.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use crate::config;
12
use crate::config::Compression;
2-
use crate::{config, path};
3-
use codeql_extractor::{extractor, trap};
3+
use codeql_extractor::{extractor, file_paths, trap};
44
use log::debug;
55
use ra_ap_ide_db::line_index::LineCol;
6-
use std::ffi::OsString;
76
use std::fmt::Debug;
87
use std::hash::Hash;
98
use std::marker::PhantomData;
@@ -12,7 +11,6 @@ use std::path::{Path, PathBuf};
1211
pub use trap::Label as UntypedLabel;
1312
pub use trap::Writer;
1413

15-
//TODO: typed labels
1614
pub trait AsTrapKeyPart {
1715
fn as_key_part(&self) -> String;
1816
}
@@ -210,19 +208,8 @@ impl TrapFileProvider {
210208
}
211209

212210
pub fn create(&self, category: &str, key: &Path) -> TrapFile {
213-
let mut path = PathBuf::from(category);
214-
path.push(path::key(key));
215-
path.set_extension(
216-
path.extension()
217-
.map(|e| {
218-
let mut o: OsString = e.to_owned();
219-
o.push(".trap");
220-
o
221-
})
222-
.unwrap_or("trap".into()),
223-
);
211+
let path = file_paths::path_for(&self.trap_dir.join(category), key, ".trap");
224212
debug!("creating trap file {}", path.display());
225-
path = self.trap_dir.join(path);
226213
let mut writer = trap::Writer::new();
227214
extractor::populate_empty_location(&mut writer);
228215
TrapFile {

rust/integration-tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
import shutil
3+
4+
class _Manifests:
5+
def __init__(self, cwd):
6+
self.dir = cwd / "manifests"
7+
8+
def select(self, name: str):
9+
(self.dir / name).rename(name)
10+
shutil.rmtree(self.dir)
11+
12+
13+
@pytest.fixture
14+
def manifests(cwd):
15+
return _Manifests(cwd)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| src/main.rs:4:1:6:1 | main |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import rust
2+
3+
from Function f
4+
where exists(f.getLocation().getFile().getRelativePath())
5+
select f
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
[package]
3+
name = "hello-cargo"
4+
version = "0.1.0"
5+
edition = "2021"
6+
7+
[dependencies]

0 commit comments

Comments
 (0)