Skip to content

feat: Derive tests for derived schemas#571

Closed
Kriskras99 wants to merge 3 commits into
mainfrom
feat/derived_schema_test
Closed

feat: Derive tests for derived schemas#571
Kriskras99 wants to merge 3 commits into
mainfrom
feat/derived_schema_test

Conversation

@Kriskras99

Copy link
Copy Markdown
Contributor

This adds a test to every generated schema to check if the schema can actually be created. Tests are automatically disabled for types with generics, consts, or lifetimes. They can also be disabled by setting #[avro(test = false)] on the type, for if a user uses a different validator at runtime or the type is inside a function which would trigger the unnameable_test_items lint.

In the future we could extend the attribute syntax to provide a different validator, so that use case would also be supported. I also think we should be able to test types with lifetimes, but that needs some further experimentation.

@Kriskras99 Kriskras99 mentioned this pull request Jul 3, 2026
@Kriskras99 Kriskras99 force-pushed the feat/derived_schema_test branch from bb9dcde to b004614 Compare July 6, 2026 14:45
@martin-g martin-g added this to the 0.22.0 milestone Jul 10, 2026
Base automatically changed from feat/all_the_enums to main July 13, 2026 20:59
Comment thread avro/src/serde/derive.rs Outdated
Comment thread avro_derive/src/attributes/avro.rs Outdated
Kriskras99 and others added 2 commits July 14, 2026 12:54
-----

Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
@Kriskras99 Kriskras99 force-pushed the feat/derived_schema_test branch from b004614 to 0e982c4 Compare July 14, 2026 10:57
{
let ident = &self.ident;
self.add_test(Test {
name: "schema".to_string(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the idea of this PR :-/
It is invasive by generating tests no one asked for.
The end user will have to opt-out instead of opt-in for those tests.

It is not clear what is being tested too.

  1. The name is always "schema". Is it really needed ?!
  2. The body always prints "Invalid schema" to stderr
  3. should_panic is always None
  4. The body just calls get_schema(), so it tests runtime construction of the derived Schema and validates its Name. But one could assume that the users make use of the derived schema too in their application and tests, so this is kinda already covered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think especially point 4 is a good point, so let's close this for now.

(1 and 3 are to allow generating other kinds of tests, 2 is so that the user gets some feedback when the test fails).

Comment thread avro/src/serde/derive.rs Outdated
@Kriskras99

Copy link
Copy Markdown
Contributor Author

Closing for now, needs more work

@Kriskras99 Kriskras99 closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants