diff --git a/rule/rule.go b/rule/rule.go index 0b7f3091a..85afb1adb 100644 --- a/rule/rule.go +++ b/rule/rule.go @@ -997,6 +997,7 @@ func (r *Rule) Args() []bzl.Expr { // AddArg adds a positional argument to the rule. func (r *Rule) AddArg(value bzl.Expr) { r.args = append(r.args, value) + r.updated = true } // Insert marks this statement for insertion at the end of the file. Multiple diff --git a/rule/rule_test.go b/rule/rule_test.go index 363a97b9e..685386793 100644 --- a/rule/rule_test.go +++ b/rule/rule_test.go @@ -638,3 +638,31 @@ a_rule( t.Errorf("got:%s\nwant:%s", got, want) } } + +func TestSimpleArgument(t *testing.T) { + f := EmptyFile("foo", "bar") + + r := NewRule("export_files", "") + r.AddArg(&bzl.CallExpr{ + X: &bzl.Ident{Name: "glob"}, + List: []bzl.Expr{ + &bzl.ListExpr{ + List: []bzl.Expr{ + &bzl.StringExpr{Value: "**"}, + }, + }, + }, + }) + + r.Insert(f) + f.Sync() + + got := strings.TrimSpace(string(bzl.FormatWithoutRewriting(f.File))) + want := strings.TrimSpace(` +export_files(glob(["**"])) +`) + + if got != want { + t.Errorf("got:%s\nwant:%s", got, want) + } +}