internal/rosa/azalea: pass through source ident
All checks were successful
Test / ShareFS (push) Successful in 41s
Test / Sandbox (push) Successful in 48s
Test / Hakurei (push) Successful in 51s
Test / Create distribution (push) Successful in 1m3s
Test / Sandbox (race detector) (push) Successful in 2m27s
Test / Hakurei (race detector) (push) Successful in 3m29s
Test / Flake checks (push) Successful in 1m23s

For source handle special case.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-19 18:05:39 +09:00
parent e65a3b435c
commit 3010a209b5
3 changed files with 62 additions and 11 deletions

View File

@@ -32,7 +32,7 @@ func TestEvaluate(t *testing.T) {
name string
data string
s []Frame
want string
want any
err error
}{
{"apply unset", `f { v = unset; }`, makeStackCheck(func(
@@ -110,7 +110,7 @@ func TestEvaluate(t *testing.T) {
}, V: Val{Array(nil)}},
},
},
Err: ErrInvalidInputs,
Err: ErrInvalidSpecial,
}},
{"bound inputs", `package name { inputs* = []; }`, nil, "", EvaluationError{
@@ -122,7 +122,7 @@ func TestEvaluate(t *testing.T) {
{K: []Ident{"inputs"}, V: Val{Array(nil)}, R: true},
},
},
Err: ErrInvalidInputs,
Err: ErrInvalidSpecial,
}},
{"bound runtime", `package name { runtime* = []; }`, nil, "", EvaluationError{
@@ -134,7 +134,7 @@ func TestEvaluate(t *testing.T) {
{K: []Ident{"runtime"}, V: Val{Array(nil)}, R: true},
},
},
Err: ErrInvalidInputs,
Err: ErrInvalidSpecial,
}},
{"concat inputs", `package name { inputs = ""+""; }`, nil, "", EvaluationError{
@@ -146,8 +146,24 @@ func TestEvaluate(t *testing.T) {
{K: []Ident{"inputs"}, V: Val{String(""), String("")}},
},
},
Err: ErrInvalidInputs,
Err: ErrInvalidSpecial,
}},
{"concat source", `package name { source = ""+""; }`, nil, "", EvaluationError{
Expr: Func{
Ident: Ident("name"),
Package: true,
Args: []Arg{
{K: []Ident{"source"}, V: Val{String(""), String("")}},
},
},
Err: ErrInvalidSpecial,
}},
{"source handle", `package name { source = name; }`, nil, FArgs{
{K: unique.Make(Ident("source")), V: Ident("name")},
}, nil},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@@ -161,12 +177,23 @@ func TestEvaluate(t *testing.T) {
} else {
expr = e[0].(Func)
}
r, set, err := Evaluate[string](nil, tc.s, expr)
const rPackage = "\xff\xff\xff\xff"
r, set, err := Evaluate[string](func(
name Ident,
args FArgs,
) (v any, set bool, err error) {
v = rPackage
if !reflect.DeepEqual(args, tc.want) {
err = fmt.Errorf("%#v, want %#v", args, tc.want)
}
set = true
return
}, tc.s, expr)
if set != (err == nil) {
t.Error("Evaluate: unexpected unset")
}
if r != tc.want {
if r != rPackage && r != tc.want {
t.Errorf("Evaluate: %q, want %q", r, tc.want)
}