Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@

module(
name = "score_test_scenarios",
version = "0.3.0",
version = "0.3.1",
compatibility_level = 0,
)

# Starlark language server
bazel_dep(name = "score_starpls_lsp", version = "0.1.0")
bazel_dep(name = "score_starpls_lsp", version = "0.1.0", dev_dependency = True)

# Python rules.
bazel_dep(name = "rules_python", version = "1.0.0")
bazel_dep(name = "rules_python", version = "1.0.0", dev_dependency = True)

PYTHON_VERSION = "3.12"

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(
is_default = True,
python_version = PYTHON_VERSION,
)
use_repo(python)

# C++ GoogleTest dependencies.
bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)

# Rust rules.
bazel_dep(name = "rules_rust", version = "0.56.0")

# C/C++ rules.
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_cc", version = "0.1.1", dev_dependency = True)

# Rust module dependencies.
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
Expand All @@ -51,15 +51,8 @@ rust.toolchain(
versions = ["1.85.0"],
)

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.from_cargo(
name = "test_scenarios_rust_crates",
cargo_lockfile = "//test_scenarios_rust:Cargo.lock",
manifests = [
"//test_scenarios_rust:Cargo.toml",
],
)
use_repo(crate, "test_scenarios_rust_crates")

# C++ base libs.
bazel_dep(name = "score_baselibs", version = "0.1.2")
bazel_dep(name = "score_baselibs", version = "0.1.2", dev_dependency = True)

# Score Rust crates.
bazel_dep(name = "score_crates", version = "0.0.4")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "testing-utils"
version = "0.3.0"
version = "0.3.1"
dependencies = ["pytest>=8.3.5", "pytest-html>=4.1.1", "pytest-repeat>=0.9.4"]
requires-python = ">=3.12"
authors = [
Expand Down
11 changes: 8 additions & 3 deletions test_scenarios_rust/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("@test_scenarios_rust_crates//:defs.bzl", "all_crate_deps")

rust_library(
name = "test_scenarios_rust",
srcs = glob(["src/**/*.rs"]),
visibility = ["//visibility:public"],
deps = all_crate_deps(normal = True),
deps = [
"@score_crates//:tracing",
"@score_crates//:tracing_subscriber",
],
)

rust_test(
name = "tests",
crate = ":test_scenarios_rust",
visibility = ["//visibility:private"],
deps = all_crate_deps(normal = True),
deps = [
"@score_crates//:tracing",
"@score_crates//:tracing_subscriber",
],
)
2 changes: 1 addition & 1 deletion test_scenarios_rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test_scenarios_rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_scenarios_rust"
version = "0.3.0"
version = "0.3.1"
edition = "2021"

[dependencies]
Expand Down
23 changes: 8 additions & 15 deletions test_scenarios_rust/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
// *******************************************************************************
use crate::monotonic_clock::MonotonicClock;
use crate::test_context::TestContext;
use std::sync::Once;
use tracing::Level;
use tracing_subscriber::fmt::format::{Format, JsonFields};
use tracing_subscriber::FmtSubscriber;

/// Tracing subscriber should be initialized only once.
static TRACING_SUBSCRIBER_INIT: Once = Once::new();

fn init_tracing_subscriber() {
let subscriber = FmtSubscriber::builder()
/// Create a tracing subscriber that outputs logs in JSON format with monotonic timestamps.
/// # Returns
/// configured `FmtSubscriber`.
pub fn create_tracing_subscriber(
) -> FmtSubscriber<JsonFields, Format<tracing_subscriber::fmt::format::Json, MonotonicClock>> {
FmtSubscriber::builder()
.with_max_level(Level::TRACE)
.with_thread_ids(true)
.with_timer(MonotonicClock::new())
.json()
.finish();

tracing::subscriber::set_global_default(subscriber)
.expect("Setting default subscriber failed!");
.finish()
}

/// Test scenario arguments.
Expand Down Expand Up @@ -154,11 +152,6 @@ pub fn run_cli_app(raw_arguments: &[String], test_context: &TestContext) -> Resu
None => return Err("Test scenario input must be provided".to_string()),
};

// Initialize tracing subscriber.
TRACING_SUBSCRIBER_INIT.call_once(|| {
init_tracing_subscriber();
});

test_context.run(&scenario_name, &scenario_input)
}

Expand Down
Loading