mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-28 17:44:10 +00:00
2855eaecb5
Fixes clippy warning in Rust 1.68. BUG=b:276487055 TEST=tools/clippy # with rust 1.68 Change-Id: I4482f26ac58de31931b82da5962899afc90f5377 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391105 Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Dennis Kempin <denniskempin@google.com>
62 lines
2 KiB
Rust
62 lines
2 KiB
Rust
// Copyright 2022 The ChromiumOS Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use std::env;
|
|
|
|
use prebuilts::download_prebuilt;
|
|
use prebuilts::download_prebuilts;
|
|
use tempfile::TempDir;
|
|
|
|
static LIBRARY: &str = "prebuilts_test";
|
|
static PREBUILT_FILE1: &str = "prebuilt_test";
|
|
static PREBUILT_FILE2: &str = "prebuilt_test2";
|
|
static VERSION: u32 = 1;
|
|
|
|
fn setup_env(build_type: &str) -> TempDir {
|
|
let tempdir = tempfile::tempdir().unwrap();
|
|
if build_type == "debug" {
|
|
env::set_var("DEBUG", "");
|
|
} else {
|
|
env::remove_var("DEBUG");
|
|
}
|
|
env::set_var("CARGO_CFG_TARGET_FAMILY", "windows");
|
|
env::set_var("CARGO_CFG_TARGET_ARCH", "x86_64");
|
|
env::set_var("CARGO_CFG_TARGET_ENV", "gnu");
|
|
let deps = tempdir.path().join("deps");
|
|
std::fs::create_dir_all(deps).unwrap();
|
|
let out_dir = tempdir.path().join("build").join("crate_name").join("out");
|
|
std::fs::create_dir_all(&out_dir).unwrap();
|
|
env::set_var("OUT_DIR", out_dir.as_os_str().to_str().unwrap());
|
|
tempdir
|
|
}
|
|
|
|
#[test]
|
|
fn test_download_prebuilt() {
|
|
for build_type in ["release", "debug"] {
|
|
let _tempdir = setup_env(build_type);
|
|
let file = download_prebuilt(LIBRARY, VERSION, PREBUILT_FILE1).unwrap();
|
|
assert!(file.exists());
|
|
assert_eq!(
|
|
std::fs::read_to_string(&file).unwrap(),
|
|
format!("hello world {}\n", build_type)
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_download_prebuilt_files() {
|
|
for build_type in ["release", "debug"] {
|
|
let _tempdir = setup_env(build_type);
|
|
let files =
|
|
download_prebuilts(LIBRARY, VERSION, &[PREBUILT_FILE1, PREBUILT_FILE2]).unwrap();
|
|
for file in files {
|
|
assert!(file.exists());
|
|
assert_eq!(
|
|
std::fs::read_to_string(&file).unwrap(),
|
|
format!("hello world {}\n", build_type),
|
|
"failed for file {file:?}"
|
|
);
|
|
}
|
|
}
|
|
}
|