11// Copyright 2025 the Vello Authors
22// SPDX-License-Identifier: Apache-2.0 OR MIT
33
4+ //! The [`vello_api_test`](crate::vello_api_test) macro, which automatically generates variations of tests for
5+ //! functions using Vello API.
6+
47use crate :: {
58 Attribute , AttributeInput , DEFAULT_CPU_F32_TOLERANCE , DEFAULT_CPU_U8_TOLERANCE ,
69 DEFAULT_HYBRID_TOLERANCE , DEFAULT_SIMD_TOLERANCE , parse_int_lit, parse_string_lit,
@@ -39,6 +42,10 @@ struct Arguments {
3942 /// Whether no reference image should actually be created (for tests that only check
4043 /// for panics, but are not interested in the actual output).
4144 no_ref : bool ,
45+ /// Whether a reference image should be used but not created for this test.
46+ ///
47+ /// This is used for porting tests from the interim "API" to Vello API.
48+ existing_ref : bool ,
4249 /// A reason for ignoring a test.
4350 ignore_reason : Option < String > ,
4451}
@@ -56,6 +63,7 @@ impl Default for Arguments {
5663 skip_hybrid : false ,
5764 no_ref : false ,
5865 diff_pixels : 0 ,
66+ existing_ref : false ,
5967 ignore_reason : None ,
6068 }
6169 }
@@ -147,16 +155,21 @@ pub(crate) fn vello_test_inner(attr: TokenStream, item: TokenStream) -> TokenStr
147155 width,
148156 height,
149157 cpu_u8_tolerance,
150- mut hybrid_tolerance,
158+ hybrid_tolerance,
151159 transparent,
152160 skip_cpu,
153161 skip_multithreaded,
154162 mut skip_hybrid,
155163 ignore_reason,
156164 no_ref,
157165 diff_pixels,
166+ existing_ref,
158167 } = parse_args ( & attrs) ;
159168
169+ if no_ref && existing_ref {
170+ panic ! ( "Setting `no_ref` and `existing_ref` at the same time is meaningless." ) ;
171+ }
172+
160173 let params_const = {
161174 let cpu_u8_scalar_tolerance = cpu_u8_tolerance + DEFAULT_CPU_U8_TOLERANCE ;
162175 let cpu_u8_simd_tolerance =
@@ -322,7 +335,8 @@ pub(crate) fn vello_test_inner(attr: TokenStream, item: TokenStream) -> TokenStr
322335 f32_fn_name_scalar,
323336 f32_fn_name_str_scalar,
324337 & cpu_f32_tolerance_scalar,
325- true ,
338+ // Only make a reference image if there is already a reference image existing.
339+ !existing_ref,
326340 0 ,
327341 quote ! { "fallback" } ,
328342 skip_cpu,
@@ -496,7 +510,6 @@ pub(crate) fn vello_test_inner(attr: TokenStream, item: TokenStream) -> TokenStr
496510 } ,
497511 #webgl_fn_name_str,
498512 #params_name. hybrid_tolerance,
499- false ,
500513 ) ;
501514 }
502515 } ;
@@ -542,6 +555,7 @@ fn parse_args(attribute_input: &AttributeInput) -> Arguments {
542555 "skip_multithreaded" => args. skip_multithreaded = true ,
543556 "skip_hybrid" => args. skip_hybrid = true ,
544557 "no_ref" => args. no_ref = true ,
558+ "existing_ref" => args. existing_ref = true ,
545559 "ignore" => {
546560 args. skip_cpu = true ;
547561 args. skip_multithreaded = true ;
0 commit comments