Skip to content

Commit 189f844

Browse files
committed
Add submodules for the integration tests
DeepSpeech "v0.9.3" pdf.js "v2.12.313" rust "1.57.0"
1 parent c21be13 commit 189f844

File tree

9 files changed

+30
-71
lines changed

9 files changed

+30
-71
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
target
22
enums/target
3-
tests/repositories
43
*~

.gitmodules

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[submodule "tests/repositories/rca-output"]
2+
path = tests/repositories/rca-output
3+
url = https://github.com/SoftengPoliTo/rca-output
4+
[submodule "tests/repositories/DeepSpeech"]
5+
path = tests/repositories/DeepSpeech
6+
url = https://github.com/mozilla/DeepSpeech
7+
[submodule "tests/repositories/rust"]
8+
path = tests/repositories/rust
9+
url = https://github.com/rust-lang/rust.git
10+
[submodule "tests/repositories/pdf.js"]
11+
path = tests/repositories/pdf.js
12+
url = https://github.com/mozilla/pdf.js

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.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ crossbeam = { version = "^0.8", features = ["crossbeam-channel"] }
1616
fxhash = "0.2"
1717
globset = "^0.4"
1818
lazy_static = "^1.3"
19+
once_cell = "1.12.1"
1920
num = "^0.4"
2021
num-derive = "^0.3"
2122
num-format = "^0.4"

tests/repositories/DeepSpeech

Submodule DeepSpeech added at f2e9c85

tests/repositories/pdf.js

Submodule pdf.js added at a2ae56f

tests/repositories/rca-output

Submodule rca-output added at 16033b9

tests/repositories/rust

Submodule rust added at f1edd04

tests/test.rs

Lines changed: 12 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
use globset::GlobSet;
22
use globset::{Glob, GlobSetBuilder};
3+
use once_cell::sync::Lazy;
34
use rust_code_analysis::LANG;
45
use rust_code_analysis::*;
56
use std::fs::*;
67
use std::io::BufReader;
78
use std::path::Path;
89
use std::path::PathBuf;
910
use std::process;
10-
use std::process::Command;
11-
use std::sync::Once;
12-
13-
// Synchronization primitive
14-
static INIT: Once = Once::new();
1511

1612
#[derive(Debug)]
1713
struct Config {
1814
language: Option<LANG>,
19-
output_folder: String,
15+
output_folder: PathBuf,
2016
}
2117

2218
fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> {
@@ -37,15 +33,11 @@ fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> {
3733
};
3834

3935
// Build json file path
40-
let file_path = Path::new(&cfg.output_folder)
41-
.join(path.strip_prefix("./").unwrap())
42-
.into_os_string()
43-
.into_string()
44-
.unwrap()
45-
+ ".json";
36+
let mut file_path = cfg.output_folder.join(path.strip_prefix("./").unwrap());
37+
file_path.set_extension("json");
4638

4739
// Produce and compare metrics only if json file exists
48-
if Path::new(&file_path).exists() {
40+
if file_path.exists() {
4941
// Get FuncSpace struct
5042
let funcspace_struct = get_function_spaces(&language, source, &path, None).unwrap();
5143

@@ -182,32 +174,15 @@ fn compare_f64(f1: f64, f2: &serde_json::Value) {
182174
}
183175
}
184176

185-
const OUTPUT_FOLDER: &str = "./tests/repositories/rca-output";
177+
static REPO: Lazy<&Path> = Lazy::new(|| &Path::new("./tests/repositories"));
186178

187179
/// Produces metrics runtime and compares them with previously generated json files
188-
fn compare_rca_output_with_files(
189-
repo_branch: &str,
190-
repo_url: &str,
191-
repo_folder: &str,
192-
include: &[&str],
193-
) {
194-
// The first test clones the repository
195-
// Next tests wait here until the repository is cloned
196-
INIT.call_once(|| {
197-
clone_repository(
198-
"main",
199-
"https://github.com/SoftengPoliTo/rca-output.git",
200-
OUTPUT_FOLDER,
201-
);
202-
});
203-
204-
clone_repository(repo_branch, repo_url, repo_folder);
205-
180+
fn compare_rca_output_with_files(repo_name: &str, include: &[&str]) {
206181
let num_jobs = 4;
207182

208183
let cfg = Config {
209184
language: None,
210-
output_folder: OUTPUT_FOLDER.to_owned(),
185+
output_folder: REPO.join("rca-output"),
211186
};
212187

213188
let mut gsbi = GlobSetBuilder::new();
@@ -218,7 +193,7 @@ fn compare_rca_output_with_files(
218193
let files_data = FilesData {
219194
include: gsbi.build().unwrap(),
220195
exclude: GlobSet::empty(),
221-
paths: vec![Path::new(repo_folder).to_path_buf()],
196+
paths: vec![REPO.join(repo_name)],
222197
};
223198

224199
if let Err(e) = ConcurrentRunner::new(num_jobs, act_on_file).run(cfg, files_data) {
@@ -227,50 +202,17 @@ fn compare_rca_output_with_files(
227202
}
228203
}
229204

230-
/// Runs a git clone command
231-
fn clone_repository(branch: &str, url: &str, destination: &str) {
232-
if !Path::new(destination).exists() {
233-
Command::new("git")
234-
.args([
235-
"clone",
236-
"--depth",
237-
"1",
238-
"--branch",
239-
branch,
240-
url,
241-
destination,
242-
])
243-
.output()
244-
.expect("Git clone failed");
245-
}
246-
}
247-
248205
#[test]
249206
fn test_deepspeech() {
250-
compare_rca_output_with_files(
251-
"v0.9.3",
252-
"https://github.com/mozilla/DeepSpeech.git",
253-
"./tests/repositories/DeepSpeech",
254-
&["*.cc", "*.cpp", "*.h", "*.hh"],
255-
);
207+
compare_rca_output_with_files("DeepSpeech", &["*.cc", "*.cpp", "*.h", "*.hh"]);
256208
}
257209

258210
#[test]
259211
fn test_pdfjs() {
260-
compare_rca_output_with_files(
261-
"v2.12.313",
262-
"https://github.com/mozilla/pdf.js.git",
263-
"./tests/repositories/pdf.js",
264-
&["*.js"],
265-
);
212+
compare_rca_output_with_files("pdf.js", &["*.js"]);
266213
}
267214

268215
#[test]
269216
fn test_rust_library() {
270-
compare_rca_output_with_files(
271-
"1.57.0",
272-
"https://github.com/rust-lang/rust.git",
273-
"./tests/repositories/rust",
274-
&["*/library/*.rs"],
275-
);
217+
compare_rca_output_with_files("rust", &["*/library/*.rs"]);
276218
}

0 commit comments

Comments
 (0)