mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(formatter_core,formatter_tests): extract oxc_formatter_tests crate from oxc_formatter_core (#25465)
- Extract `test_harness` feature as crate `oxc_formatter_tests` - This crate will also provide infra for `tasks/prettier_conformance` later
This commit is contained in:
1 parent
9d49d279fd
commit
6e1b4ddceb
26 files changed
+100
-51
No files matched your search
Generated
+13
-1
@@ -2033,6 +2033,7 @@ dependencies = [
|
||||
"oxc_ast",
|
||||
"oxc_diagnostics",
|
||||
"oxc_formatter_core",
|
||||
"oxc_formatter_tests",
|
||||
"oxc_jsdoc",
|
||||
"oxc_parser",
|
||||
"oxc_semantic",
|
||||
@@ -2058,7 +2059,6 @@ dependencies = [
|
||||
"oxc_data_structures",
|
||||
"oxc_span",
|
||||
"rustc-hash",
|
||||
"serde_json",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
@@ -2072,6 +2072,7 @@ dependencies = [
|
||||
"oxc_allocator",
|
||||
"oxc_diagnostics",
|
||||
"oxc_formatter_core",
|
||||
"oxc_formatter_tests",
|
||||
"oxc_span",
|
||||
"phf",
|
||||
"pico-args",
|
||||
@@ -2087,6 +2088,7 @@ dependencies = [
|
||||
"oxc_allocator",
|
||||
"oxc_diagnostics",
|
||||
"oxc_formatter_core",
|
||||
"oxc_formatter_tests",
|
||||
"oxc_span",
|
||||
"oxc_tasks_common",
|
||||
"pico-args",
|
||||
@@ -2102,6 +2104,7 @@ dependencies = [
|
||||
"oxc_ast",
|
||||
"oxc_diagnostics",
|
||||
"oxc_formatter_core",
|
||||
"oxc_formatter_tests",
|
||||
"oxc_parser",
|
||||
"oxc_span",
|
||||
"oxc_syntax",
|
||||
@@ -2109,6 +2112,14 @@ dependencies = [
|
||||
"pico-args",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "oxc_formatter_tests"
|
||||
version = "0.62.0"
|
||||
dependencies = [
|
||||
"oxc_formatter_core",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "oxc_formatter_yaml"
|
||||
version = "0.63.0"
|
||||
@@ -2119,6 +2130,7 @@ dependencies = [
|
||||
"oxc_allocator",
|
||||
"oxc_diagnostics",
|
||||
"oxc_formatter_core",
|
||||
"oxc_formatter_tests",
|
||||
"oxc_span",
|
||||
"oxc_tasks_common",
|
||||
"pico-args",
|
||||
|
||||
@@ -163,6 +163,7 @@ oxc_formatter_core = { path = "crates/oxc_formatter_core" } # Language-agnostic
|
||||
oxc_formatter_css = { path = "crates/oxc_formatter_css" } # CSS formatter
|
||||
oxc_formatter_graphql = { path = "crates/oxc_formatter_graphql" } # GraphQL formatter
|
||||
oxc_formatter_json = { path = "crates/oxc_formatter_json" } # JSON formatter
|
||||
oxc_formatter_tests = { path = "crates/oxc_formatter_tests" } # Formatter test infrastructure (fixture codegen + harness)
|
||||
oxc_formatter_yaml = { path = "crates/oxc_formatter_yaml" } # YAML formatter
|
||||
oxc_language_server = { path = "crates/oxc_language_server", default-features = false } # Language server
|
||||
oxc_lexer = { path = "crates/oxc_lexer" } # JS/TS lexer (incubating; x86_64 SIMD, stub elsewhere)
|
||||
|
||||
@@ -41,14 +41,14 @@ unicode-width = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
oxc_tasks_common = { workspace = true }
|
||||
pico-args = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
|
||||
[build-dependencies]
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use oxc_formatter_core::test_support::{GenerateConfig, generate_tests};
|
||||
use oxc_formatter_tests::{GenerateConfig, generate_tests};
|
||||
|
||||
fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ use oxc_formatter::{
|
||||
ArrowParentheses, BracketSameLine, BracketSpacing, JsFormatOptions, JsdocOptions,
|
||||
QuoteProperties, QuoteStyle, Semicolons, TrailingCommas,
|
||||
};
|
||||
use oxc_formatter_core::test_support::{
|
||||
use oxc_formatter_tests::{
|
||||
FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot,
|
||||
};
|
||||
use oxc_span::SourceType;
|
||||
|
||||
@@ -160,18 +160,11 @@ core owns the span-ordered cursor mechanics; what the items mean (comments) and
|
||||
|
||||
Quote-style options, comment rules, and the like are likewise consumer-owned.
|
||||
|
||||
## Cargo features
|
||||
|
||||
`test_harness` exposes `test_support/` (fixture test generation) to downstream crates.
|
||||
Consumers still need their own `insta` dev-dep so the recorded `source:` header points to the consumer crate.
|
||||
|
||||
## Verification
|
||||
|
||||
Feature configs to check:
|
||||
|
||||
```sh
|
||||
cargo c -p oxc_formatter_core
|
||||
cargo c -p oxc_formatter_core --features test_harness
|
||||
```
|
||||
|
||||
This crate has basic tests only of its own, it is exercised through the conformance/snapshot tests of its consumers.
|
||||
The fixture-test infrastructure those consumers use lives in `crates/oxc_formatter_tests`.
|
||||
@@ -25,14 +25,5 @@ cow-utils = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
|
||||
serde_json = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
# Enables `test_support` (used from build.rs and tests/) in downstream formatter
|
||||
# crates. Consumer crates still need a direct `insta` dev-dep — the snapshot macro
|
||||
# is invoked from each consumer's `tests/fixtures/mod.rs` so the recorded `source:`
|
||||
# header points to the consumer, not the shared harness.
|
||||
test_harness = ["dep:serde_json"]
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
@@ -35,9 +35,6 @@ pub mod spec;
|
||||
mod state;
|
||||
mod traits;
|
||||
|
||||
#[cfg(feature = "test_harness")]
|
||||
pub mod test_support;
|
||||
|
||||
pub use arguments::{Argument, Arguments};
|
||||
pub use buffer::{
|
||||
AccumulatorBuffer, Buffer, BufferExtensions, HeapVecBuffer, Inspect, PreambleBuffer, Recorded,
|
||||
|
||||
@@ -27,11 +27,11 @@ oxc-css-parser = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
pico-args = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
@@ -3,7 +3,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use oxc_formatter_core::test_support::{GenerateConfig, generate_tests};
|
||||
use oxc_formatter_tests::{GenerateConfig, generate_tests};
|
||||
|
||||
fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_allocator::{Allocator, ArenaVec};
|
||||
use oxc_formatter_core::test_support::{
|
||||
use oxc_formatter_css::{CssFormatOptions, CssVariant, format};
|
||||
use oxc_formatter_tests::{
|
||||
FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot,
|
||||
};
|
||||
use oxc_formatter_css::{CssFormatOptions, CssVariant, format};
|
||||
|
||||
struct CssHarness;
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ oxc_span = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
oxc_tasks_common = { workspace = true }
|
||||
pico-args = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use oxc_formatter_core::test_support::{GenerateConfig, generate_tests};
|
||||
use oxc_formatter_tests::{GenerateConfig, generate_tests};
|
||||
|
||||
fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_formatter_core::test_support::{
|
||||
use oxc_formatter_graphql::{GraphqlFormatOptions, format};
|
||||
use oxc_formatter_tests::{
|
||||
FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot,
|
||||
};
|
||||
use oxc_formatter_graphql::{GraphqlFormatOptions, format};
|
||||
|
||||
struct GraphqlHarness;
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ oxc_syntax = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
oxc_tasks_common = { workspace = true }
|
||||
pico-args = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
@@ -3,7 +3,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use oxc_formatter_core::test_support::{GenerateConfig, generate_tests};
|
||||
use oxc_formatter_tests::{GenerateConfig, generate_tests};
|
||||
|
||||
fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_formatter_core::test_support::{
|
||||
FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot,
|
||||
};
|
||||
use oxc_formatter_json::{
|
||||
BracketSpacing, Expand, JsonFormatOptions, JsonVariant, QuoteProps, TrailingCommas, format,
|
||||
};
|
||||
use oxc_formatter_tests::{
|
||||
FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot,
|
||||
};
|
||||
|
||||
struct JsonHarness;
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Coding agent guides for `crates/oxc_formatter_tests`
|
||||
|
||||
Test infrastructure shared by the formatter crates (e.g. `oxc_formatter`, `oxc_formatter_json`, `oxc_formatter_css`, etc).
|
||||
|
||||
- `codegen`: build-script helper — consumers call `generate_tests` from `build.rs` via `[build-dependencies]` to emit one `#[test]` per fixture file
|
||||
- `harness`: fixture runtime — consumers implement `FixtureFormatter` in `tests/fixtures/mod.rs` via `[dev-dependencies]`
|
||||
|
||||
## Dependency rule
|
||||
|
||||
This crate depends only on `oxc_formatter_core` — NEVER on language crates.
|
||||
Consumers use it from both `[build-dependencies]` and `[dev-dependencies]`; a dependency on a language crate would make that a build-dep cycle, which cargo rejects.
|
||||
|
||||
## insta stays consumer-side
|
||||
|
||||
`build_fixture_snapshot` returns the snapshot body without calling `insta::assert_snapshot!`.
|
||||
Each consumer invokes the macro from its own `tests/fixtures/mod.rs` so the recorded `source:` header points to the consumer crate (required by `INSTA_REQUIRE_FULL_MATCH=1` in CI). Consumers therefore need their own `insta` dev-dep.
|
||||
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
cargo c -p oxc_formatter_tests
|
||||
```
|
||||
|
||||
Exercised through the fixture tests of its consumers (`cargo test -p <formatter crate>`).
|
||||
@@ -0,0 +1 @@
|
||||
@AGENTS.md
|
||||
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "oxc_formatter_tests"
|
||||
version = "0.62.0"
|
||||
authors.workspace = true
|
||||
categories.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
include = ["/src"]
|
||||
keywords.workspace = true
|
||||
license.workspace = true
|
||||
publish = false
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
description.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
oxc_formatter_core = { workspace = true }
|
||||
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
test = false
|
||||
File renamed without changes.
+3
-1
@@ -17,7 +17,9 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use crate::{CoreFormatOptions, FormatOptions, IndentStyle, IndentWidth, LineEnding, LineWidth};
|
||||
use oxc_formatter_core::{
|
||||
CoreFormatOptions, FormatOptions, IndentStyle, IndentWidth, LineEnding, LineWidth,
|
||||
};
|
||||
|
||||
/// A single `options.json` entry: a JSON object of per-test format options.
|
||||
pub type OptionSet = serde_json::Map<String, serde_json::Value>;
|
||||
+5
-3
@@ -1,9 +1,11 @@
|
||||
//! Fixture-test infrastructure shared across formatter crates.
|
||||
//!
|
||||
//! Gated behind the `test_harness` Cargo feature. Split into:
|
||||
//! Test infrastructure shared across formatter crates.
|
||||
//!
|
||||
//! - `harness`: runtime that walks fixtures, drives format passes, and assembles snapshots.
|
||||
//! - `codegen`: build-script helper that emits `#[test]` functions for each fixture.
|
||||
//!
|
||||
//! Consumer crates use `codegen` from `build.rs` (via `[build-dependencies]`) and `harness`
|
||||
//! from `tests/fixtures/mod.rs` (via `[dev-dependencies]`). This crate depends only on
|
||||
//! `oxc_formatter_core`, never on language crates, so both directions stay cycle-free.
|
||||
|
||||
mod codegen;
|
||||
mod harness;
|
||||
@@ -26,12 +26,12 @@ oxc_span = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
oxc_tasks_common = { workspace = true }
|
||||
pico-args = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
oxc_formatter_core = { workspace = true, features = ["test_harness"] }
|
||||
oxc_formatter_tests = { workspace = true }
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
@@ -3,7 +3,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use oxc_formatter_core::test_support::{GenerateConfig, generate_tests};
|
||||
use oxc_formatter_tests::{GenerateConfig, generate_tests};
|
||||
|
||||
fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_formatter_core::{
|
||||
LineEnding,
|
||||
test_support::{FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot},
|
||||
use oxc_formatter_core::LineEnding;
|
||||
use oxc_formatter_tests::{
|
||||
FixtureFormatter, OptionSet, apply_core_options, build_fixture_snapshot,
|
||||
};
|
||||
use oxc_formatter_yaml::{ProseWrap, YamlFormatOptions, format};
|
||||
|
||||
|
||||
Reference in new issue
Block a user