From 0c9b09ea985b22a0ad968f7b33d5ff7d376591e7 Mon Sep 17 00:00:00 2001 From: Varsha Munishwar Date: Mon, 5 Dec 2022 14:52:32 -0700 Subject: [PATCH 1/2] update go version to 1.19.3 and linter version to 1.50.1 --- .github/workflows/golangci-lint.yml | 6 +++--- .github/workflows/release.yml | 4 ++-- .github/workflows/test-all.yml | 4 ++-- .github/workflows/test-windows.yml | 4 ++-- .github/workflows/trivy-scan.yml | 2 +- examples/integrating-with-ytt/internal-templating/go.mod | 2 +- go.mod | 2 +- go.sum | 1 - 8 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index f78f197c..7c98a457 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -12,15 +12,15 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - name: Install Go 1.17 + - name: Install Go 1.19.3 uses: actions/setup-go@v3 with: - go-version: "1.17" + go-version: "1.19.3" - uses: actions/checkout@v2 with: fetch-depth: '0' - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.45.2 + version: v1.50.1 args: -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3471f733..6745bb97 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,10 +17,10 @@ jobs: with: fetch-depth: 0 - - name: Install Go 1.17 + - name: Install Go 1.19.3 uses: actions/setup-go@v3 with: - go-version: "1.17" + go-version: "1.19.3" - name: generate website/generate.go if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index 3a1d6ed5..7e09cc83 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -10,10 +10,10 @@ jobs: name: Test All runs-on: ubuntu-latest steps: - - name: Install Go 1.17 + - name: Install Go 1.19.3 uses: actions/setup-go@v3 with: - go-version: "1.17" + go-version: "1.19.3" - name: Check out code into the Go module directory uses: actions/checkout@v2 with: diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index f0427e03..4c661bcf 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -10,10 +10,10 @@ jobs: name: Test Windows runs-on: windows-latest steps: - - name: Install Go 1.17 + - name: Install Go 1.19.3 uses: actions/setup-go@v3 with: - go-version: "1.17" + go-version: "1.19.3" - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: Run Tests diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index d304a7dc..d99e903c 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -10,7 +10,7 @@ jobs: with: repo: vmware-tanzu/carvel-ytt tool: ytt - goVersion: "1.17" + goVersion: "1.19.3" secrets: githubToken: ${{ secrets.GITHUB_TOKEN }} slackWebhookURL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/examples/integrating-with-ytt/internal-templating/go.mod b/examples/integrating-with-ytt/internal-templating/go.mod index dbcae0b3..fa9bf584 100644 --- a/examples/integrating-with-ytt/internal-templating/go.mod +++ b/examples/integrating-with-ytt/internal-templating/go.mod @@ -1,6 +1,6 @@ module example_internal_templating -go 1.17 +go 1.19 // ensure example works with this copy of ytt; remove before use replace github.com/vmware-tanzu/carvel-ytt => ../../../ diff --git a/go.mod b/go.mod index 29866082..3136f53c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/vmware-tanzu/carvel-ytt -go 1.17 +go 1.19 require ( github.com/BurntSushi/toml v1.1.0 diff --git a/go.sum b/go.sum index ca639894..10c39ac2 100644 --- a/go.sum +++ b/go.sum @@ -56,7 +56,6 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/vito/go-interact v0.0.0-20171111012221-fa338ed9e9ec/go.mod h1:wPlfmglZmRWMYv/qJy3P+fK/UnoQB5ISk4txfNd9tDo= From 21de6be6f4807aa79828a1f3c59a68b4bae354b4 Mon Sep 17 00:00:00 2001 From: Varsha Munishwar Date: Mon, 5 Dec 2022 14:59:58 -0700 Subject: [PATCH 2/2] format the code as per go fmt --- pkg/cmd/doc.go | 2 +- pkg/doc.go | 275 ++++++++++++++-------------- pkg/schema/doc.go | 6 +- pkg/validations/doc.go | 2 +- pkg/validations/validations_test.go | 9 +- pkg/workspace/library_execution.go | 4 +- pkg/yamlmeta/parser.go | 11 +- pkg/yamlmeta/walk.go | 7 +- pkg/yamltemplate/metas.go | 8 +- pkg/yamltemplate/template_test.go | 9 +- pkg/yttlibrary/math.go | 74 ++++---- test/filetests/filetests.go | 4 + 12 files changed, 210 insertions(+), 201 deletions(-) diff --git a/pkg/cmd/doc.go b/pkg/cmd/doc.go index 94f22f08..721498aa 100644 --- a/pkg/cmd/doc.go +++ b/pkg/cmd/doc.go @@ -9,7 +9,7 @@ A cobra.Command is the starting point of execution. For a list of commands run: - $ ytt help + $ ytt help The default command is "template". */ diff --git a/pkg/doc.go b/pkg/doc.go index b536f0dc..25228ae1 100644 --- a/pkg/doc.go +++ b/pkg/doc.go @@ -12,7 +12,7 @@ degree absolutely required. In the inventory, below, individual packages are named alongside their coupling with the other packages in the codebase. - (# of dependents) => => (# of dependencies) + (# of dependents) => => (# of dependencies) Where "# of dependents" is the count of packages that import the named package and "# of dependencies" is the count of packages that this named package @@ -23,51 +23,51 @@ This is output from the tool https://github.com/jtigger/go-orient. From top-down (http://www.catb.org/~esr/writings/taoup/html/ch04s03.html), ytt code is layered in this way: -Entry Point +# Entry Point ytt is built into two executable formats: - ./cmd/ytt // a command-line tool - ./cmd/ytt-lambda-website // an AWS Lambda function + ./cmd/ytt // a command-line tool + ./cmd/ytt-lambda-website // an AWS Lambda function ytt's contains a mini website that is the "Playground". - (1) => pkg/website => (0) + (1) => pkg/website => (0) -Commands +# Commands There are half-a-dozen commands ytt implements. The most commonly used and most complex is "template". - (1) => pkg/cmd => (8) - (2) => pkg/cmd/template => (10) + (1) => pkg/cmd => (8) + (2) => pkg/cmd/template => (10) -The Workspace +# The Workspace ytt processing can be thought of as a sequence of steps: schema "pre-processing", data values "pre-processing", template evaluation, and overlay "post-processing". All of these steps are executed over a collection of files we call a workspace.Library. - (1) => pkg/workspace => (14) - (2) => pkg/workspace/datavalues => (6) - (3) => pkg/workspace/ref => (2) - (4) => pkg/files => (1) - (10) => pkg/filepos => (0) + (1) => pkg/workspace => (14) + (2) => pkg/workspace/datavalues => (6) + (3) => pkg/workspace/ref => (2) + (4) => pkg/files => (1) + (10) => pkg/filepos => (0) -Templating +# Templating The heart of ytt's action is structural templating. There are two flavors of templates: templating on a YAML structure and templating on text. Each source template file is "compiled" into a Starlark program whose job is to build-up the output. - (9) => pkg/template => (2) - (9) => pkg/template/core => (1) - (3) => pkg/yamltemplate => (6) - (2) => pkg/texttemplate => (2) + (9) => pkg/template => (2) + (9) => pkg/template/core => (1) + (3) => pkg/yamltemplate => (6) + (2) => pkg/texttemplate => (2) -Standard Library +# Standard Library ytt injects a collection of "standard" modules into Starlark executions. These modules support serialization, hashing, parsing of special kinds @@ -75,30 +75,30 @@ of values, and programmatic access to some of ytt's core capabilities. This collection is known as a library (not to be confused with the workspace.Library concept). - (2) => pkg/yttlibrary => (5) + (2) => pkg/yttlibrary => (5) The implementation for ytt's other fundamental feature -- Overlays -- lives within this standard library. This allows for both template authors and ytt itself to use this powerful editing feature. - (3) => pkg/yttlibrary/overlay => (5) + (3) => pkg/yttlibrary/overlay => (5) "Standard Library" modules that have Go dependencies are included as "extensions" to minimize the set of transitive dependencies that come from the github.com/vmware-tanzu/carvel-ytt module. - (1) => pkg/yttlibraryext => (1) - (1) => pkg/yttlibraryext/toml => (4) + (1) => pkg/yttlibraryext => (1) + (1) => pkg/yttlibraryext/toml => (4) -YAML Enhancements +# YAML Enhancements ytt can enrich a YAML structure with more fine-grained data typing and user-defined constraints on values. - (3) => pkg/schema => (5) - (1) => pkg/assertions => (5) + (3) => pkg/schema => (5) + (1) => pkg/assertions => (5) -YAML Structures +# YAML Structures At the heart of ytt is the ability to parse annotated YAML. @@ -109,131 +109,130 @@ hints, etc.). It does this by converting the output from the standard YAML parser into a composite tree of its own yamlmeta.Node structure that can hold that metadata. - (11) => pkg/yamlmeta => (3) - (1) => pkg/yamlmeta/internal/yaml.v2 => (0) + (11) => pkg/yamlmeta => (3) + (1) => pkg/yamlmeta/internal/yaml.v2 => (0) -Utilities +# Utilities Finally, there is a collection of supporting features. One of which provides the implementation of the "fmt" command: - (1) => pkg/yamlfmt => (1) + (1) => pkg/yamlfmt => (1) The remainder are domain-agnostic utilities that provide either an application-level capability or a specialized piece of logic. - (5) => pkg/cmd/ui => (0) - (5) => pkg/orderedmap => (0) - (2) => pkg/version => (0) - (2) => pkg/feature => (0) - (1) => pkg/spell => (0) + (5) => pkg/cmd/ui => (0) + (5) => pkg/orderedmap => (0) + (2) => pkg/version => (0) + (2) => pkg/feature => (0) + (1) => pkg/spell => (0) -Dependencies +# Dependencies Each package's dependencies on other packages within this module are as follows (if a package is not listed, it has no dependencies on other packages within this module): - pkg/cmd/template: - - pkg/workspace - - pkg/workspace/datavalues - - pkg/schema - - pkg/workspace/ref - - pkg/yttlibrary/overlay - - pkg/files - - pkg/cmd/ui - - pkg/template - - pkg/filepos - - pkg/yamlmeta - pkg/workspace: - - pkg/assertions - - pkg/texttemplate - - pkg/workspace/datavalues - - pkg/yttlibrary - - pkg/schema - - pkg/workspace/ref - - pkg/yamltemplate - - pkg/yttlibrary/overlay - - pkg/files - - pkg/cmd/ui - - pkg/template - - pkg/template/core - - pkg/filepos - - pkg/yamlmeta - pkg/assertions: - - pkg/feature - - pkg/yamltemplate - - pkg/template - - pkg/filepos - - pkg/yamlmeta - pkg/yamltemplate: - - pkg/texttemplate - - pkg/orderedmap - - pkg/template - - pkg/template/core - - pkg/filepos - - pkg/yamlmeta - pkg/texttemplate: - - pkg/template - - pkg/filepos - pkg/template: - - pkg/template/core - - pkg/filepos - pkg/template/core: - - pkg/orderedmap - pkg/yamlmeta: - - pkg/yamlmeta/internal/yaml.v2 - - pkg/orderedmap - - pkg/filepos - pkg/workspace/datavalues: - - pkg/schema - - pkg/workspace/ref - - pkg/template - - pkg/template/core - - pkg/filepos - - pkg/yamlmeta - pkg/schema: - - pkg/spell - - pkg/template - - pkg/template/core - - pkg/filepos - - pkg/yamlmeta - pkg/workspace/ref: - - pkg/template - - pkg/template/core - pkg/yttlibrary: - - pkg/version - - pkg/yttlibrary/overlay - - pkg/orderedmap - - pkg/template/core - - pkg/yamlmeta - pkg/yttlibrary/overlay: - - pkg/yamltemplate - - pkg/template - - pkg/template/core - - pkg/filepos - - pkg/yamlmeta - pkg/files: - - pkg/cmd/ui - pkg/cmd: - - pkg/website - - pkg/yamlfmt - - pkg/yttlibraryext - - pkg/cmd/template - - pkg/version - - pkg/files - - pkg/cmd/ui - - pkg/yamlmeta - pkg/yamlfmt: - - pkg/yamlmeta - pkg/yttlibraryext: - - pkg/yttlibraryext/toml - pkg/yttlibraryext/toml: - - pkg/yttlibrary - - pkg/orderedmap - - pkg/template/core - - pkg/yamlmeta - + pkg/cmd/template: + - pkg/workspace + - pkg/workspace/datavalues + - pkg/schema + - pkg/workspace/ref + - pkg/yttlibrary/overlay + - pkg/files + - pkg/cmd/ui + - pkg/template + - pkg/filepos + - pkg/yamlmeta + pkg/workspace: + - pkg/assertions + - pkg/texttemplate + - pkg/workspace/datavalues + - pkg/yttlibrary + - pkg/schema + - pkg/workspace/ref + - pkg/yamltemplate + - pkg/yttlibrary/overlay + - pkg/files + - pkg/cmd/ui + - pkg/template + - pkg/template/core + - pkg/filepos + - pkg/yamlmeta + pkg/assertions: + - pkg/feature + - pkg/yamltemplate + - pkg/template + - pkg/filepos + - pkg/yamlmeta + pkg/yamltemplate: + - pkg/texttemplate + - pkg/orderedmap + - pkg/template + - pkg/template/core + - pkg/filepos + - pkg/yamlmeta + pkg/texttemplate: + - pkg/template + - pkg/filepos + pkg/template: + - pkg/template/core + - pkg/filepos + pkg/template/core: + - pkg/orderedmap + pkg/yamlmeta: + - pkg/yamlmeta/internal/yaml.v2 + - pkg/orderedmap + - pkg/filepos + pkg/workspace/datavalues: + - pkg/schema + - pkg/workspace/ref + - pkg/template + - pkg/template/core + - pkg/filepos + - pkg/yamlmeta + pkg/schema: + - pkg/spell + - pkg/template + - pkg/template/core + - pkg/filepos + - pkg/yamlmeta + pkg/workspace/ref: + - pkg/template + - pkg/template/core + pkg/yttlibrary: + - pkg/version + - pkg/yttlibrary/overlay + - pkg/orderedmap + - pkg/template/core + - pkg/yamlmeta + pkg/yttlibrary/overlay: + - pkg/yamltemplate + - pkg/template + - pkg/template/core + - pkg/filepos + - pkg/yamlmeta + pkg/files: + - pkg/cmd/ui + pkg/cmd: + - pkg/website + - pkg/yamlfmt + - pkg/yttlibraryext + - pkg/cmd/template + - pkg/version + - pkg/files + - pkg/cmd/ui + - pkg/yamlmeta + pkg/yamlfmt: + - pkg/yamlmeta + pkg/yttlibraryext: + - pkg/yttlibraryext/toml + pkg/yttlibraryext/toml: + - pkg/yttlibrary + - pkg/orderedmap + - pkg/template/core + - pkg/yamlmeta */ package pkg diff --git a/pkg/schema/doc.go b/pkg/schema/doc.go index e60d7ae9..0c4eb173 100644 --- a/pkg/schema/doc.go +++ b/pkg/schema/doc.go @@ -4,7 +4,7 @@ /* Package schema enhances yamlmeta.Node structures with fine-grain data types. -Type and Checking +# Type and Checking Within a schema document (which itself is a yamlmeta.Document), type metadata is attached to nodes via @schema/... annotations. Those annotations are parsed and @@ -18,12 +18,12 @@ corresponding yamlmeta.Node. "Typed" documents can then be "checked" (via schema.CheckNode()) to determine if their fine-grain types conform to the assigned schema. -Documenting +# Documenting Other @schema/... annotations are used to describe the exact syntax and semantic of values. -Other Schema Formats +# Other Schema Formats Like other Carvel tools, ytt aims to interoperate well with other tooling. In this vein, ytt can export schema defined within ytt as an OpenAPI v3 document. diff --git a/pkg/validations/doc.go b/pkg/validations/doc.go index abf12832..fb26c9f4 100644 --- a/pkg/validations/doc.go +++ b/pkg/validations/doc.go @@ -5,7 +5,7 @@ Package validations enriches YAML structures by attaching user-defined constraints (that is, validationRun rules) onto individual yamlmeta.Node's. -Validations on Data Values +# Validations on Data Values While "@data/values" can technically be annotated with "@assert/validate" annotations, it is expected that authors will use "@schema/validationRun" in diff --git a/pkg/validations/validations_test.go b/pkg/validations/validations_test.go index a57fc455..9ffd150f 100644 --- a/pkg/validations/validations_test.go +++ b/pkg/validations/validations_test.go @@ -34,11 +34,12 @@ func TestMain(m *testing.M) { // 4. combines rule results into an appropriate validation outcome (list of error or passing) // // Example usage: -// Run a specific test: -// ./hack/test-all.sh -v -run TestValidations/filetests/success.tpltest // -// Include template compilation results in the output: -// ./hack/test-all.sh -v -run TestValidations/filetests/success.tpltest TestValidations.code=true +// Run a specific test: +// ./hack/test-all.sh -v -run TestValidations/filetests/success.tpltest +// +// Include template compilation results in the output: +// ./hack/test-all.sh -v -run TestValidations/filetests/success.tpltest TestValidations.code=true // // see also: // - pkg/template/... for tests around validations used in schema and data values. diff --git a/pkg/workspace/library_execution.go b/pkg/workspace/library_execution.go index 5758f317..91d3343f 100644 --- a/pkg/workspace/library_execution.go +++ b/pkg/workspace/library_execution.go @@ -110,8 +110,8 @@ func (ll *LibraryExecution) Values(valuesOverlays []*datavalues.Envelope, schema // validateValues runs validations on Data Values for the current library. // Validations are attached to data value and come from two sources: -// 1. @schema/validation annotations in a data values schema file. -// 2. @assert/validate annotations in a data values file. +// 1. @schema/validation annotations in a data values schema file. +// 2. @assert/validate annotations in a data values file. // // Returns an error if the arguments to an @assert/validate are invalid, // otherwise, checks the Check for violations, and returns nil if there are no violations. diff --git a/pkg/yamlmeta/parser.go b/pkg/yamlmeta/parser.go index 20020c7d..45ab867b 100644 --- a/pkg/yamlmeta/parser.go +++ b/pkg/yamlmeta/parser.go @@ -123,11 +123,12 @@ func (p *Parser) parseBytes(data []byte, lineCorrection int) (*DocumentSet, erro } // setPositionOfCollections assigns the Position of Maps and Arrays to their parent -// these kinds of nodes are not visible and therefore technically don't have a position. -// However, it is useful when communicating certain error cases to be able to reference -// a collection by line number. -// The position of the parent matches well with what the user sees. E.g. the MapItem that -// holds an Array is a great place to point at when referring to the entire array. +// +// these kinds of nodes are not visible and therefore technically don't have a position. +// However, it is useful when communicating certain error cases to be able to reference +// a collection by line number. +// The position of the parent matches well with what the user sees. E.g. the MapItem that +// holds an Array is a great place to point at when referring to the entire array. func setPositionOfCollections(node Node, parent Node) { if !node.GetPosition().IsKnown() { if parent != nil { diff --git a/pkg/yamlmeta/walk.go b/pkg/yamlmeta/walk.go index 698645e3..b0bcd5c0 100644 --- a/pkg/yamlmeta/walk.go +++ b/pkg/yamlmeta/walk.go @@ -31,7 +31,8 @@ func Walk(n Node, v Visitor) error { } // VisitorWithParent performs an operation on the given Node while traversing the AST, including a reference to "node"'s -// parent node. +// +// parent node. // // Typically defines the action taken during a WalkWithParent(). type VisitorWithParent interface { @@ -39,7 +40,9 @@ type VisitorWithParent interface { } // WalkWithParent traverses the tree starting at `n`, recursively, depth-first, invoking `v` on each node and including -// a reference to "node"s parent node as well. +// +// a reference to "node"s parent node as well. +// // if `v` returns non-nil error, the traversal is aborted. func WalkWithParent(node Node, parent Node, path string, v VisitorWithParent) error { err := v.VisitWithParent(node, parent, path) diff --git a/pkg/yamltemplate/metas.go b/pkg/yamltemplate/metas.go index 4da1a657..dc01bb69 100644 --- a/pkg/yamltemplate/metas.go +++ b/pkg/yamltemplate/metas.go @@ -40,10 +40,10 @@ type CommentAndAnnotation struct { // nodePos is the position of the node to which "comment" is attached. // // When a comment contains a shorthand annotation (i.e. `#@ `): -// - if the comment is above its node, it's a template.AnnotationCode annotation: it's _merely_ contributing raw -// Starlark code. -// - if the comment is on the same line as its node, it's a template.AnnotationValue annotation: it's meant to set the -// value of the annotated node. +// - if the comment is above its node, it's a template.AnnotationCode annotation: it's _merely_ contributing raw +// Starlark code. +// - if the comment is on the same line as its node, it's a template.AnnotationValue annotation: it's meant to set the +// value of the annotated node. func NewTemplateAnnotationFromYAMLComment(comment *yamlmeta.Comment, nodePos *filepos.Position, opts template.MetaOpts) (template.Annotation, error) { ann, err := template.NewAnnotationFromComment(comment.Data, comment.Position, opts) if err != nil { diff --git a/pkg/yamltemplate/template_test.go b/pkg/yamltemplate/template_test.go index da032345..1b0372f6 100644 --- a/pkg/yamltemplate/template_test.go +++ b/pkg/yamltemplate/template_test.go @@ -27,11 +27,12 @@ func TestMain(m *testing.M) { } // Example usage: -// Run a specific test: -// ./hack/test-all.sh -v -run TestYAMLTemplate/filetests/if.tpltest // -// Include template compilation results in the output: -// ./hack/test-all.sh -v -run TestYAMLTemplate/filetests/if.tpltest TestYAMLTemplate.code=true +// Run a specific test: +// ./hack/test-all.sh -v -run TestYAMLTemplate/filetests/if.tpltest +// +// Include template compilation results in the output: +// ./hack/test-all.sh -v -run TestYAMLTemplate/filetests/if.tpltest TestYAMLTemplate.code=true func TestYAMLTemplate(t *testing.T) { fileTests := filetests.FileTests{ PathToTests: "filetests", diff --git a/pkg/yttlibrary/math.go b/pkg/yttlibrary/math.go index 35711690..1cbfaca2 100644 --- a/pkg/yttlibrary/math.go +++ b/pkg/yttlibrary/math.go @@ -46,53 +46,52 @@ import ( // It contains math-related functions and constants. // The module defines the following functions: // -// ceil(x) - Returns the ceiling of x, the smallest integer greater than or equal to x. -// copysign(x, y) - Returns a value with the magnitude of x and the sign of y. -// fabs(x) - Returns the absolute value of x as float. -// floor(x) - Returns the floor of x, the largest integer less than or equal to x. -// mod(x, y) - Returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x. -// pow(x, y) - Returns x**y, the base-x exponential of y. -// remainder(x, y) - Returns the IEEE 754 floating-point remainder of x/y. -// round(x) - Returns the nearest integer, rounding half away from zero. +// ceil(x) - Returns the ceiling of x, the smallest integer greater than or equal to x. +// copysign(x, y) - Returns a value with the magnitude of x and the sign of y. +// fabs(x) - Returns the absolute value of x as float. +// floor(x) - Returns the floor of x, the largest integer less than or equal to x. +// mod(x, y) - Returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x. +// pow(x, y) - Returns x**y, the base-x exponential of y. +// remainder(x, y) - Returns the IEEE 754 floating-point remainder of x/y. +// round(x) - Returns the nearest integer, rounding half away from zero. // -// exp(x) - Returns e raised to the power x, where e = 2.718281… is the base of natural logarithms. -// sqrt(x) - Returns the square root of x. +// exp(x) - Returns e raised to the power x, where e = 2.718281… is the base of natural logarithms. +// sqrt(x) - Returns the square root of x. // -// acos(x) - Returns the arc cosine of x, in radians. -// asin(x) - Returns the arc sine of x, in radians. -// atan(x) - Returns the arc tangent of x, in radians. -// atan2(y, x) - Returns atan(y / x), in radians. -// The result is between -pi and pi. -// The vector in the plane from the origin to point (x, y) makes this angle with the positive X axis. -// The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct -// quadrant for the angle. -// For example, atan(1) and atan2(1, 1) are both pi/4, but atan2(-1, -1) is -3*pi/4. -// cos(x) - Returns the cosine of x, in radians. -// hypot(x, y) - Returns the Euclidean norm, sqrt(x*x + y*y). This is the length of the vector from the origin to point (x, y). -// sin(x) - Returns the sine of x, in radians. -// tan(x) - Returns the tangent of x, in radians. +// acos(x) - Returns the arc cosine of x, in radians. +// asin(x) - Returns the arc sine of x, in radians. +// atan(x) - Returns the arc tangent of x, in radians. +// atan2(y, x) - Returns atan(y / x), in radians. +// The result is between -pi and pi. +// The vector in the plane from the origin to point (x, y) makes this angle with the positive X axis. +// The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct +// quadrant for the angle. +// For example, atan(1) and atan2(1, 1) are both pi/4, but atan2(-1, -1) is -3*pi/4. +// cos(x) - Returns the cosine of x, in radians. +// hypot(x, y) - Returns the Euclidean norm, sqrt(x*x + y*y). This is the length of the vector from the origin to point (x, y). +// sin(x) - Returns the sine of x, in radians. +// tan(x) - Returns the tangent of x, in radians. // -// degrees(x) - Converts angle x from radians to degrees. -// radians(x) - Converts angle x from degrees to radians. +// degrees(x) - Converts angle x from radians to degrees. +// radians(x) - Converts angle x from degrees to radians. // -// acosh(x) - Returns the inverse hyperbolic cosine of x. -// asinh(x) - Returns the inverse hyperbolic sine of x. -// atanh(x) - Returns the inverse hyperbolic tangent of x. -// cosh(x) - Returns the hyperbolic cosine of x. -// sinh(x) - Returns the hyperbolic sine of x. -// tanh(x) - Returns the hyperbolic tangent of x. +// acosh(x) - Returns the inverse hyperbolic cosine of x. +// asinh(x) - Returns the inverse hyperbolic sine of x. +// atanh(x) - Returns the inverse hyperbolic tangent of x. +// cosh(x) - Returns the hyperbolic cosine of x. +// sinh(x) - Returns the hyperbolic sine of x. +// tanh(x) - Returns the hyperbolic tangent of x. // -// log(x, base) - Returns the logarithm of x in the given base, or natural logarithm by default. +// log(x, base) - Returns the logarithm of x in the given base, or natural logarithm by default. // -// gamma(x) - Returns the Gamma function of x. +// gamma(x) - Returns the Gamma function of x. // // All functions accept both int and float values as arguments. // // The module also defines approximations of the following constants: // -// e - The base of natural logarithms, approximately 2.71828. -// pi - The ratio of a circle's circumference to its diameter, approximately 3.14159. -// +// e - The base of natural logarithms, approximately 2.71828. +// pi - The ratio of a circle's circumference to its diameter, approximately 3.14159. type MathModule struct { ui ui.UI } @@ -203,7 +202,8 @@ func (m MathModule) warnOnCall(wrappedFunc core.StarlarkFunc) core.StarlarkFunc } } -// log wraps the Log function +// log wraps the Log function +// // as a Starlark built-in that accepts int or float arguments. func (m MathModule) log(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) { var ( diff --git a/test/filetests/filetests.go b/test/filetests/filetests.go index 4535e066..60dd7894 100644 --- a/test/filetests/filetests.go +++ b/test/filetests/filetests.go @@ -1,6 +1,10 @@ // Copyright 2022 VMware, Inc. // SPDX-License-Identifier: Apache-2.0 +/* +Package filetests houses a test harness for evaluating templates and asserting +the expected output. +*/ package filetests import (