mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor logging configuration and streamline command execution in tests
- Updated the main function to conditionally disable file logging based on the `ATLAS_NO_FILE_LOG` environment variable, enhancing flexibility in logging behavior. - Introduced a new `atlas_command` function to encapsulate command creation for tests, ensuring consistent command execution across various test files. - Replaced direct usage of `ROJO_PATH` with `atlas_command` in multiple test utilities, improving code clarity and maintainability. These changes aim to enhance the logging setup and simplify command handling in the test suite.
This commit is contained in:
parent
c0f5a01e17
commit
380041dc2a
7 changed files with 35 additions and 27 deletions
12
src/main.rs
12
src/main.rs
|
|
@ -55,10 +55,14 @@ fn main() {
|
||||||
|
|
||||||
let project_dir = options.subcommand.project_path().map(resolve_project_dir);
|
let project_dir = options.subcommand.project_path().map(resolve_project_dir);
|
||||||
|
|
||||||
let file_log_level = project_dir
|
let file_log_level = if env::var("ATLAS_NO_FILE_LOG").is_ok() {
|
||||||
.as_deref()
|
None
|
||||||
.and_then(logging::quick_read_file_log_level)
|
} else {
|
||||||
.unwrap_or(Some(tracing::level_filters::LevelFilter::TRACE));
|
project_dir
|
||||||
|
.as_deref()
|
||||||
|
.and_then(logging::quick_read_file_log_level)
|
||||||
|
.unwrap_or(Some(tracing::level_filters::LevelFilter::TRACE))
|
||||||
|
};
|
||||||
|
|
||||||
let command_name = format!("atlas-{}", options.subcommand.command_name());
|
let command_name = format!("atlas-{}", options.subcommand.command_name());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,18 @@ use std::{
|
||||||
fs,
|
fs,
|
||||||
io::{self, Read},
|
io::{self, Read},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Child,
|
process::{Child, Command},
|
||||||
};
|
};
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub static ROJO_PATH: &str = env!("CARGO_BIN_EXE_atlas");
|
pub static ROJO_PATH: &str = env!("CARGO_BIN_EXE_atlas");
|
||||||
|
|
||||||
|
pub fn atlas_command() -> Command {
|
||||||
|
let mut cmd = Command::new(ROJO_PATH);
|
||||||
|
cmd.env("ATLAS_NO_FILE_LOG", "1");
|
||||||
|
cmd
|
||||||
|
}
|
||||||
pub static BUILD_TESTS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/rojo-test/build-tests");
|
pub static BUILD_TESTS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/rojo-test/build-tests");
|
||||||
pub static SERVE_TESTS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/rojo-test/serve-tests");
|
pub static SERVE_TESTS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/rojo-test/serve-tests");
|
||||||
pub static SYNCBACK_TESTS_PATH: &str =
|
pub static SYNCBACK_TESTS_PATH: &str =
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@ use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
use super::io_util::ROJO_PATH;
|
use super::io_util::atlas_command;
|
||||||
|
|
||||||
/// Run `rojo build` on a project and return the output file path.
|
/// Run `rojo build` on a project and return the output file path.
|
||||||
///
|
///
|
||||||
|
|
@ -25,7 +24,7 @@ pub fn run_rojo_build(project_path: &Path, output_name: &str) -> (TempDir, PathB
|
||||||
let output_dir = tempfile::tempdir().expect("Failed to create temp dir for build output");
|
let output_dir = tempfile::tempdir().expect("Failed to create temp dir for build output");
|
||||||
let output_path = output_dir.path().join(output_name);
|
let output_path = output_dir.path().join(output_name);
|
||||||
|
|
||||||
let output = Command::new(ROJO_PATH)
|
let output = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"build",
|
"build",
|
||||||
project_path.to_str().unwrap(),
|
project_path.to_str().unwrap(),
|
||||||
|
|
@ -57,7 +56,7 @@ pub fn run_rojo_syncback_clean(project_path: &Path, input_path: &Path) -> bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = Command::new(ROJO_PATH)
|
let output = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"syncback",
|
"syncback",
|
||||||
project_path.to_str().unwrap(),
|
project_path.to_str().unwrap(),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
fs,
|
fs,
|
||||||
io::Read as _,
|
io::Read as _,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::Stdio,
|
||||||
thread,
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
@ -22,7 +22,7 @@ use librojo::web_api::{
|
||||||
use rojo_insta_ext::RedactionMap;
|
use rojo_insta_ext::RedactionMap;
|
||||||
|
|
||||||
use crate::rojo_test::io_util::{
|
use crate::rojo_test::io_util::{
|
||||||
copy_recursive, get_working_dir_path, KillOnDrop, ROJO_PATH, SERVE_TESTS_PATH,
|
atlas_command, copy_recursive, get_working_dir_path, KillOnDrop, SERVE_TESTS_PATH,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Convenience method to run a `rojo serve` test.
|
/// Convenience method to run a `rojo serve` test.
|
||||||
|
|
@ -110,7 +110,7 @@ impl TestServeSession {
|
||||||
let port = get_port_number();
|
let port = get_port_number();
|
||||||
let port_string = port.to_string();
|
let port_string = port.to_string();
|
||||||
|
|
||||||
let rojo_process = Command::new(ROJO_PATH)
|
let rojo_process = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"serve",
|
"serve",
|
||||||
project_path.to_str().unwrap(),
|
project_path.to_str().unwrap(),
|
||||||
|
|
@ -163,7 +163,7 @@ impl TestServeSession {
|
||||||
let port = get_port_number();
|
let port = get_port_number();
|
||||||
let port_string = port.to_string();
|
let port_string = port.to_string();
|
||||||
|
|
||||||
let rojo_process = Command::new(ROJO_PATH)
|
let rojo_process = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"serve",
|
"serve",
|
||||||
project_path.to_str().unwrap(),
|
project_path.to_str().unwrap(),
|
||||||
|
|
@ -223,7 +223,7 @@ impl TestServeSession {
|
||||||
let port = get_port_number();
|
let port = get_port_number();
|
||||||
let port_string = port.to_string();
|
let port_string = port.to_string();
|
||||||
|
|
||||||
let rojo_process = Command::new(ROJO_PATH)
|
let rojo_process = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"serve",
|
"serve",
|
||||||
project_path.to_str().unwrap(),
|
project_path.to_str().unwrap(),
|
||||||
|
|
@ -257,7 +257,7 @@ impl TestServeSession {
|
||||||
let port_string = port.to_string();
|
let port_string = port.to_string();
|
||||||
let working_dir = get_working_dir_path();
|
let working_dir = get_working_dir_path();
|
||||||
|
|
||||||
let rojo_process = Command::new(ROJO_PATH)
|
let rojo_process = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"serve",
|
"serve",
|
||||||
self.project_path.to_str().unwrap(),
|
self.project_path.to_str().unwrap(),
|
||||||
|
|
@ -777,7 +777,7 @@ pub fn run_cli_syncback_on_chunks(
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
chunks: &[librojo::web_api::ServiceChunk],
|
chunks: &[librojo::web_api::ServiceChunk],
|
||||||
) -> (TempDir, PathBuf) {
|
) -> (TempDir, PathBuf) {
|
||||||
use crate::rojo_test::io_util::{copy_recursive, ROJO_PATH, SERVE_TESTS_PATH};
|
use crate::rojo_test::io_util::{atlas_command, copy_recursive, SERVE_TESTS_PATH};
|
||||||
|
|
||||||
let source_path = Path::new(SERVE_TESTS_PATH).join(fixture_name);
|
let source_path = Path::new(SERVE_TESTS_PATH).join(fixture_name);
|
||||||
let dir = tempdir().expect("Couldn't create temp dir for CLI syncback");
|
let dir = tempdir().expect("Couldn't create temp dir for CLI syncback");
|
||||||
|
|
@ -789,7 +789,7 @@ pub fn run_cli_syncback_on_chunks(
|
||||||
let rbxl_path = dir.path().join("input.rbxl");
|
let rbxl_path = dir.path().join("input.rbxl");
|
||||||
fs::write(&rbxl_path, rbxl_data).expect("Failed to write rbxl");
|
fs::write(&rbxl_path, rbxl_data).expect("Failed to write rbxl");
|
||||||
|
|
||||||
let output = std::process::Command::new(ROJO_PATH)
|
let output = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"syncback",
|
"syncback",
|
||||||
project_path.to_str().unwrap(),
|
project_path.to_str().unwrap(),
|
||||||
|
|
@ -984,7 +984,7 @@ pub fn fresh_rebuild_read(project_path: &Path) -> NormalizedInstance {
|
||||||
let port = get_port_number();
|
let port = get_port_number();
|
||||||
let port_string = port.to_string();
|
let port_string = port.to_string();
|
||||||
|
|
||||||
let process = Command::new(ROJO_PATH)
|
let process = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"serve",
|
"serve",
|
||||||
project_file.to_str().unwrap(),
|
project_file.to_str().unwrap(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{io::Write as _, path::Path, process::Command};
|
use std::{io::Write as _, path::Path};
|
||||||
|
|
||||||
use insta::{assert_snapshot, assert_yaml_snapshot};
|
use insta::{assert_snapshot, assert_yaml_snapshot};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
@ -6,7 +6,7 @@ use tempfile::tempdir;
|
||||||
|
|
||||||
use crate::rojo_test::io_util::SYNCBACK_TESTS_PATH;
|
use crate::rojo_test::io_util::SYNCBACK_TESTS_PATH;
|
||||||
|
|
||||||
use super::io_util::{copy_recursive, ROJO_PATH};
|
use super::io_util::{atlas_command, copy_recursive};
|
||||||
|
|
||||||
const INPUT_FILE_PROJECT: &str = "input-project";
|
const INPUT_FILE_PROJECT: &str = "input-project";
|
||||||
const INPUT_FILE_PLACE: &str = "input.rbxl";
|
const INPUT_FILE_PLACE: &str = "input.rbxl";
|
||||||
|
|
@ -82,7 +82,7 @@ fn run_syncback_test_impl(name: &str, incremental: bool, callback: impl FnOnce(&
|
||||||
args.push("--incremental");
|
args.push("--incremental");
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = Command::new(ROJO_PATH)
|
let output = atlas_command()
|
||||||
// I don't really understand why setting the working directory breaks this, but it does.
|
// I don't really understand why setting the working directory breaks this, but it does.
|
||||||
// It's a bit concerning but I'm more interested in writing tests than debugging it right now.
|
// It's a bit concerning but I'm more interested in writing tests than debugging it right now.
|
||||||
// TODO: Figure out why and fix it.
|
// TODO: Figure out why and fix it.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use std::{fs, path::Path, process::Command};
|
use std::{fs, path::Path};
|
||||||
|
|
||||||
use insta::assert_snapshot;
|
use insta::assert_snapshot;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use crate::rojo_test::io_util::{get_working_dir_path, BUILD_TESTS_PATH, ROJO_PATH};
|
use crate::rojo_test::io_util::{atlas_command, get_working_dir_path, BUILD_TESTS_PATH};
|
||||||
|
|
||||||
macro_rules! gen_build_tests {
|
macro_rules! gen_build_tests {
|
||||||
( $($test_name: ident,)* ) => {
|
( $($test_name: ident,)* ) => {
|
||||||
|
|
@ -81,7 +81,7 @@ fn run_build_test(test_name: &str) {
|
||||||
let output_dir = tempdir().expect("couldn't create temporary directory");
|
let output_dir = tempdir().expect("couldn't create temporary directory");
|
||||||
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
|
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
|
||||||
|
|
||||||
let output = Command::new(ROJO_PATH)
|
let output = atlas_command()
|
||||||
.args([
|
.args([
|
||||||
"build",
|
"build",
|
||||||
input_path.to_str().unwrap(),
|
input_path.to_str().unwrap(),
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,10 @@
|
||||||
//! 4. Incremental mode preserves existing file structure
|
//! 4. Incremental mode preserves existing file structure
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use crate::rojo_test::io_util::{copy_recursive, ROJO_PATH};
|
use crate::rojo_test::io_util::{atlas_command, copy_recursive};
|
||||||
|
|
||||||
const SYNCBACK_TESTS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/rojo-test/syncback-tests");
|
const SYNCBACK_TESTS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/rojo-test/syncback-tests");
|
||||||
|
|
||||||
|
|
@ -30,7 +29,7 @@ fn run_syncback(project_path: &Path, input_path: &Path, incremental: bool) -> bo
|
||||||
args.push("--incremental");
|
args.push("--incremental");
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = Command::new(ROJO_PATH)
|
let output = atlas_command()
|
||||||
.args(args)
|
.args(args)
|
||||||
.output()
|
.output()
|
||||||
.expect("Couldn't spawn syncback process");
|
.expect("Couldn't spawn syncback process");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue