From 40098134292d5bb030c417d05d54603599b8d273 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 1 Jul 2024 16:04:20 -0400 Subject: [PATCH] lang: Move stateful test objects into a per-test mode Was this causing failures? --- lang/interpret_test.go | 114 ++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/lang/interpret_test.go b/lang/interpret_test.go index d24a4ccfd..f62d1d54c 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -109,25 +109,6 @@ func TestAstFunc1(t *testing.T) { } t.Logf("tests directory is: %s", dir) - variables := map[string]interfaces.Expr{ - "purpleidea": &ast.ExprStr{V: "hello world!"}, // james says hi - // TODO: change to a func when we can change hostname dynamically! - "hostname": &ast.ExprStr{V: ""}, // NOTE: empty b/c not used - } - consts := ast.VarPrefixToVariablesScope(vars.ConstNamespace) // strips prefix! - addback := vars.ConstNamespace + interfaces.ModuleSep // add it back... - variables, err = ast.MergeExprMaps(variables, consts, addback) - if err != nil { - t.Errorf("couldn't merge in consts: %+v", err) - return - } - - scope := &interfaces.Scope{ // global scope - Variables: variables, - // all the built-in top-level, core functions enter here... - Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix - } - type test struct { // an individual test name string path string // relative txtar path inside tests dir @@ -304,6 +285,25 @@ func TestAstFunc1(t *testing.T) { afs := &afero.Afero{Fs: mmFs} // wrap to implement the fs API's fs := &util.AferoFs{Afero: afs} + variables := map[string]interfaces.Expr{ + "purpleidea": &ast.ExprStr{V: "hello world!"}, // james says hi + // TODO: change to a func when we can change hostname dynamically! + "hostname": &ast.ExprStr{V: ""}, // NOTE: empty b/c not used + } + consts := ast.VarPrefixToVariablesScope(vars.ConstNamespace) // strips prefix! + addback := vars.ConstNamespace + interfaces.ModuleSep // add it back... + variables, err = ast.MergeExprMaps(variables, consts, addback) + if err != nil { + t.Errorf("couldn't merge in consts: %+v", err) + return + } + + scope := &interfaces.Scope{ // global scope + Variables: variables, + // all the built-in top-level, core functions enter here... + Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix + } + // use this variant, so that we don't copy the dir name // this is the equivalent to running `rsync -a src/ /` if err := util.CopyDiskContentsToFs(fs, src, "/", false); err != nil { @@ -596,25 +596,6 @@ func TestAstFunc2(t *testing.T) { } t.Logf("tests directory is: %s", dir) - variables := map[string]interfaces.Expr{ - "purpleidea": &ast.ExprStr{V: "hello world!"}, // james says hi - // TODO: change to a func when we can change hostname dynamically! - "hostname": &ast.ExprStr{V: ""}, // NOTE: empty b/c not used - } - consts := ast.VarPrefixToVariablesScope(vars.ConstNamespace) // strips prefix! - addback := vars.ConstNamespace + interfaces.ModuleSep // add it back... - variables, err = ast.MergeExprMaps(variables, consts, addback) - if err != nil { - t.Errorf("couldn't merge in consts: %+v", err) - return - } - - scope := &interfaces.Scope{ // global scope - Variables: variables, - // all the built-in top-level, core functions enter here... - Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix - } - type test struct { // an individual test name string path string // relative txtar path inside tests dir @@ -841,6 +822,25 @@ func TestAstFunc2(t *testing.T) { }, } + variables := map[string]interfaces.Expr{ + "purpleidea": &ast.ExprStr{V: "hello world!"}, // james says hi + // TODO: change to a func when we can change hostname dynamically! + "hostname": &ast.ExprStr{V: ""}, // NOTE: empty b/c not used + } + consts := ast.VarPrefixToVariablesScope(vars.ConstNamespace) // strips prefix! + addback := vars.ConstNamespace + interfaces.ModuleSep // add it back... + variables, err = ast.MergeExprMaps(variables, consts, addback) + if err != nil { + t.Errorf("couldn't merge in consts: %+v", err) + return + } + + scope := &interfaces.Scope{ // global scope + Variables: variables, + // all the built-in top-level, core functions enter here... + Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix + } + // use this variant, so that we don't copy the dir name // this is the equivalent to running `rsync -a src/ /` if err := util.CopyDiskContentsToFs(fs, src, "/", false); err != nil { @@ -1411,25 +1411,6 @@ func TestAstFunc3(t *testing.T) { } t.Logf("tests directory is: %s", dir) - variables := map[string]interfaces.Expr{ - "purpleidea": &ast.ExprStr{V: "hello world!"}, // james says hi - // TODO: change to a func when we can change hostname dynamically! - "hostname": &ast.ExprStr{V: ""}, // NOTE: empty b/c not used - } - consts := ast.VarPrefixToVariablesScope(vars.ConstNamespace) // strips prefix! - addback := vars.ConstNamespace + interfaces.ModuleSep // add it back... - variables, err = ast.MergeExprMaps(variables, consts, addback) - if err != nil { - t.Errorf("couldn't merge in consts: %+v", err) - return - } - - scope := &interfaces.Scope{ // global scope - Variables: variables, - // all the built-in top-level, core functions enter here... - Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix - } - type test struct { // an individual test name string path string // relative txtar path inside tests dir @@ -1650,6 +1631,25 @@ func TestAstFunc3(t *testing.T) { }, } + variables := map[string]interfaces.Expr{ + "purpleidea": &ast.ExprStr{V: "hello world!"}, // james says hi + // TODO: change to a func when we can change hostname dynamically! + "hostname": &ast.ExprStr{V: ""}, // NOTE: empty b/c not used + } + consts := ast.VarPrefixToVariablesScope(vars.ConstNamespace) // strips prefix! + addback := vars.ConstNamespace + interfaces.ModuleSep // add it back... + variables, err = ast.MergeExprMaps(variables, consts, addback) + if err != nil { + t.Errorf("couldn't merge in consts: %+v", err) + return + } + + scope := &interfaces.Scope{ // global scope + Variables: variables, + // all the built-in top-level, core functions enter here... + Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix + } + // use this variant, so that we don't copy the dir name // this is the equivalent to running `rsync -a src/ /` if err := util.CopyDiskContentsToFs(fs, src, "/", false); err != nil {