From cd3f17b41f0371fcc04d65d335191d201dd7d139 Mon Sep 17 00:00:00 2001 From: xmh <1197843839@qq.com> Date: Wed, 31 Jan 2024 11:19:23 +0800 Subject: [PATCH] ci: add github action and resolve static warning (#777) * ci: add github action and resolve static warning (#5) * ci: add go check github action (#3) Signed-off-by: xmh1011 <1197843839@qq.com> * test: test ci test: test ci Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> * chore: resolve static warning Signed-off-by: xmh1011 <1197843839@qq.com> --------- Signed-off-by: xmh1011 <1197843839@qq.com> * chore: update go version Signed-off-by: xmh1011 <1197843839@qq.com> --------- Signed-off-by: xmh1011 <1197843839@qq.com> --- .github/workflows/ci.yml | 75 + Makefile | 8 + go.mod | 2 +- go.sum | 13 + inputs/appdynamics/instances.go | 2 +- inputs/mtail/internal/exporter/export_test.go | 2 +- .../internal/exporter/prometheus_test.go | 2 +- .../mtail/examples_integration_unix_test.go | 2 +- .../mtail/read_pipe_integration_unix_test.go | 2 +- .../runtime/compiler/codegen/codegen.go | 10 +- .../runtime/compiler/codegen/codegen_test.go | 1404 +++++++++-------- .../runtime/compiler/errors/errors.go | 2 +- .../internal/runtime/compiler/parser/lexer.go | 2 +- .../runtime/compiler/parser/lexer_test.go | 424 ++--- .../runtime/compiler/parser/parser_test.go | 24 +- inputs/mtail/internal/runtime/vm/vm_test.go | 1142 +++++++------- .../tailer/logstream/dgramstream_unix_test.go | 4 +- .../tailer/logstream/filestream_test.go | 14 +- .../tailer/logstream/filestream_unix_test.go | 6 +- .../tailer/logstream/pipestream_unix_test.go | 6 +- .../logstream/socketstream_unix_test.go | 4 +- inputs/mtail/internal/tailer/tail_test.go | 26 +- .../mtail/internal/tailer/tail_unix_test.go | 2 +- scripts/ci/go_version_check.sh | 16 + scripts/ci/go_vet.sh | 5 + scripts/ci/static_check.sh | 19 + 26 files changed, 1678 insertions(+), 1540 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 scripts/ci/go_version_check.sh create mode 100644 scripts/ci/go_vet.sh create mode 100644 scripts/ci/static_check.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..1b1de9d8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +name: Continuous Integration + +on: + workflow_dispatch: + pull_request: + types: [ opened, synchronize, reopened, ready_for_review ] + paths-ignore: + - 'conf/**' + - 'docker/**' + - 'doc/**' + - 'k8s/**' + - 'scripts/**' + - '**.md' + - '.gitignore' + +env: + GO111MODULE: on + GONOSUMDB: "*" + GOSUMDB: off + +jobs: + CommitLint: + name: Commit Lint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 100 + - name: Run commitlint + uses: wagoid/commitlint-github-action@v5 + GoLint: + name: "Code Analysis" + needs: CommitLint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: WillAbides/setup-go-faster@v1.14.0 + with: + go-version: "1.21" + - name: Run go version check + run: make go-version-check + - name: Run go vet check + run: make go-vet-check + - name: Run golang-ci-lint + uses: golangci/golangci-lint-action@v3.6.0 + with: + version: v1.53 + args: --timeout=10m --tests=false + only-new-issues: true + skip-pkg-cache: true + skip-build-cache: true + BuildCheck: + name: "Go Build Check" + needs: GoLint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: WillAbides/setup-go-faster@v1.14.0 + with: + go-version: "1.21" + - name: go mod tidy + run: make vendor + - name: go build linux + run: make build-linux && make build-linux-arm + - name: go build windows + run: make build-windows + - name: go build mac + run: make build-mac && make build-mac-arm diff --git a/Makefile b/Makefile index 4bc8fe73..aad6ec4f 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ TAG=$(shell echo "${_GIT_VERSION}" | awk -F"-" '{print $$1}') GIT_VERSION:="$(TAG)-$(GIT_COMMIT)" BUILD_VERSION:='flashcat.cloud/categraf/config.Version=$(GIT_VERSION)' LDFLAGS:="-w -s -X $(BUILD_VERSION)" +STYLE_CHECK_GOFILE := $$(find . -name '*.go') +GO := GO111MODULE=on go all: build @@ -52,3 +54,9 @@ pack:build-linux build-windows rm -rf $(APP)-$(TAG).zip tar -zcvf $(APP)-$(TAG)-linux-amd64.tar.gz conf $(APP) zip -r $(APP)-$(TAG)-windows-amd64.zip conf $(APP).exe + +go-version-check: + bash ./scripts/ci/go_version_check.sh + +go-vet-check: + bash ./scripts/ci/go_vet.sh diff --git a/go.mod b/go.mod index 95b7be0d..d5ca4dc3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module flashcat.cloud/categraf -go 1.19 +go 1.21 require ( github.com/Shopify/sarama v1.36.0 diff --git a/go.sum b/go.sum index 25ef4055..c052155d 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,7 @@ cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECH cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= cloud.google.com/go v0.110.0 h1:Zc8gqp3+a9/Eyph2KDmcGaPtbKRIoqq4YTlL4NMD0Ys= +cloud.google.com/go v0.110.0/go.mod h1:SJnCLqQ0FCFGSZMUNUf84MV3Aia54kn7pi8st7tMzaY= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -34,6 +35,7 @@ cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2Aawl cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM= +cloud.google.com/go/longrunning v0.4.1/go.mod h1:4iWDqhBZ70CvZ6BfETbvam3T8FMvLK+eFj0E6AaRQTo= cloud.google.com/go/monitoring v1.13.0 h1:2qsrgXGVoRXpP7otZ14eE1I568zAa92sJSDPyOJvwjM= cloud.google.com/go/monitoring v1.13.0/go.mod h1:k2yMBAB1H9JT/QETjNkgdCGD9bPF712XiLTVr+cBrpw= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= @@ -58,6 +60,7 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbL github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0= github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.11.18/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA= @@ -393,6 +396,7 @@ github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU= github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/freedomkk-qfeng/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:g8x+P3+xjxt7c53bucQW0ymvj+whjKfCLZH+99UMLS0= github.com/freedomkk-qfeng/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:UcrAEbxjAhuq5beDj0conKRHGUhBPLkFt8aUmN/jrHY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -673,6 +677,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= github.com/hashicorp/consul/api v1.8.1/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk= github.com/hashicorp/consul/api v1.15.3 h1:WYONYL2rxTXtlekAqblR2SCdJsizMDIj/uXb5wNy9zU= @@ -984,6 +989,7 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= +github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= @@ -1001,6 +1007,7 @@ github.com/moby/ipvs v1.0.2 h1:NSbzuRTvfneftLU3VwPU5QuA6NZ0IUmqq9+VHcQxqHw= github.com/moby/ipvs v1.0.2/go.mod h1:2pngiyseZbIKXNv7hsKj3O9UEz30c53MT9005gt2hxQ= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 h1:dcztxKSvZ4Id8iPpHERQBbIJfabdt4wUm5qy3wOL2Zc= +github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -1011,6 +1018,7 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mostynb/go-grpc-compression v1.1.16 h1:D9tGUINmcII049pxOj9dl32Fzhp26TrDVQXECoKJqQg= github.com/mostynb/go-grpc-compression v1.1.16/go.mod h1:xxa6UoYynYS2h+5HB/Hglu81iYAp87ARaNmhhwi0s1s= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= @@ -1033,6 +1041,7 @@ github.com/nats-io/nats-server/v2 v2.10.9/go.mod h1:oorGiV9j3BOLLO3ejQe+U7pfAGyP github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E= +github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= @@ -1069,6 +1078,7 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/open-telemetry/opentelemetry-collector v0.54.0 h1:Ib3aRVdlDhqy6FUcSP/ID1YoPnTnXKCP84g8HPM3Z9o= github.com/open-telemetry/opentelemetry-collector v0.54.0/go.mod h1:FgNzyfb4sAGb5cqusB5znETJ8Pz4OQUBGbOeGIZ2rlQ= @@ -1089,6 +1099,7 @@ github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthchecke github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension v0.54.0 h1:3HbhTEm0RPvbySmuFmbzv9ZuDBWvUPsLqwnuo5uLWt0= github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension v0.54.0/go.mod h1:5bWnzEUIlYXKUf9l0Bozfkx5FkFmrJKbuXEG/2RabkQ= github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.54.0 h1:dYT3V8dSbdlo+P+f7sAV9pLha034GDxTF3GphUysHFI= +github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.54.0/go.mod h1:h09Gu4NgUG2Dj2sJC9Zz7Ldk7BV965KLls2mQCpm0u8= github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.54.0 h1:Bvf7Dt70kj9O2lJ6XCiYny4aFqp6WlSR6d40gj9GzgI= github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.54.0/go.mod h1:CSe1wsnLhSAEgAEXLfi8wTyl0VwPVkq7925aV8xm0oM= github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.54.0 h1:ei9mpIXxeyLp0l9sEwHsnTMniBdQBwi4QfzYbR8st5c= @@ -1178,6 +1189,7 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus-community/pro-bing v0.1.0 h1:zjzLGhfNPP0bP1OlzGB+SJcguOViw7df12LPg2vUJh8= github.com/prometheus-community/pro-bing v0.1.0/go.mod h1:BpWlHurD9flHtzq8wrh8QGWYz9ka9z9ZJAyOel8ej58= github.com/prometheus/alertmanager v0.24.0 h1:HBWR3lk4uy3ys+naDZthDdV7yEsxpaNeZuUS+hJgrOw= @@ -1428,6 +1440,7 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.3 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0 h1:mac9BKRqwaX6zxHPDe3pvmWpwuuIM0vuXv2juCnQevE= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0/go.mod h1:5eCOqeGphOyz6TsY3ZDNjE33SM/TFAK3RGuCL2naTgY= go.opentelemetry.io/contrib/zpages v0.32.0 h1:AVKTx5ppWDaem7A61HFsO1T3CK/t6kFRQoZQMj0/TW4= +go.opentelemetry.io/contrib/zpages v0.32.0/go.mod h1:Jx75I61RDcZU3d/1WrP6UdINlzGGLAwFNdQ3bCTb+qw= go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= go.opentelemetry.io/otel/exporters/prometheus v0.30.0 h1:YXo5ZY5nofaEYMCMTTMaRH2cLDZB8+0UGuk5RwMfIo0= diff --git a/inputs/appdynamics/instances.go b/inputs/appdynamics/instances.go index cd08a837..f2829b92 100644 --- a/inputs/appdynamics/instances.go +++ b/inputs/appdynamics/instances.go @@ -69,7 +69,7 @@ type ( Sum float64 `json:"sum"` Value float64 `json:"value"` - standardDiv float64 `json:"standardDeviation"` + StandardDiv float64 `json:"standardDeviation"` } ) diff --git a/inputs/mtail/internal/exporter/export_test.go b/inputs/mtail/internal/exporter/export_test.go index 8644e4c9..a2a728d5 100644 --- a/inputs/mtail/internal/exporter/export_test.go +++ b/inputs/mtail/internal/exporter/export_test.go @@ -135,7 +135,7 @@ func TestMetricToGraphite(t *testing.T) { testutil.ExpectNoDiff(t, expected, r) histogramMetric := metrics.NewMetric("hist", "prog", metrics.Histogram, metrics.Buckets, "xxx") - lv := &metrics.LabelValue{Labels: []string{"bar"}, Value: datum.MakeBuckets([]datum.Range{{0, 10}, {10, 20}}, time.Unix(0, 0))} + lv := &metrics.LabelValue{Labels: []string{"bar"}, Value: datum.MakeBuckets([]datum.Range{{Min: 0, Max: 10}, {Min: 10, Max: 20}}, time.Unix(0, 0))} histogramMetric.AppendLabelValue(lv) d, _ = histogramMetric.GetDatum("bar") datum.SetFloat(d, 1, ts) diff --git a/inputs/mtail/internal/exporter/prometheus_test.go b/inputs/mtail/internal/exporter/prometheus_test.go index b18e50c9..28cc8cf2 100644 --- a/inputs/mtail/internal/exporter/prometheus_test.go +++ b/inputs/mtail/internal/exporter/prometheus_test.go @@ -192,7 +192,7 @@ foo{prog="test1"} 1 Program: "test", Kind: metrics.Histogram, Keys: []string{"a"}, - LabelValues: []*metrics.LabelValue{{Labels: []string{"bar"}, Value: datum.MakeBuckets([]datum.Range{{0, 1}, {1, 2}}, time.Unix(0, 0))}}, + LabelValues: []*metrics.LabelValue{{Labels: []string{"bar"}, Value: datum.MakeBuckets([]datum.Range{{Min: 0, Max: 1}, {Min: 1, Max: 2}}, time.Unix(0, 0))}}, Source: "location.mtail:37", }, }, diff --git a/inputs/mtail/internal/mtail/examples_integration_unix_test.go b/inputs/mtail/internal/mtail/examples_integration_unix_test.go index 6072585d..7da8e8f1 100644 --- a/inputs/mtail/internal/mtail/examples_integration_unix_test.go +++ b/inputs/mtail/internal/mtail/examples_integration_unix_test.go @@ -148,7 +148,7 @@ func TestFileSocketStreamComparison(t *testing.T) { defer wg.Done() source, err := os.OpenFile(tc.logfile, os.O_RDONLY, 0) testutil.FatalIfErr(t, err) - s, err := net.DialUnix(scheme, nil, &net.UnixAddr{sockName, scheme}) + s, err := net.DialUnix(scheme, nil, &net.UnixAddr{Name: sockName, Net: scheme}) testutil.FatalIfErr(t, err) n, err := io.Copy(s, source) testutil.FatalIfErr(t, err) diff --git a/inputs/mtail/internal/mtail/read_pipe_integration_unix_test.go b/inputs/mtail/internal/mtail/read_pipe_integration_unix_test.go index 7cd635d4..9bd2dfa3 100644 --- a/inputs/mtail/internal/mtail/read_pipe_integration_unix_test.go +++ b/inputs/mtail/internal/mtail/read_pipe_integration_unix_test.go @@ -73,7 +73,7 @@ func TestReadFromSocket(t *testing.T) { lineCountCheck := m.ExpectExpvarDeltaWithDeadline("lines_total", 3) time.Sleep(10 * time.Millisecond) - s, err := net.DialUnix(scheme, nil, &net.UnixAddr{logFile, scheme}) + s, err := net.DialUnix(scheme, nil, &net.UnixAddr{Name: logFile, Net: scheme}) testutil.FatalIfErr(t, err) defer func() { testutil.FatalIfErr(t, s.Close()) diff --git a/inputs/mtail/internal/runtime/compiler/codegen/codegen.go b/inputs/mtail/internal/runtime/compiler/codegen/codegen.go index e50cb233..8d094c21 100644 --- a/inputs/mtail/internal/runtime/compiler/codegen/codegen.go +++ b/inputs/mtail/internal/runtime/compiler/codegen/codegen.go @@ -50,7 +50,7 @@ func (c *codegen) errorf(pos *position.Position, format string, args ...interfac func (c *codegen) emit(n ast.Node, opcode code.Opcode, operand interface{}) { // glog.V(2).Infof("emitting `%s %v' from line %d node %#v\n", opcode, operand, n.Pos().Line, n) - c.obj.Program = append(c.obj.Program, code.Instr{opcode, operand, n.Pos().Line}) + c.obj.Program = append(c.obj.Program, code.Instr{Opcode: opcode, Operand: operand, SourceLine: n.Pos().Line}) } // newLabel creates a new label to jump to. @@ -136,19 +136,19 @@ func (c *codegen) VisitBefore(node ast.Node) (ast.Visitor, ast.Node) { } if n.Buckets[0] > 0 { - m.Buckets = append(m.Buckets, datum.Range{0, n.Buckets[0]}) + m.Buckets = append(m.Buckets, datum.Range{Max: n.Buckets[0]}) } - m.Buckets = append(m.Buckets, datum.Range{n.Buckets[0], n.Buckets[1]}) + m.Buckets = append(m.Buckets, datum.Range{Min: n.Buckets[0], Max: n.Buckets[1]}) min := n.Buckets[1] for _, max := range n.Buckets[2:] { if max <= min { c.errorf(n.Pos(), "buckets boundaries must be sorted") return nil, n } - m.Buckets = append(m.Buckets, datum.Range{min, max}) + m.Buckets = append(m.Buckets, datum.Range{Min: min, Max: max}) min = max } - m.Buckets = append(m.Buckets, datum.Range{min, math.Inf(+1)}) + m.Buckets = append(m.Buckets, datum.Range{Min: min, Max: math.Inf(+1)}) if len(n.Keys) == 0 { // Calling GetDatum here causes the storage to be allocated. diff --git a/inputs/mtail/internal/runtime/compiler/codegen/codegen_test.go b/inputs/mtail/internal/runtime/compiler/codegen/codegen_test.go index adc0df81..8e6e16bc 100644 --- a/inputs/mtail/internal/runtime/compiler/codegen/codegen_test.go +++ b/inputs/mtail/internal/runtime/compiler/codegen/codegen_test.go @@ -26,260 +26,260 @@ var testCodeGenPrograms = []struct { }{ // Composite literals require too many explicit conversions. { - "simple line counter", - "counter lines_total\n/$/ { lines_total++\n }\n", - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 7, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 1}, - {code.Dload, 0, 1}, - {code.Inc, nil, 1}, - {code.Setmatched, true, 1}, + name: "simple line counter", + source: "counter lines_total\n/$/ { lines_total++\n }\n", + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 7, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 1}, + {Opcode: code.Dload, Operand: 0, SourceLine: 1}, + {Opcode: code.Inc, Operand: nil, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "count a", - "counter a_count\n/a$/ { a_count++\n }\n", - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 7, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 1}, - {code.Dload, 0, 1}, - {code.Inc, nil, 1}, - {code.Setmatched, true, 1}, + name: "count a", + source: "counter a_count\n/a$/ { a_count++\n }\n", + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 7, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 1}, + {Opcode: code.Dload, Operand: 0, SourceLine: 1}, + {Opcode: code.Inc, Operand: nil, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "strptime and capref", - "counter foo\n" + + name: "strptime and capref", + source: "counter foo\n" + "/(.*)/ { strptime($1, \"2006-01-02T15:04:05\")\n" + "foo++\n}\n", - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 11, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 1}, - {code.Capref, 1, 1}, - {code.Str, 0, 1}, - {code.Strptime, 2, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 11, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 1}, + {Opcode: code.Capref, Operand: 1, SourceLine: 1}, + {Opcode: code.Str, Operand: 0, SourceLine: 1}, + {Opcode: code.Strptime, Operand: 2, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "strptime and named capref", - "counter foo\n" + + name: "strptime and named capref", + source: "counter foo\n" + "/(?P.*)/ { strptime($date, \"2006-01-02T15:04:05\")\n" + "foo++\n }\n", - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 11, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 1}, - {code.Capref, 1, 1}, - {code.Str, 0, 1}, - {code.Strptime, 2, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 11, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 1}, + {Opcode: code.Capref, Operand: 1, SourceLine: 1}, + {Opcode: code.Str, Operand: 0, SourceLine: 1}, + {Opcode: code.Strptime, Operand: 2, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "inc by and set", - "counter foo\ncounter bar\n" + + name: "inc by and set", + source: "counter foo\ncounter bar\n" + "/([0-9]+)/ {\n" + "foo += $1\n" + "bar = $1\n" + "}\n", - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 16, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.S2i, nil, 3}, - {code.Inc, 0, 3}, - {code.Mload, 1, 4}, - {code.Dload, 0, 4}, - {code.Push, 0, 4}, - {code.Capref, 1, 4}, - {code.S2i, nil, 4}, - {code.Iset, nil, 4}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 16, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.Inc, Operand: 0, SourceLine: 3}, + {Opcode: code.Mload, Operand: 1, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Push, Operand: 0, SourceLine: 4}, + {Opcode: code.Capref, Operand: 1, SourceLine: 4}, + {Opcode: code.S2i, Operand: nil, SourceLine: 4}, + {Opcode: code.Iset, Operand: nil, SourceLine: 4}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "cond expr gt", - "counter foo\n" + + name: "cond expr gt", + source: "counter foo\n" + "1 > 0 {\n" + " foo++\n" + "}\n", - []code.Instr{ - {code.Push, int64(1), 1}, - {code.Push, int64(0), 1}, - {code.Icmp, 1, 1}, - {code.Jnm, 6, 1}, - {code.Push, true, 1}, - {code.Jmp, 7, 1}, - {code.Push, false, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 1}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 1}, + {Opcode: code.Icmp, Operand: 1, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 6, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "cond expr lt", - "counter foo\n" + + name: "cond expr lt", + source: "counter foo\n" + "1 < 0 {\n" + " foo++\n" + "}\n", - []code.Instr{ - {code.Push, int64(1), 1}, - {code.Push, int64(0), 1}, - {code.Icmp, -1, 1}, - {code.Jnm, 6, 1}, - {code.Push, true, 1}, - {code.Jmp, 7, 1}, - {code.Push, false, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 1}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 1}, + {Opcode: code.Icmp, Operand: -1, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 6, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "cond expr eq", - "counter foo\n" + + name: "cond expr eq", + source: "counter foo\n" + "1 == 0 {\n" + " foo++\n" + "}\n", - []code.Instr{ - {code.Push, int64(1), 1}, - {code.Push, int64(0), 1}, - {code.Icmp, 0, 1}, - {code.Jnm, 6, 1}, - {code.Push, true, 1}, - {code.Jmp, 7, 1}, - {code.Push, false, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 1}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 1}, + {Opcode: code.Icmp, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 6, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "cond expr le", - "counter foo\n" + + name: "cond expr le", + source: "counter foo\n" + "1 <= 0 {\n" + " foo++\n" + "}\n", - []code.Instr{ - {code.Push, int64(1), 1}, - {code.Push, int64(0), 1}, - {code.Icmp, 1, 1}, - {code.Jm, 6, 1}, - {code.Push, true, 1}, - {code.Jmp, 7, 1}, - {code.Push, false, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 1}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 1}, + {Opcode: code.Icmp, Operand: 1, SourceLine: 1}, + {Opcode: code.Jm, Operand: 6, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "cond expr ge", - "counter foo\n" + + name: "cond expr ge", + source: "counter foo\n" + "1 >= 0 {\n" + " foo++\n" + "}\n", - []code.Instr{ - {code.Push, int64(1), 1}, - {code.Push, int64(0), 1}, - {code.Icmp, -1, 1}, - {code.Jm, 6, 1}, - {code.Push, true, 1}, - {code.Jmp, 7, 1}, - {code.Push, false, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 1}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 1}, + {Opcode: code.Icmp, Operand: -1, SourceLine: 1}, + {Opcode: code.Jm, Operand: 6, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "cond expr ne", - "counter foo\n" + + name: "cond expr ne", + source: "counter foo\n" + "1 != 0 {\n" + " foo++\n" + "}\n", - []code.Instr{ - {code.Push, int64(1), 1}, - {code.Push, int64(0), 1}, - {code.Icmp, 0, 1}, - {code.Jm, 6, 1}, - {code.Push, true, 1}, - {code.Jmp, 7, 1}, - {code.Push, false, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 1}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 1}, + {Opcode: code.Icmp, Operand: 0, SourceLine: 1}, + {Opcode: code.Jm, Operand: 6, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "nested cond", - "counter foo\n" + + name: "nested cond", + source: "counter foo\n" + "/(\\d+)/ {\n" + " $1 <= 1 {\n" + " foo++\n" + " }\n" + "}\n", - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 19, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2i, nil, 2}, - {code.Push, int64(1), 2}, - {code.Icmp, 1, 2}, - {code.Jm, 11, 2}, - {code.Push, true, 2}, - {code.Jmp, 12, 2}, - {code.Push, false, 2}, - {code.Jnm, 18, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Inc, nil, 3}, - {code.Setmatched, true, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 19, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2i, Operand: nil, SourceLine: 2}, + {Opcode: code.Push, Operand: int64(1), SourceLine: 2}, + {Opcode: code.Icmp, Operand: 1, SourceLine: 2}, + {Opcode: code.Jm, Operand: 11, SourceLine: 2}, + {Opcode: code.Push, Operand: true, SourceLine: 2}, + {Opcode: code.Jmp, Operand: 12, SourceLine: 2}, + {Opcode: code.Push, Operand: false, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 18, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Inc, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "deco", - "counter foo\n" + + name: "deco", + source: "counter foo\n" + "counter bar\n" + "def fooWrap {\n" + " /.*/ {\n" + @@ -289,211 +289,211 @@ var testCodeGenPrograms = []struct { "}\n" + "" + "@fooWrap { bar++\n }\n", - []code.Instr{ - {code.Match, 0, 3}, - {code.Jnm, 10, 3}, - {code.Setmatched, false, 3}, - {code.Mload, 0, 4}, - {code.Dload, 0, 4}, - {code.Inc, nil, 4}, - {code.Mload, 1, 8}, - {code.Dload, 0, 8}, - {code.Inc, nil, 8}, - {code.Setmatched, true, 3}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 3}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Inc, Operand: nil, SourceLine: 4}, + {Opcode: code.Mload, Operand: 1, SourceLine: 8}, + {Opcode: code.Dload, Operand: 0, SourceLine: 8}, + {Opcode: code.Inc, Operand: nil, SourceLine: 8}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 3}, }, }, { - "length", - "len(\"foo\") > 0 {\n" + + name: "length", + source: "len(\"foo\") > 0 {\n" + "}\n", - []code.Instr{ - {code.Str, 0, 0}, - {code.Length, 1, 0}, - {code.Push, int64(0), 0}, - {code.Cmp, 1, 0}, - {code.Jnm, 7, 0}, - {code.Push, true, 0}, - {code.Jmp, 8, 0}, - {code.Push, false, 0}, - {code.Jnm, 11, 0}, - {code.Setmatched, false, 0}, - {code.Setmatched, true, 0}, + prog: []code.Instr{ + {Opcode: code.Str, Operand: 0, SourceLine: 0}, + {Opcode: code.Length, Operand: 1, SourceLine: 0}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 0}, + {Opcode: code.Cmp, Operand: 1, SourceLine: 0}, + {Opcode: code.Jnm, Operand: 7, SourceLine: 0}, + {Opcode: code.Push, Operand: true, SourceLine: 0}, + {Opcode: code.Jmp, Operand: 8, SourceLine: 0}, + {Opcode: code.Push, Operand: false, SourceLine: 0}, + {Opcode: code.Jnm, Operand: 11, SourceLine: 0}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 0}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 0}, }, }, { - "bitwise", ` + name: "bitwise", source: ` gauge a a = 1 & 7 ^ 15 | 8 a = ~ 16 << 2 a = 1 >> 20 `, - []code.Instr{ - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, int64(1), 3}, - {code.Push, int64(7), 3}, - {code.And, nil, 3}, - {code.Push, int64(15), 3}, - {code.Xor, nil, 3}, - {code.Push, int64(8), 3}, - {code.Or, nil, 3}, - {code.Iset, nil, 3}, - {code.Mload, 0, 4}, - {code.Dload, 0, 4}, - {code.Push, int64(16), 4}, - {code.Neg, nil, 4}, - {code.Push, int64(2), 4}, - {code.Shl, nil, 4}, - {code.Iset, nil, 4}, - {code.Mload, 0, 5}, - {code.Dload, 0, 5}, - {code.Push, int64(1), 5}, - {code.Push, int64(20), 5}, - {code.Shr, nil, 5}, - {code.Iset, nil, 5}, + prog: []code.Instr{ + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: int64(1), SourceLine: 3}, + {Opcode: code.Push, Operand: int64(7), SourceLine: 3}, + {Opcode: code.And, Operand: nil, SourceLine: 3}, + {Opcode: code.Push, Operand: int64(15), SourceLine: 3}, + {Opcode: code.Xor, Operand: nil, SourceLine: 3}, + {Opcode: code.Push, Operand: int64(8), SourceLine: 3}, + {Opcode: code.Or, Operand: nil, SourceLine: 3}, + {Opcode: code.Iset, Operand: nil, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Push, Operand: int64(16), SourceLine: 4}, + {Opcode: code.Neg, Operand: nil, SourceLine: 4}, + {Opcode: code.Push, Operand: int64(2), SourceLine: 4}, + {Opcode: code.Shl, Operand: nil, SourceLine: 4}, + {Opcode: code.Iset, Operand: nil, SourceLine: 4}, + {Opcode: code.Mload, Operand: 0, SourceLine: 5}, + {Opcode: code.Dload, Operand: 0, SourceLine: 5}, + {Opcode: code.Push, Operand: int64(1), SourceLine: 5}, + {Opcode: code.Push, Operand: int64(20), SourceLine: 5}, + {Opcode: code.Shr, Operand: nil, SourceLine: 5}, + {Opcode: code.Iset, Operand: nil, SourceLine: 5}, }, }, { - "pow", ` + name: "pow", source: ` gauge a /(\d+) (\d+)/ { a = $1 ** $2 } `, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 14, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.S2i, nil, 3}, - {code.Push, 0, 3}, - {code.Capref, 2, 3}, - {code.S2i, nil, 3}, - {code.Ipow, nil, 3}, - {code.Iset, nil, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 14, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 2, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.Ipow, Operand: nil, SourceLine: 3}, + {Opcode: code.Iset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "indexed expr", ` + name: "indexed expr", source: ` counter a by b a["string"]++ `, - []code.Instr{ - {code.Str, 0, 2}, - {code.Mload, 0, 2}, - {code.Dload, 1, 2}, - {code.Inc, nil, 2}, + prog: []code.Instr{ + {Opcode: code.Str, Operand: 0, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 1, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, }, }, { - "strtol", ` + name: "strtol", source: ` strtol("deadbeef", 16) `, - []code.Instr{ - {code.Str, 0, 1}, - {code.Push, int64(16), 1}, - {code.S2i, 2, 1}, + prog: []code.Instr{ + {Opcode: code.Str, Operand: 0, SourceLine: 1}, + {Opcode: code.Push, Operand: int64(16), SourceLine: 1}, + {Opcode: code.S2i, Operand: 2, SourceLine: 1}, }, }, { - "float", ` + name: "float", source: ` 20.0 `, - []code.Instr{ - {code.Push, 20.0, 1}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: 20.0, SourceLine: 1}, }, }, { - "otherwise", ` + name: "otherwise", source: ` counter a otherwise { a++ } `, - []code.Instr{ - {code.Otherwise, nil, 2}, - {code.Jnm, 7, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Inc, nil, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Otherwise, Operand: nil, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 7, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Inc, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "cond else", - `counter foo + name: "cond else", + source: `counter foo counter bar 1 > 0 { foo++ } else { bar++ }`, - []code.Instr{ - {code.Push, int64(1), 2}, - {code.Push, int64(0), 2}, - {code.Icmp, 1, 2}, - {code.Jnm, 6, 2}, - {code.Push, true, 2}, - {code.Jmp, 7, 2}, - {code.Push, false, 2}, - {code.Jnm, 14, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Inc, nil, 3}, - {code.Setmatched, true, 2}, - {code.Jmp, 17, 2}, - {code.Mload, 1, 5}, - {code.Dload, 0, 5}, - {code.Inc, nil, 5}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: int64(1), SourceLine: 2}, + {Opcode: code.Push, Operand: int64(0), SourceLine: 2}, + {Opcode: code.Icmp, Operand: 1, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 6, SourceLine: 2}, + {Opcode: code.Push, Operand: true, SourceLine: 2}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 2}, + {Opcode: code.Push, Operand: false, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 14, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Inc, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, + {Opcode: code.Jmp, Operand: 17, SourceLine: 2}, + {Opcode: code.Mload, Operand: 1, SourceLine: 5}, + {Opcode: code.Dload, Operand: 0, SourceLine: 5}, + {Opcode: code.Inc, Operand: nil, SourceLine: 5}, }, }, { - "mod", - ` + name: "mod", + source: ` gauge a a = 3 % 1 `, - []code.Instr{ - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Push, int64(3), 2}, - {code.Push, int64(1), 2}, - {code.Imod, nil, 2}, - {code.Iset, nil, 2}, + prog: []code.Instr{ + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Push, Operand: int64(3), SourceLine: 2}, + {Opcode: code.Push, Operand: int64(1), SourceLine: 2}, + {Opcode: code.Imod, Operand: nil, SourceLine: 2}, + {Opcode: code.Iset, Operand: nil, SourceLine: 2}, }, }, { - "del", ` + name: "del", source: ` counter a by b del a["string"] `, - []code.Instr{ - {code.Str, 0, 2}, - {code.Mload, 0, 2}, - {code.Del, 1, 2}, + prog: []code.Instr{ + {Opcode: code.Str, Operand: 0, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Del, Operand: 1, SourceLine: 2}, }, }, { - "del after", ` + name: "del after", source: ` counter a by b del a["string"] after 1h `, - []code.Instr{ - {code.Push, time.Hour, 2}, - {code.Str, 0, 2}, - {code.Mload, 0, 2}, - {code.Expire, 1, 2}, + prog: []code.Instr{ + {Opcode: code.Push, Operand: time.Hour, SourceLine: 2}, + {Opcode: code.Str, Operand: 0, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Expire, Operand: 1, SourceLine: 2}, }, }, { - "types", ` + name: "types", source: ` gauge i gauge f /(\d+)/ { @@ -503,479 +503,481 @@ gauge f f = $1 } `, - []code.Instr{ - {code.Match, 0, 3}, - {code.Jnm, 10, 3}, - {code.Setmatched, false, 3}, - {code.Mload, 0, 4}, - {code.Dload, 0, 4}, - {code.Push, 0, 4}, - {code.Capref, 1, 4}, - {code.S2i, nil, 4}, - {code.Iset, nil, 4}, - {code.Setmatched, true, 3}, - {code.Match, 1, 6}, - {code.Jnm, 20, 6}, - {code.Setmatched, false, 6}, - {code.Mload, 1, 7}, - {code.Dload, 0, 7}, - {code.Push, 1, 7}, - {code.Capref, 1, 7}, - {code.S2f, nil, 7}, - {code.Fset, nil, 7}, - {code.Setmatched, true, 6}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 3}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Push, Operand: 0, SourceLine: 4}, + {Opcode: code.Capref, Operand: 1, SourceLine: 4}, + {Opcode: code.S2i, Operand: nil, SourceLine: 4}, + {Opcode: code.Iset, Operand: nil, SourceLine: 4}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 3}, + {Opcode: code.Match, Operand: 1, SourceLine: 6}, + {Opcode: code.Jnm, Operand: 20, SourceLine: 6}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 6}, + {Opcode: code.Mload, Operand: 1, SourceLine: 7}, + {Opcode: code.Dload, Operand: 0, SourceLine: 7}, + {Opcode: code.Push, Operand: 1, SourceLine: 7}, + {Opcode: code.Capref, Operand: 1, SourceLine: 7}, + {Opcode: code.S2f, Operand: nil, SourceLine: 7}, + {Opcode: code.Fset, Operand: nil, SourceLine: 7}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 6}, }, }, { - "getfilename", ` + name: "getfilename", source: ` getfilename() `, - []code.Instr{ - {code.Getfilename, 0, 1}, + prog: []code.Instr{ + {Opcode: code.Getfilename, Operand: 0, SourceLine: 1}, }, }, { - "dimensioned counter", - `counter c by a,b,c + name: "dimensioned counter", + source: `counter c by a,b,c /(\d) (\d) (\d)/ { c[$1,$2][$3]++ } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 13, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.Push, 0, 2}, - {code.Capref, 2, 2}, - {code.Push, 0, 2}, - {code.Capref, 3, 2}, - {code.Mload, 0, 2}, - {code.Dload, 3, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 2, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 3, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 3, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "string to int", - `counter c + name: "string to int", + source: `counter c /(.*)/ { c = int($1) } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 10, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2i, nil, 2}, - {code.Iset, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2i, Operand: nil, SourceLine: 2}, + {Opcode: code.Iset, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "int to float", - `counter c + name: "int to float", + source: `counter c /(\d)/ { c = float($1) } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 10, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2f, nil, 2}, - {code.Fset, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2f, Operand: nil, SourceLine: 2}, + {Opcode: code.Fset, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "string to float", - `counter c + name: "string to float", + source: `counter c /(.*)/ { c = float($1) } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 10, 1}, - {code.Setmatched, false, 1}, - {code.Mload, 0, 2}, - {code.Dload, 0, 2}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2f, nil, 2}, - {code.Fset, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 0, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2f, Operand: nil, SourceLine: 2}, + {Opcode: code.Fset, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "float to string", - `counter c by a + name: "float to string", + source: `counter c by a /(\d+\.\d+)/ { c[string($1)] ++ } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 11, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2f, nil, 2}, - {code.F2s, nil, 2}, - {code.Mload, 0, 2}, - {code.Dload, 1, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 11, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2f, Operand: nil, SourceLine: 2}, + {Opcode: code.F2s, Operand: nil, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 1, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "int to string", - `counter c by a + name: "int to string", + source: `counter c by a /(\d+)/ { c[string($1)] ++ } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 11, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2i, nil, 2}, - {code.I2s, nil, 2}, - {code.Mload, 0, 2}, - {code.Dload, 1, 2}, - {code.Inc, nil, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 11, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2i, Operand: nil, SourceLine: 2}, + {Opcode: code.I2s, Operand: nil, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 2}, + {Opcode: code.Dload, Operand: 1, SourceLine: 2}, + {Opcode: code.Inc, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "nested comparisons", - `counter foo + name: "nested comparisons", + source: `counter foo /(.*)/ { $1 == "foo" || $1 == "bar" { foo++ } } `, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 31, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.Str, 0, 2}, - {code.Scmp, 0, 2}, - {code.Jnm, 10, 2}, - {code.Push, true, 2}, - {code.Jmp, 11, 2}, - {code.Push, false, 2}, - {code.Jm, 23, 2}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.Str, 1, 2}, - {code.Scmp, 0, 2}, - {code.Jnm, 19, 2}, - {code.Push, true, 2}, - {code.Jmp, 20, 2}, - {code.Push, false, 2}, - {code.Jm, 23, 2}, - {code.Push, false, 2}, - {code.Jmp, 24, 2}, - {code.Push, true, 2}, - {code.Jnm, 30, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Inc, nil, 3}, - {code.Setmatched, true, 2}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 31, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.Str, Operand: 0, SourceLine: 2}, + {Opcode: code.Scmp, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 2}, + {Opcode: code.Push, Operand: true, SourceLine: 2}, + {Opcode: code.Jmp, Operand: 11, SourceLine: 2}, + {Opcode: code.Push, Operand: false, SourceLine: 2}, + {Opcode: code.Jm, Operand: 23, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.Str, Operand: 1, SourceLine: 2}, + {Opcode: code.Scmp, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 19, SourceLine: 2}, + {Opcode: code.Push, Operand: true, SourceLine: 2}, + {Opcode: code.Jmp, Operand: 20, SourceLine: 2}, + {Opcode: code.Push, Operand: false, SourceLine: 2}, + {Opcode: code.Jm, Operand: 23, SourceLine: 2}, + {Opcode: code.Push, Operand: false, SourceLine: 2}, + {Opcode: code.Jmp, Operand: 24, SourceLine: 2}, + {Opcode: code.Push, Operand: true, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 30, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Inc, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "string concat", ` + name: "string concat", source: ` counter f by s /(.*), (.*)/ { f[$1 + $2]++ } `, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 12, 2}, - {code.Setmatched, false, 2}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.Push, 0, 3}, - {code.Capref, 2, 3}, - {code.Cat, nil, 3}, - {code.Mload, 0, 3}, - {code.Dload, 1, 3}, - {code.Inc, nil, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 12, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 2, SourceLine: 3}, + {Opcode: code.Cat, Operand: nil, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 1, SourceLine: 3}, + {Opcode: code.Inc, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "add assign float", ` + name: "add assign float", source: ` gauge foo /(\d+\.\d+)/ { foo += $1 } `, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 13, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.S2f, nil, 3}, - {code.Fadd, nil, 3}, - {code.Fset, nil, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.S2f, Operand: nil, SourceLine: 3}, + {Opcode: code.Fadd, Operand: nil, SourceLine: 3}, + {Opcode: code.Fset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "match expression", ` + name: "match expression", source: ` counter foo /(.*)/ { $1 =~ /asdf/ { foo++ } }`, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 13, 2}, - {code.Setmatched, false, 2}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.Smatch, 1, 3}, - {code.Jnm, 12, 3}, - {code.Setmatched, false, 3}, - {code.Mload, 0, 4}, - {code.Dload, 0, 4}, - {code.Inc, nil, 4}, - {code.Setmatched, true, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.Smatch, Operand: 1, SourceLine: 3}, + {Opcode: code.Jnm, Operand: 12, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Inc, Operand: nil, SourceLine: 4}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "negative match expression", ` + name: "negative match expression", source: ` counter foo /(.*)/ { $1 !~ /asdf/ { foo++ } }`, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 14, 2}, - {code.Setmatched, false, 2}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.Smatch, 1, 3}, - {code.Not, nil, 3}, - {code.Jnm, 13, 3}, - {code.Setmatched, false, 3}, - {code.Mload, 0, 4}, - {code.Dload, 0, 4}, - {code.Inc, nil, 4}, - {code.Setmatched, true, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 14, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.Smatch, Operand: 1, SourceLine: 3}, + {Opcode: code.Not, Operand: nil, SourceLine: 3}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Inc, Operand: nil, SourceLine: 4}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "capref used in def", ` + name: "capref used in def", source: ` /(?P\d+)/ && $x > 5 { }`, - []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 14, 1}, - {code.Push, 0, 1}, - {code.Capref, 1, 1}, - {code.S2i, nil, 1}, - {code.Push, int64(5), 1}, - {code.Icmp, 1, 1}, - {code.Jnm, 10, 1}, - {code.Push, true, 1}, - {code.Jmp, 11, 1}, - {code.Push, false, 1}, - {code.Jnm, 14, 1}, - {code.Push, true, 1}, - {code.Jmp, 15, 1}, - {code.Push, false, 1}, - {code.Jnm, 18, 1}, - {code.Setmatched, false, 1}, - {code.Setmatched, true, 1}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 14, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 1}, + {Opcode: code.Capref, Operand: 1, SourceLine: 1}, + {Opcode: code.S2i, Operand: nil, SourceLine: 1}, + {Opcode: code.Push, Operand: int64(5), SourceLine: 1}, + {Opcode: code.Icmp, Operand: 1, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 11, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 14, SourceLine: 1}, + {Opcode: code.Push, Operand: true, SourceLine: 1}, + {Opcode: code.Jmp, Operand: 15, SourceLine: 1}, + {Opcode: code.Push, Operand: false, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 18, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }, }, { - "binop arith type conversion", ` + name: "binop arith type conversion", source: ` gauge var /(?P\d+) (\d+\.\d+)/ { var = $x + $2 }`, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 15, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.S2i, nil, 3}, - {code.I2f, nil, 3}, - {code.Push, 0, 3}, - {code.Capref, 2, 3}, - {code.S2f, nil, 3}, - {code.Fadd, nil, 3}, - {code.Fset, nil, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 15, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.I2f, Operand: nil, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 2, SourceLine: 3}, + {Opcode: code.S2f, Operand: nil, SourceLine: 3}, + {Opcode: code.Fadd, Operand: nil, SourceLine: 3}, + {Opcode: code.Fset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, { - "binop compare type conversion", ` + name: "binop compare type conversion", source: ` counter var /(?P\d+) (\d+\.\d+)/ { $x > $2 { var++ } }`, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 22, 2}, - {code.Setmatched, false, 2}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.S2i, nil, 3}, - {code.I2f, nil, 3}, - {code.Push, 0, 3}, - {code.Capref, 2, 3}, - {code.S2f, nil, 3}, - {code.Fcmp, 1, 3}, - {code.Jnm, 14, 3}, - {code.Push, true, 3}, - {code.Jmp, 15, 3}, - {code.Push, false, 3}, - {code.Jnm, 21, 3}, - {code.Setmatched, false, 3}, - {code.Mload, 0, 4}, - {code.Dload, 0, 4}, - {code.Inc, nil, 4}, - {code.Setmatched, true, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 22, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.I2f, Operand: nil, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 2, SourceLine: 3}, + {Opcode: code.S2f, Operand: nil, SourceLine: 3}, + {Opcode: code.Fcmp, Operand: 1, SourceLine: 3}, + {Opcode: code.Jnm, Operand: 14, SourceLine: 3}, + {Opcode: code.Push, Operand: true, SourceLine: 3}, + {Opcode: code.Jmp, Operand: 15, SourceLine: 3}, + {Opcode: code.Push, Operand: false, SourceLine: 3}, + {Opcode: code.Jnm, Operand: 21, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 4}, + {Opcode: code.Dload, Operand: 0, SourceLine: 4}, + {Opcode: code.Inc, Operand: nil, SourceLine: 4}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, - {"set string", ` + { + name: "set string", source: ` text foo /(.*)/ { foo = $1 } -`, []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 9, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.Sset, nil, 3}, - {code.Setmatched, true, 2}, - }}, +`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 9, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.Sset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, + }}, { - "concat to text", ` + name: "concat to text", source: ` text foo /(?P.*)/ { foo += $v }`, - []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 12, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.Cat, nil, 3}, - {code.Sset, nil, 3}, - {code.Setmatched, true, 2}, + prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 12, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.Cat, Operand: nil, SourceLine: 3}, + {Opcode: code.Sset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }, }, - {"decrement", ` + { + name: "decrement", source: ` counter i // { i-- -}`, []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 7, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Dec, nil, 3}, - {code.Setmatched, true, 2}, - }}, - {"capref and settime", ` +}`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 7, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dec, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, + }}, + {name: "capref and settime", source: ` /(\d+)/ { settime($1) -}`, []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 8, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2i, nil, 2}, - {code.Settime, 1, 2}, - {code.Setmatched, true, 1}, +}`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 8, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2i, Operand: nil, SourceLine: 2}, + {Opcode: code.Settime, Operand: 1, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }}, - {"cast to self", ` + {name: "cast to self", source: ` /(\d+)/ { settime(int($1)) -}`, []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 8, 1}, - {code.Setmatched, false, 1}, - {code.Push, 0, 2}, - {code.Capref, 1, 2}, - {code.S2i, nil, 2}, - {code.Settime, 1, 2}, - {code.Setmatched, true, 1}, +}`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 8, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Push, Operand: 0, SourceLine: 2}, + {Opcode: code.Capref, Operand: 1, SourceLine: 2}, + {Opcode: code.S2i, Operand: nil, SourceLine: 2}, + {Opcode: code.Settime, Operand: 1, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }}, - {"stop", ` + {name: "stop", source: ` stop -`, []code.Instr{ - {code.Stop, nil, 1}, +`, prog: []code.Instr{ + {Opcode: code.Stop, Operand: nil, SourceLine: 1}, }}, - {"stop inside", ` + {name: "stop inside", source: ` // { stop } -`, []code.Instr{ - {code.Match, 0, 1}, - {code.Jnm, 5, 1}, - {code.Setmatched, false, 1}, - {code.Stop, nil, 2}, - {code.Setmatched, true, 1}, +`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 1}, + {Opcode: code.Jnm, Operand: 5, SourceLine: 1}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 1}, + {Opcode: code.Stop, Operand: nil, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 1}, }}, { - "nested decorators", - `def b { + name: "nested decorators", + source: `def b { def b { next } @@ -984,64 +986,64 @@ stop } } @b { -}`, nil, +}`, prog: nil, }, - {"negative numbers in capture groups", ` + {name: "negative numbers in capture groups", source: ` gauge foo /(?P-?\d+)/ { foo += $value_ms / 1000.0 -}`, []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 16, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.S2i, nil, 3}, - {code.I2f, nil, 3}, - {code.Push, 1000.0, 3}, - {code.Fdiv, nil, 3}, - {code.Fadd, nil, 3}, - {code.Fset, nil, 3}, - {code.Setmatched, true, 2}, +}`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 16, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.I2f, Operand: nil, SourceLine: 3}, + {Opcode: code.Push, Operand: 1000.0, SourceLine: 3}, + {Opcode: code.Fdiv, Operand: nil, SourceLine: 3}, + {Opcode: code.Fadd, Operand: nil, SourceLine: 3}, + {Opcode: code.Fset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }}, - {"substitution", ` + {name: "substitution", source: ` gauge foo /(\d+,\d)/ { foo = int(subst(",", "", $1)) -}`, []code.Instr{ - {code.Match, 0, 2}, - {code.Jnm, 13, 2}, - {code.Setmatched, false, 2}, - {code.Mload, 0, 3}, - {code.Dload, 0, 3}, - {code.Str, 0, 3}, - {code.Str, 1, 3}, - {code.Push, 0, 3}, - {code.Capref, 1, 3}, - {code.Subst, 3, 3}, - {code.S2i, nil, 3}, - {code.Iset, nil, 3}, - {code.Setmatched, true, 2}, +}`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 2}, + {Opcode: code.Jnm, Operand: 13, SourceLine: 2}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 2}, + {Opcode: code.Mload, Operand: 0, SourceLine: 3}, + {Opcode: code.Dload, Operand: 0, SourceLine: 3}, + {Opcode: code.Str, Operand: 0, SourceLine: 3}, + {Opcode: code.Str, Operand: 1, SourceLine: 3}, + {Opcode: code.Push, Operand: 0, SourceLine: 3}, + {Opcode: code.Capref, Operand: 1, SourceLine: 3}, + {Opcode: code.Subst, Operand: 3, SourceLine: 3}, + {Opcode: code.S2i, Operand: nil, SourceLine: 3}, + {Opcode: code.Iset, Operand: nil, SourceLine: 3}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 2}, }}, - {"const term as pattern", ` + {name: "const term as pattern", source: ` const A /n/ A && 1 { } -`, []code.Instr{ - {code.Match, 0, 0}, - {code.Jnm, 6, 0}, - {code.Push, int64(1), 2}, - {code.Jnm, 6, 0}, - {code.Push, true, 0}, - {code.Jmp, 7, 0}, - {code.Push, false, 0}, - {code.Jnm, 10, 0}, - {code.Setmatched, false, 0}, - {code.Setmatched, true, 0}, +`, prog: []code.Instr{ + {Opcode: code.Match, Operand: 0, SourceLine: 0}, + {Opcode: code.Jnm, Operand: 6, SourceLine: 0}, + {Opcode: code.Push, Operand: int64(1), SourceLine: 2}, + {Opcode: code.Jnm, Operand: 6, SourceLine: 0}, + {Opcode: code.Push, Operand: true, SourceLine: 0}, + {Opcode: code.Jmp, Operand: 7, SourceLine: 0}, + {Opcode: code.Push, Operand: false, SourceLine: 0}, + {Opcode: code.Jnm, Operand: 10, SourceLine: 0}, + {Opcode: code.Setmatched, Operand: false, SourceLine: 0}, + {Opcode: code.Setmatched, Operand: true, SourceLine: 0}, }}, } @@ -1090,10 +1092,10 @@ var testCodeGenASTs = []struct { }, }, prog: []code.Instr{ - {code.Str, 0, 0}, - {code.Str, 1, 0}, - {code.Str, 2, 0}, - {code.Subst, 3, 0}, + {Opcode: code.Str, Operand: 0, SourceLine: 0}, + {Opcode: code.Str, Operand: 1, SourceLine: 0}, + {Opcode: code.Str, Operand: 2, SourceLine: 0}, + {Opcode: code.Subst, Operand: 3, SourceLine: 0}, }, }, { @@ -1118,10 +1120,10 @@ var testCodeGenASTs = []struct { }, }, prog: []code.Instr{ - {code.Str, 0, 0}, - {code.Str, 1, 0}, - {code.Push, 0, 0}, - {code.Rsubst, 3, 0}, + {Opcode: code.Str, Operand: 0, SourceLine: 0}, + {Opcode: code.Str, Operand: 1, SourceLine: 0}, + {Opcode: code.Push, Operand: 0, SourceLine: 0}, + {Opcode: code.Rsubst, Operand: 3, SourceLine: 0}, }, }, } diff --git a/inputs/mtail/internal/runtime/compiler/errors/errors.go b/inputs/mtail/internal/runtime/compiler/errors/errors.go index 76882472..409c58a4 100644 --- a/inputs/mtail/internal/runtime/compiler/errors/errors.go +++ b/inputs/mtail/internal/runtime/compiler/errors/errors.go @@ -26,7 +26,7 @@ type ErrorList []*compileError // Add appends an error at a position to the list of errors. func (p *ErrorList) Add(pos *position.Position, msg string) { if pos == nil { - pos = &position.Position{"", -1, -1, -1} + pos = &position.Position{Line: -1, Startcol: -1, Endcol: -1} } *p = append(*p, &compileError{*pos, msg}) } diff --git a/inputs/mtail/internal/runtime/compiler/parser/lexer.go b/inputs/mtail/internal/runtime/compiler/parser/lexer.go index 07e31607..69571ffb 100644 --- a/inputs/mtail/internal/runtime/compiler/parser/lexer.go +++ b/inputs/mtail/internal/runtime/compiler/parser/lexer.go @@ -114,7 +114,7 @@ func (l *Lexer) NextToken() Token { // emit passes a token to the client. func (l *Lexer) emit(kind Kind) { - pos := position.Position{l.name, l.line, l.startcol, l.col - 1} + pos := position.Position{Filename: l.name, Line: l.line, Startcol: l.startcol, Endcol: l.col - 1} // glog.V(2).Infof("Emitting %v spelled %q at %v", kind, l.text.String(), pos) l.tokens <- Token{kind, l.text.String(), pos} // Reset the current token diff --git a/inputs/mtail/internal/runtime/compiler/parser/lexer_test.go b/inputs/mtail/internal/runtime/compiler/parser/lexer_test.go index ae53a792..d07368e2 100644 --- a/inputs/mtail/internal/runtime/compiler/parser/lexer_test.go +++ b/inputs/mtail/internal/runtime/compiler/parser/lexer_test.go @@ -18,257 +18,257 @@ type lexerTest struct { } var lexerTests = []lexerTest{ - {"empty", "", []Token{ - {EOF, "", position.Position{"empty", 0, 0, 0}}, + {name: "empty", tokens: []Token{ + {Kind: EOF, Pos: position.Position{Filename: "empty"}}, }}, - {"spaces", " \t", []Token{ - {EOF, "", position.Position{"spaces", 0, 2, 2}}, + {name: "spaces", input: " \t", tokens: []Token{ + {Kind: EOF, Pos: position.Position{Filename: "spaces", Startcol: 2, Endcol: 2}}, }}, - {"newlines", "\n", []Token{ - {NL, "\n", position.Position{"newlines", 1, 0, -1}}, - {EOF, "", position.Position{"newlines", 1, 0, 0}}, + {name: "newlines", input: "\n", tokens: []Token{ + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "newlines", Line: 1, Endcol: -1}}, + {Kind: EOF, Pos: position.Position{Filename: "newlines", Line: 1}}, }}, - {"comment", "# comment", []Token{ - {EOF, "", position.Position{"comment", 0, 9, 9}}, + {name: "comment", input: "# comment", tokens: []Token{ + {Kind: EOF, Pos: position.Position{Filename: "comment", Startcol: 9, Endcol: 9}}, }}, - {"comment not at col 1", " # comment", []Token{ - {EOF, "", position.Position{"comment not at col 1", 0, 11, 11}}, + {name: "comment not at col 1", input: " # comment", tokens: []Token{ + {Kind: EOF, Pos: position.Position{Filename: "comment not at col 1", Startcol: 11, Endcol: 11}}, }}, - {"punctuation", "{}()[],", []Token{ - {LCURLY, "{", position.Position{"punctuation", 0, 0, 0}}, - {RCURLY, "}", position.Position{"punctuation", 0, 1, 1}}, - {LPAREN, "(", position.Position{"punctuation", 0, 2, 2}}, - {RPAREN, ")", position.Position{"punctuation", 0, 3, 3}}, - {LSQUARE, "[", position.Position{"punctuation", 0, 4, 4}}, - {RSQUARE, "]", position.Position{"punctuation", 0, 5, 5}}, - {COMMA, ",", position.Position{"punctuation", 0, 6, 6}}, - {EOF, "", position.Position{"punctuation", 0, 7, 7}}, + {name: "punctuation", input: "{}()[],", tokens: []Token{ + {Kind: LCURLY, Spelling: "{", Pos: position.Position{Filename: "punctuation"}}, + {Kind: RCURLY, Spelling: "}", Pos: position.Position{Filename: "punctuation", Startcol: 1, Endcol: 1}}, + {Kind: LPAREN, Spelling: "(", Pos: position.Position{Filename: "punctuation", Startcol: 2, Endcol: 2}}, + {Kind: RPAREN, Spelling: ")", Pos: position.Position{Filename: "punctuation", Startcol: 3, Endcol: 3}}, + {Kind: LSQUARE, Spelling: "[", Pos: position.Position{Filename: "punctuation", Startcol: 4, Endcol: 4}}, + {Kind: RSQUARE, Spelling: "]", Pos: position.Position{Filename: "punctuation", Startcol: 5, Endcol: 5}}, + {Kind: COMMA, Spelling: ",", Pos: position.Position{Filename: "punctuation", Startcol: 6, Endcol: 6}}, + {Kind: EOF, Pos: position.Position{Filename: "punctuation", Startcol: 7, Endcol: 7}}, }}, - {"operators", "- + = ++ += < > <= >= == != * / << >> & | ^ ~ ** % || && =~ !~ --", []Token{ - {MINUS, "-", position.Position{"operators", 0, 0, 0}}, - {PLUS, "+", position.Position{"operators", 0, 2, 2}}, - {ASSIGN, "=", position.Position{"operators", 0, 4, 4}}, - {INC, "++", position.Position{"operators", 0, 6, 7}}, - {ADD_ASSIGN, "+=", position.Position{"operators", 0, 9, 10}}, - {LT, "<", position.Position{"operators", 0, 12, 12}}, - {GT, ">", position.Position{"operators", 0, 14, 14}}, - {LE, "<=", position.Position{"operators", 0, 16, 17}}, - {GE, ">=", position.Position{"operators", 0, 19, 20}}, - {EQ, "==", position.Position{"operators", 0, 22, 23}}, - {NE, "!=", position.Position{"operators", 0, 25, 26}}, - {MUL, "*", position.Position{"operators", 0, 28, 28}}, - {DIV, "/", position.Position{"operators", 0, 30, 30}}, - {SHL, "<<", position.Position{"operators", 0, 32, 33}}, - {SHR, ">>", position.Position{"operators", 0, 35, 36}}, - {BITAND, "&", position.Position{"operators", 0, 38, 38}}, - {BITOR, "|", position.Position{"operators", 0, 40, 40}}, - {XOR, "^", position.Position{"operators", 0, 42, 42}}, - {NOT, "~", position.Position{"operators", 0, 44, 44}}, - {POW, "**", position.Position{"operators", 0, 46, 47}}, - {MOD, "%", position.Position{"operators", 0, 49, 49}}, - {OR, "||", position.Position{"operators", 0, 51, 52}}, - {AND, "&&", position.Position{"operators", 0, 54, 55}}, - {MATCH, "=~", position.Position{"operators", 0, 57, 58}}, - {NOT_MATCH, "!~", position.Position{"operators", 0, 60, 61}}, - {DEC, "--", position.Position{"operators", 0, 63, 64}}, - {EOF, "", position.Position{"operators", 0, 65, 65}}, + {name: "operators", input: "- + = ++ += < > <= >= == != * / << >> & | ^ ~ ** % || && =~ !~ --", tokens: []Token{ + {Kind: MINUS, Spelling: "-", Pos: position.Position{Filename: "operators"}}, + {Kind: PLUS, Spelling: "+", Pos: position.Position{Filename: "operators", Startcol: 2, Endcol: 2}}, + {Kind: ASSIGN, Spelling: "=", Pos: position.Position{Filename: "operators", Startcol: 4, Endcol: 4}}, + {Kind: INC, Spelling: "++", Pos: position.Position{Filename: "operators", Startcol: 6, Endcol: 7}}, + {Kind: ADD_ASSIGN, Spelling: "+=", Pos: position.Position{Filename: "operators", Startcol: 9, Endcol: 10}}, + {Kind: LT, Spelling: "<", Pos: position.Position{Filename: "operators", Startcol: 12, Endcol: 12}}, + {Kind: GT, Spelling: ">", Pos: position.Position{Filename: "operators", Startcol: 14, Endcol: 14}}, + {Kind: LE, Spelling: "<=", Pos: position.Position{Filename: "operators", Startcol: 16, Endcol: 17}}, + {Kind: GE, Spelling: ">=", Pos: position.Position{Filename: "operators", Startcol: 19, Endcol: 20}}, + {Kind: EQ, Spelling: "==", Pos: position.Position{Filename: "operators", Startcol: 22, Endcol: 23}}, + {Kind: NE, Spelling: "!=", Pos: position.Position{Filename: "operators", Startcol: 25, Endcol: 26}}, + {Kind: MUL, Spelling: "*", Pos: position.Position{Filename: "operators", Startcol: 28, Endcol: 28}}, + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "operators", Startcol: 30, Endcol: 30}}, + {Kind: SHL, Spelling: "<<", Pos: position.Position{Filename: "operators", Startcol: 32, Endcol: 33}}, + {Kind: SHR, Spelling: ">>", Pos: position.Position{Filename: "operators", Startcol: 35, Endcol: 36}}, + {Kind: BITAND, Spelling: "&", Pos: position.Position{Filename: "operators", Startcol: 38, Endcol: 38}}, + {Kind: BITOR, Spelling: "|", Pos: position.Position{Filename: "operators", Startcol: 40, Endcol: 40}}, + {Kind: XOR, Spelling: "^", Pos: position.Position{Filename: "operators", Startcol: 42, Endcol: 42}}, + {Kind: NOT, Spelling: "~", Pos: position.Position{Filename: "operators", Startcol: 44, Endcol: 44}}, + {Kind: POW, Spelling: "**", Pos: position.Position{Filename: "operators", Startcol: 46, Endcol: 47}}, + {Kind: MOD, Spelling: "%", Pos: position.Position{Filename: "operators", Startcol: 49, Endcol: 49}}, + {Kind: OR, Spelling: "||", Pos: position.Position{Filename: "operators", Startcol: 51, Endcol: 52}}, + {Kind: AND, Spelling: "&&", Pos: position.Position{Filename: "operators", Startcol: 54, Endcol: 55}}, + {Kind: MATCH, Spelling: "=~", Pos: position.Position{Filename: "operators", Startcol: 57, Endcol: 58}}, + {Kind: NOT_MATCH, Spelling: "!~", Pos: position.Position{Filename: "operators", Startcol: 60, Endcol: 61}}, + {Kind: DEC, Spelling: "--", Pos: position.Position{Filename: "operators", Startcol: 63, Endcol: 64}}, + {Kind: EOF, Pos: position.Position{Filename: "operators", Startcol: 65, Endcol: 65}}, }}, { - "keywords", - "counter\ngauge\nas\nby\nhidden\ndef\nnext\nconst\ntimer\notherwise\nelse\ndel\ntext\nafter\nstop\nhistogram\nbuckets\n", - []Token{ - {COUNTER, "counter", position.Position{"keywords", 0, 0, 6}}, - {NL, "\n", position.Position{"keywords", 1, 7, -1}}, - {GAUGE, "gauge", position.Position{"keywords", 1, 0, 4}}, - {NL, "\n", position.Position{"keywords", 2, 5, -1}}, - {AS, "as", position.Position{"keywords", 2, 0, 1}}, - {NL, "\n", position.Position{"keywords", 3, 2, -1}}, - {BY, "by", position.Position{"keywords", 3, 0, 1}}, - {NL, "\n", position.Position{"keywords", 4, 2, -1}}, - {HIDDEN, "hidden", position.Position{"keywords", 4, 0, 5}}, - {NL, "\n", position.Position{"keywords", 5, 6, -1}}, - {DEF, "def", position.Position{"keywords", 5, 0, 2}}, - {NL, "\n", position.Position{"keywords", 6, 3, -1}}, - {NEXT, "next", position.Position{"keywords", 6, 0, 3}}, - {NL, "\n", position.Position{"keywords", 7, 4, -1}}, - {CONST, "const", position.Position{"keywords", 7, 0, 4}}, - {NL, "\n", position.Position{"keywords", 8, 5, -1}}, - {TIMER, "timer", position.Position{"keywords", 8, 0, 4}}, - {NL, "\n", position.Position{"keywords", 9, 5, -1}}, - {OTHERWISE, "otherwise", position.Position{"keywords", 9, 0, 8}}, - {NL, "\n", position.Position{"keywords", 10, 9, -1}}, - {ELSE, "else", position.Position{"keywords", 10, 0, 3}}, - {NL, "\n", position.Position{"keywords", 11, 4, -1}}, - {DEL, "del", position.Position{"keywords", 11, 0, 2}}, - {NL, "\n", position.Position{"keywords", 12, 3, -1}}, - {TEXT, "text", position.Position{"keywords", 12, 0, 3}}, - {NL, "\n", position.Position{"keywords", 13, 4, -1}}, - {AFTER, "after", position.Position{"keywords", 13, 0, 4}}, - {NL, "\n", position.Position{"keywords", 14, 5, -1}}, - {STOP, "stop", position.Position{"keywords", 14, 0, 3}}, - {NL, "\n", position.Position{"keywords", 15, 4, -1}}, - {HISTOGRAM, "histogram", position.Position{"keywords", 15, 0, 8}}, - {NL, "\n", position.Position{"keywords", 16, 9, -1}}, - {BUCKETS, "buckets", position.Position{"keywords", 16, 0, 6}}, - {NL, "\n", position.Position{"keywords", 17, 7, -1}}, - {EOF, "", position.Position{"keywords", 17, 0, 0}}, + name: "keywords", + input: "counter\ngauge\nas\nby\nhidden\ndef\nnext\nconst\ntimer\notherwise\nelse\ndel\ntext\nafter\nstop\nhistogram\nbuckets\n", + tokens: []Token{ + {Kind: COUNTER, Spelling: "counter", Pos: position.Position{Filename: "keywords", Endcol: 6}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 1, Startcol: 7, Endcol: -1}}, + {Kind: GAUGE, Spelling: "gauge", Pos: position.Position{Filename: "keywords", Line: 1, Endcol: 4}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 2, Startcol: 5, Endcol: -1}}, + {Kind: AS, Spelling: "as", Pos: position.Position{Filename: "keywords", Line: 2, Endcol: 1}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 3, Startcol: 2, Endcol: -1}}, + {Kind: BY, Spelling: "by", Pos: position.Position{Filename: "keywords", Line: 3, Endcol: 1}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 4, Startcol: 2, Endcol: -1}}, + {Kind: HIDDEN, Spelling: "hidden", Pos: position.Position{Filename: "keywords", Line: 4, Endcol: 5}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 5, Startcol: 6, Endcol: -1}}, + {Kind: DEF, Spelling: "def", Pos: position.Position{Filename: "keywords", Line: 5, Endcol: 2}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 6, Startcol: 3, Endcol: -1}}, + {Kind: NEXT, Spelling: "next", Pos: position.Position{Filename: "keywords", Line: 6, Endcol: 3}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 7, Startcol: 4, Endcol: -1}}, + {Kind: CONST, Spelling: "const", Pos: position.Position{Filename: "keywords", Line: 7, Endcol: 4}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 8, Startcol: 5, Endcol: -1}}, + {Kind: TIMER, Spelling: "timer", Pos: position.Position{Filename: "keywords", Line: 8, Endcol: 4}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 9, Startcol: 5, Endcol: -1}}, + {Kind: OTHERWISE, Spelling: "otherwise", Pos: position.Position{Filename: "keywords", Line: 9, Endcol: 8}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 10, Startcol: 9, Endcol: -1}}, + {Kind: ELSE, Spelling: "else", Pos: position.Position{Filename: "keywords", Line: 10, Endcol: 3}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 11, Startcol: 4, Endcol: -1}}, + {Kind: DEL, Spelling: "del", Pos: position.Position{Filename: "keywords", Line: 11, Endcol: 2}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 12, Startcol: 3, Endcol: -1}}, + {Kind: TEXT, Spelling: "text", Pos: position.Position{Filename: "keywords", Line: 12, Endcol: 3}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 13, Startcol: 4, Endcol: -1}}, + {Kind: AFTER, Spelling: "after", Pos: position.Position{Filename: "keywords", Line: 13, Endcol: 4}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 14, Startcol: 5, Endcol: -1}}, + {Kind: STOP, Spelling: "stop", Pos: position.Position{Filename: "keywords", Line: 14, Endcol: 3}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 15, Startcol: 4, Endcol: -1}}, + {Kind: HISTOGRAM, Spelling: "histogram", Pos: position.Position{Filename: "keywords", Line: 15, Endcol: 8}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 16, Startcol: 9, Endcol: -1}}, + {Kind: BUCKETS, Spelling: "buckets", Pos: position.Position{Filename: "keywords", Line: 16, Endcol: 6}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "keywords", Line: 17, Startcol: 7, Endcol: -1}}, + {Kind: EOF, Pos: position.Position{Filename: "keywords", Line: 17}}, }, }, { - "builtins", - "strptime\ntimestamp\ntolower\nlen\nstrtol\nsettime\ngetfilename\nint\nbool\nfloat\nstring\nsubst\n", - []Token{ - {BUILTIN, "strptime", position.Position{"builtins", 0, 0, 7}}, - {NL, "\n", position.Position{"builtins", 1, 8, -1}}, - {BUILTIN, "timestamp", position.Position{"builtins", 1, 0, 8}}, - {NL, "\n", position.Position{"builtins", 2, 9, -1}}, - {BUILTIN, "tolower", position.Position{"builtins", 2, 0, 6}}, - {NL, "\n", position.Position{"builtins", 3, 7, -1}}, - {BUILTIN, "len", position.Position{"builtins", 3, 0, 2}}, - {NL, "\n", position.Position{"builtins", 4, 3, -1}}, - {BUILTIN, "strtol", position.Position{"builtins", 4, 0, 5}}, - {NL, "\n", position.Position{"builtins", 5, 6, -1}}, - {BUILTIN, "settime", position.Position{"builtins", 5, 0, 6}}, - {NL, "\n", position.Position{"builtins", 6, 7, -1}}, - {BUILTIN, "getfilename", position.Position{"builtins", 6, 0, 10}}, - {NL, "\n", position.Position{"builtins", 7, 11, -1}}, - {BUILTIN, "int", position.Position{"builtins", 7, 0, 2}}, - {NL, "\n", position.Position{"builtins", 8, 3, -1}}, - {BUILTIN, "bool", position.Position{"builtins", 8, 0, 3}}, - {NL, "\n", position.Position{"builtins", 9, 4, -1}}, - {BUILTIN, "float", position.Position{"builtins", 9, 0, 4}}, - {NL, "\n", position.Position{"builtins", 10, 5, -1}}, - {BUILTIN, "string", position.Position{"builtins", 10, 0, 5}}, - {NL, "\n", position.Position{"builtins", 11, 6, -1}}, - {BUILTIN, "subst", position.Position{"builtins", 11, 0, 4}}, - {NL, "\n", position.Position{"builtins", 12, 5, -1}}, - {EOF, "", position.Position{"builtins", 12, 0, 0}}, + name: "builtins", + input: "strptime\ntimestamp\ntolower\nlen\nstrtol\nsettime\ngetfilename\nint\nbool\nfloat\nstring\nsubst\n", + tokens: []Token{ + {Kind: BUILTIN, Spelling: "strptime", Pos: position.Position{Filename: "builtins", Endcol: 7}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 1, Startcol: 8, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "timestamp", Pos: position.Position{Filename: "builtins", Line: 1, Endcol: 8}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 2, Startcol: 9, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "tolower", Pos: position.Position{Filename: "builtins", Line: 2, Endcol: 6}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 3, Startcol: 7, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "len", Pos: position.Position{Filename: "builtins", Line: 3, Endcol: 2}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 4, Startcol: 3, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "strtol", Pos: position.Position{Filename: "builtins", Line: 4, Endcol: 5}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 5, Startcol: 6, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "settime", Pos: position.Position{Filename: "builtins", Line: 5, Endcol: 6}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 6, Startcol: 7, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "getfilename", Pos: position.Position{Filename: "builtins", Line: 6, Endcol: 10}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 7, Startcol: 11, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "int", Pos: position.Position{Filename: "builtins", Line: 7, Endcol: 2}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 8, Startcol: 3, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "bool", Pos: position.Position{Filename: "builtins", Line: 8, Endcol: 3}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 9, Startcol: 4, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "float", Pos: position.Position{Filename: "builtins", Line: 9, Endcol: 4}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 10, Startcol: 5, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "string", Pos: position.Position{Filename: "builtins", Line: 10, Endcol: 5}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 11, Startcol: 6, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "subst", Pos: position.Position{Filename: "builtins", Line: 11, Endcol: 4}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "builtins", Line: 12, Startcol: 5, Endcol: -1}}, + {Kind: EOF, Pos: position.Position{Filename: "builtins", Line: 12}}, }, }, - {"numbers", "1 23 3.14 1.61.1 -1 -1.0 1h 0d 3d -1.5h 15m 24h0m0s 1e3 1e-3 .11 123.456e7", []Token{ - {INTLITERAL, "1", position.Position{"numbers", 0, 0, 0}}, - {INTLITERAL, "23", position.Position{"numbers", 0, 2, 3}}, - {FLOATLITERAL, "3.14", position.Position{"numbers", 0, 5, 8}}, - {FLOATLITERAL, "1.61", position.Position{"numbers", 0, 10, 13}}, - {FLOATLITERAL, ".1", position.Position{"numbers", 0, 14, 15}}, - {INTLITERAL, "-1", position.Position{"numbers", 0, 17, 18}}, - {FLOATLITERAL, "-1.0", position.Position{"numbers", 0, 20, 23}}, - {DURATIONLITERAL, "1h", position.Position{"numbers", 0, 25, 26}}, - {DURATIONLITERAL, "0d", position.Position{"numbers", 0, 28, 29}}, - {DURATIONLITERAL, "3d", position.Position{"numbers", 0, 31, 32}}, - {DURATIONLITERAL, "-1.5h", position.Position{"numbers", 0, 34, 38}}, - {DURATIONLITERAL, "15m", position.Position{"numbers", 0, 40, 42}}, - {DURATIONLITERAL, "24h0m0s", position.Position{"numbers", 0, 44, 50}}, - {FLOATLITERAL, "1e3", position.Position{"numbers", 0, 52, 54}}, - {FLOATLITERAL, "1e-3", position.Position{"numbers", 0, 56, 59}}, - {FLOATLITERAL, ".11", position.Position{"numbers", 0, 61, 63}}, - {FLOATLITERAL, "123.456e7", position.Position{"numbers", 0, 65, 73}}, - {EOF, "", position.Position{"numbers", 0, 74, 74}}, + {name: "numbers", input: "1 23 3.14 1.61.1 -1 -1.0 1h 0d 3d -1.5h 15m 24h0m0s 1e3 1e-3 .11 123.456e7", tokens: []Token{ + {Kind: INTLITERAL, Spelling: "1", Pos: position.Position{Filename: "numbers"}}, + {Kind: INTLITERAL, Spelling: "23", Pos: position.Position{Filename: "numbers", Startcol: 2, Endcol: 3}}, + {Kind: FLOATLITERAL, Spelling: "3.14", Pos: position.Position{Filename: "numbers", Startcol: 5, Endcol: 8}}, + {Kind: FLOATLITERAL, Spelling: "1.61", Pos: position.Position{Filename: "numbers", Startcol: 10, Endcol: 13}}, + {Kind: FLOATLITERAL, Spelling: ".1", Pos: position.Position{Filename: "numbers", Startcol: 14, Endcol: 15}}, + {Kind: INTLITERAL, Spelling: "-1", Pos: position.Position{Filename: "numbers", Startcol: 17, Endcol: 18}}, + {Kind: FLOATLITERAL, Spelling: "-1.0", Pos: position.Position{Filename: "numbers", Startcol: 20, Endcol: 23}}, + {Kind: DURATIONLITERAL, Spelling: "1h", Pos: position.Position{Filename: "numbers", Startcol: 25, Endcol: 26}}, + {Kind: DURATIONLITERAL, Spelling: "0d", Pos: position.Position{Filename: "numbers", Startcol: 28, Endcol: 29}}, + {Kind: DURATIONLITERAL, Spelling: "3d", Pos: position.Position{Filename: "numbers", Startcol: 31, Endcol: 32}}, + {Kind: DURATIONLITERAL, Spelling: "-1.5h", Pos: position.Position{Filename: "numbers", Startcol: 34, Endcol: 38}}, + {Kind: DURATIONLITERAL, Spelling: "15m", Pos: position.Position{Filename: "numbers", Startcol: 40, Endcol: 42}}, + {Kind: DURATIONLITERAL, Spelling: "24h0m0s", Pos: position.Position{Filename: "numbers", Startcol: 44, Endcol: 50}}, + {Kind: FLOATLITERAL, Spelling: "1e3", Pos: position.Position{Filename: "numbers", Startcol: 52, Endcol: 54}}, + {Kind: FLOATLITERAL, Spelling: "1e-3", Pos: position.Position{Filename: "numbers", Startcol: 56, Endcol: 59}}, + {Kind: FLOATLITERAL, Spelling: ".11", Pos: position.Position{Filename: "numbers", Startcol: 61, Endcol: 63}}, + {Kind: FLOATLITERAL, Spelling: "123.456e7", Pos: position.Position{Filename: "numbers", Startcol: 65, Endcol: 73}}, + {Kind: EOF, Pos: position.Position{Filename: "numbers", Startcol: 74, Endcol: 74}}, }}, - {"identifier", "a be foo\nquux lines_total", []Token{ - {ID, "a", position.Position{"identifier", 0, 0, 0}}, - {ID, "be", position.Position{"identifier", 0, 2, 3}}, - {ID, "foo", position.Position{"identifier", 0, 5, 7}}, - {NL, "\n", position.Position{"identifier", 1, 8, -1}}, - {ID, "quux", position.Position{"identifier", 1, 0, 3}}, - {ID, "lines_total", position.Position{"identifier", 1, 5, 15}}, - {EOF, "", position.Position{"identifier", 1, 16, 16}}, + {name: "identifier", input: "a be foo\nquux lines_total", tokens: []Token{ + {Kind: ID, Spelling: "a", Pos: position.Position{Filename: "identifier"}}, + {Kind: ID, Spelling: "be", Pos: position.Position{Filename: "identifier", Startcol: 2, Endcol: 3}}, + {Kind: ID, Spelling: "foo", Pos: position.Position{Filename: "identifier", Startcol: 5, Endcol: 7}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "identifier", Line: 1, Startcol: 8, Endcol: -1}}, + {Kind: ID, Spelling: "quux", Pos: position.Position{Filename: "identifier", Line: 1, Endcol: 3}}, + {Kind: ID, Spelling: "lines_total", Pos: position.Position{Filename: "identifier", Line: 1, Startcol: 5, Endcol: 15}}, + {Kind: EOF, Pos: position.Position{Filename: "identifier", Line: 1, Startcol: 16, Endcol: 16}}, }}, - {"regex", "/asdf/", []Token{ - {DIV, "/", position.Position{"regex", 0, 0, 0}}, - {REGEX, "asdf", position.Position{"regex", 0, 1, 4}}, - {DIV, "/", position.Position{"regex", 0, 5, 5}}, - {EOF, "", position.Position{"regex", 0, 6, 6}}, + {name: "regex", input: "/asdf/", tokens: []Token{ + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "regex"}}, + {Kind: REGEX, Spelling: "asdf", Pos: position.Position{Filename: "regex", Startcol: 1, Endcol: 4}}, + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "regex", Startcol: 5, Endcol: 5}}, + {Kind: EOF, Pos: position.Position{Filename: "regex", Startcol: 6, Endcol: 6}}, }}, - {"regex with escape", `/asdf\//`, []Token{ - {DIV, "/", position.Position{"regex with escape", 0, 0, 0}}, - {REGEX, `asdf/`, position.Position{"regex with escape", 0, 1, 6}}, - {DIV, "/", position.Position{"regex with escape", 0, 7, 7}}, - {EOF, "", position.Position{"regex with escape", 0, 8, 8}}, + {name: "regex with escape", input: `/asdf\//`, tokens: []Token{ + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "regex with escape"}}, + {Kind: REGEX, Spelling: `asdf/`, Pos: position.Position{Filename: "regex with escape", Startcol: 1, Endcol: 6}}, + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "regex with escape", Startcol: 7, Endcol: 7}}, + {Kind: EOF, Pos: position.Position{Filename: "regex with escape", Startcol: 8, Endcol: 8}}, }}, - {"regex with escape and special char", `/foo\d\//`, []Token{ - {DIV, "/", position.Position{"regex with escape and special char", 0, 0, 0}}, - {REGEX, `foo\d/`, position.Position{"regex with escape and special char", 0, 1, 7}}, - {DIV, "/", position.Position{"regex with escape and special char", 0, 8, 8}}, - {EOF, "", position.Position{"regex with escape and special char", 0, 9, 9}}, + {name: "regex with escape and special char", input: `/foo\d\//`, tokens: []Token{ + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "regex with escape and special char"}}, + {Kind: REGEX, Spelling: `foo\d/`, Pos: position.Position{Filename: "regex with escape and special char", Startcol: 1, Endcol: 7}}, + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "regex with escape and special char", Startcol: 8, Endcol: 8}}, + {Kind: EOF, Pos: position.Position{Filename: "regex with escape and special char", Startcol: 9, Endcol: 9}}, }}, - {"capref", "$foo $1", []Token{ - {CAPREF_NAMED, "foo", position.Position{"capref", 0, 0, 3}}, - {CAPREF, "1", position.Position{"capref", 0, 5, 6}}, - {EOF, "", position.Position{"capref", 0, 7, 7}}, + {name: "capref", input: "$foo $1", tokens: []Token{ + {Kind: CAPREF_NAMED, Spelling: "foo", Pos: position.Position{Filename: "capref", Endcol: 3}}, + {Kind: CAPREF, Spelling: "1", Pos: position.Position{Filename: "capref", Startcol: 5, Endcol: 6}}, + {Kind: EOF, Pos: position.Position{Filename: "capref", Startcol: 7, Endcol: 7}}, }}, - {"numerical capref", "$1", []Token{ - {CAPREF, "1", position.Position{"numerical capref", 0, 0, 1}}, - {EOF, "", position.Position{"numerical capref", 0, 2, 2}}, + {name: "numerical capref", input: "$1", tokens: []Token{ + {Kind: CAPREF, Spelling: "1", Pos: position.Position{Filename: "numerical capref", Endcol: 1}}, + {Kind: EOF, Pos: position.Position{Filename: "numerical capref", Startcol: 2, Endcol: 2}}, }}, - {"capref with trailing punc", "$foo,", []Token{ - {CAPREF_NAMED, "foo", position.Position{"capref with trailing punc", 0, 0, 3}}, - {COMMA, ",", position.Position{"capref with trailing punc", 0, 4, 4}}, - {EOF, "", position.Position{"capref with trailing punc", 0, 5, 5}}, + {name: "capref with trailing punc", input: "$foo,", tokens: []Token{ + {Kind: CAPREF_NAMED, Spelling: "foo", Pos: position.Position{Filename: "capref with trailing punc", Endcol: 3}}, + {Kind: COMMA, Spelling: ",", Pos: position.Position{Filename: "capref with trailing punc", Startcol: 4, Endcol: 4}}, + {Kind: EOF, Pos: position.Position{Filename: "capref with trailing punc", Startcol: 5, Endcol: 5}}, }}, - {"quoted string", `"asdf"`, []Token{ - {STRING, `asdf`, position.Position{"quoted string", 0, 0, 5}}, - {EOF, "", position.Position{"quoted string", 0, 6, 6}}, + {name: "quoted string", input: `"asdf"`, tokens: []Token{ + {Kind: STRING, Spelling: `asdf`, Pos: position.Position{Filename: "quoted string", Endcol: 5}}, + {Kind: EOF, Pos: position.Position{Filename: "quoted string", Startcol: 6, Endcol: 6}}, }}, - {"escaped quote in quoted string", `"\""`, []Token{ - {STRING, `"`, position.Position{"escaped quote in quoted string", 0, 0, 3}}, - {EOF, "", position.Position{"escaped quote in quoted string", 0, 4, 4}}, + {name: "escaped quote in quoted string", input: `"\""`, tokens: []Token{ + {Kind: STRING, Spelling: `"`, Pos: position.Position{Filename: "escaped quote in quoted string", Endcol: 3}}, + {Kind: EOF, Pos: position.Position{Filename: "escaped quote in quoted string", Startcol: 4, Endcol: 4}}, }}, - {"decorator", `@foo`, []Token{ - {DECO, "foo", position.Position{"decorator", 0, 0, 3}}, - {EOF, "", position.Position{"decorator", 0, 4, 4}}, + {name: "decorator", input: `@foo`, tokens: []Token{ + {Kind: DECO, Spelling: "foo", Pos: position.Position{Filename: "decorator", Endcol: 3}}, + {Kind: EOF, Pos: position.Position{Filename: "decorator", Startcol: 4, Endcol: 4}}, }}, { - "large program", - "/(?P[[:digit:]-\\/ ])/ {\n" + + name: "large program", + input: "/(?P[[:digit:]-\\/ ])/ {\n" + " strptime($date, \"%Y/%m/%d %H:%M:%S\")\n" + " foo++\n" + "}", - []Token{ - {DIV, "/", position.Position{"large program", 0, 0, 0}}, - {REGEX, "(?P[[:digit:]-/ ])", position.Position{"large program", 0, 1, 25}}, - {DIV, "/", position.Position{"large program", 0, 26, 26}}, - {LCURLY, "{", position.Position{"large program", 0, 28, 28}}, - {NL, "\n", position.Position{"large program", 1, 29, -1}}, - {BUILTIN, "strptime", position.Position{"large program", 1, 2, 9}}, - {LPAREN, "(", position.Position{"large program", 1, 10, 10}}, - {CAPREF_NAMED, "date", position.Position{"large program", 1, 11, 15}}, - {COMMA, ",", position.Position{"large program", 1, 16, 16}}, - {STRING, "%Y/%m/%d %H:%M:%S", position.Position{"large program", 1, 18, 36}}, - {RPAREN, ")", position.Position{"large program", 1, 37, 37}}, - {NL, "\n", position.Position{"large program", 2, 38, -1}}, - {ID, "foo", position.Position{"large program", 2, 2, 4}}, - {INC, "++", position.Position{"large program", 2, 5, 6}}, - {NL, "\n", position.Position{"large program", 3, 7, -1}}, - {RCURLY, "}", position.Position{"large program", 3, 0, 0}}, - {EOF, "", position.Position{"large program", 3, 1, 1}}, + tokens: []Token{ + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "large program"}}, + {Kind: REGEX, Spelling: "(?P[[:digit:]-/ ])", Pos: position.Position{Filename: "large program", Startcol: 1, Endcol: 25}}, + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "large program", Startcol: 26, Endcol: 26}}, + {Kind: LCURLY, Spelling: "{", Pos: position.Position{Filename: "large program", Startcol: 28, Endcol: 28}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 29, Endcol: -1}}, + {Kind: BUILTIN, Spelling: "strptime", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 2, Endcol: 9}}, + {Kind: LPAREN, Spelling: "(", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 10, Endcol: 10}}, + {Kind: CAPREF_NAMED, Spelling: "date", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 11, Endcol: 15}}, + {Kind: COMMA, Spelling: ",", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 16, Endcol: 16}}, + {Kind: STRING, Spelling: "%Y/%m/%d %H:%M:%S", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 18, Endcol: 36}}, + {Kind: RPAREN, Spelling: ")", Pos: position.Position{Filename: "large program", Line: 1, Startcol: 37, Endcol: 37}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "large program", Line: 2, Startcol: 38, Endcol: -1}}, + {Kind: ID, Spelling: "foo", Pos: position.Position{Filename: "large program", Line: 2, Startcol: 2, Endcol: 4}}, + {Kind: INC, Spelling: "++", Pos: position.Position{Filename: "large program", Line: 2, Startcol: 5, Endcol: 6}}, + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "large program", Line: 3, Startcol: 7, Endcol: -1}}, + {Kind: RCURLY, Spelling: "}", Pos: position.Position{Filename: "large program", Line: 3}}, + {Kind: EOF, Pos: position.Position{Filename: "large program", Line: 3, Startcol: 1, Endcol: 1}}, }, }, { - "linecount", - "# comment\n" + + name: "linecount", + input: "# comment\n" + "# blank line\n" + "\n" + "foo", - []Token{ - {NL, "\n", position.Position{"linecount", 3, 12, -1}}, - {ID, "foo", position.Position{"linecount", 3, 0, 2}}, - {EOF, "", position.Position{"linecount", 3, 3, 3}}, + tokens: []Token{ + {Kind: NL, Spelling: "\n", Pos: position.Position{Filename: "linecount", Line: 3, Startcol: 12, Endcol: -1}}, + {Kind: ID, Spelling: "foo", Pos: position.Position{Filename: "linecount", Line: 3, Endcol: 2}}, + {Kind: EOF, Pos: position.Position{Filename: "linecount", Line: 3, Startcol: 3, Endcol: 3}}, }, }, // errors - {"unexpected char", "?", []Token{ - {INVALID, "Unexpected input: '?'", position.Position{"unexpected char", 0, 0, 0}}, - {EOF, "", position.Position{"unexpected char", 0, 1, 1}}, + {name: "unexpected char", input: "?", tokens: []Token{ + {Kind: INVALID, Spelling: "Unexpected input: '?'", Pos: position.Position{Filename: "unexpected char"}}, + {Kind: EOF, Pos: position.Position{Filename: "unexpected char", Startcol: 1, Endcol: 1}}, }}, - {"unterminated regex", "/foo\n", []Token{ - {DIV, "/", position.Position{"unterminated regex", 0, 0, 0}}, - {INVALID, "Unterminated regular expression: \"/foo\"", position.Position{"unterminated regex", 0, 1, 3}}, - {EOF, "", position.Position{"unterminated regex", 0, 4, 4}}, + {name: "unterminated regex", input: "/foo\n", tokens: []Token{ + {Kind: DIV, Spelling: "/", Pos: position.Position{Filename: "unterminated regex"}}, + {Kind: INVALID, Spelling: "Unterminated regular expression: \"/foo\"", Pos: position.Position{Filename: "unterminated regex", Startcol: 1, Endcol: 3}}, + {Kind: EOF, Pos: position.Position{Filename: "unterminated regex", Startcol: 4, Endcol: 4}}, }}, - {"unterminated quoted string", "\"foo\n", []Token{ - {INVALID, "Unterminated quoted string: \"\\\"foo\"", position.Position{"unterminated quoted string", 0, 0, 3}}, - {EOF, "", position.Position{"unterminated quoted string", 0, 4, 4}}, + {name: "unterminated quoted string", input: "\"foo\n", tokens: []Token{ + {Kind: INVALID, Spelling: "Unterminated quoted string: \"\\\"foo\"", Pos: position.Position{Filename: "unterminated quoted string", Endcol: 3}}, + {Kind: EOF, Pos: position.Position{Filename: "unterminated quoted string", Startcol: 4, Endcol: 4}}, }}, } diff --git a/inputs/mtail/internal/runtime/compiler/parser/parser_test.go b/inputs/mtail/internal/runtime/compiler/parser/parser_test.go index df2b697d..e1c6eb51 100644 --- a/inputs/mtail/internal/runtime/compiler/parser/parser_test.go +++ b/inputs/mtail/internal/runtime/compiler/parser/parser_test.go @@ -617,27 +617,27 @@ var parsePositionTests = []struct { positions []*position.Position }{ { - "empty", - "", - nil, + name: "empty", + program: "", + positions: nil, }, { - "variable", - `counter foo`, - []*position.Position{{"variable", 0, 8, 10}}, + name: "variable", + program: `counter foo`, + positions: []*position.Position{{Filename: "variable", Line: 0, Startcol: 8, Endcol: 10}}, }, { - "pattern", - `const ID /foo/`, - []*position.Position{{"pattern", 0, 9, 13}}, + name: "pattern", + program: `const ID /foo/`, + positions: []*position.Position{{Filename: "pattern", Line: 0, Startcol: 9, Endcol: 13}}, }, { - "multiline regex", - "const ID\n" + + name: "multiline regex", + program: "const ID\n" + "/foo/ +\n" + "/bar/", // TODO: Update position for the first token to `1, 0, 4` when position tracking is fixed - []*position.Position{{"multiline regex", 1, 4, 4}, {"multiline regex", 2, 0, 4}}, + positions: []*position.Position{{Filename: "multiline regex", Line: 1, Startcol: 4, Endcol: 4}, {Filename: "multiline regex", Line: 2, Startcol: 0, Endcol: 4}}, }, } diff --git a/inputs/mtail/internal/runtime/vm/vm_test.go b/inputs/mtail/internal/runtime/vm/vm_test.go index c058e6d1..fc599ea2 100644 --- a/inputs/mtail/internal/runtime/vm/vm_test.go +++ b/inputs/mtail/internal/runtime/vm/vm_test.go @@ -27,565 +27,565 @@ var instructions = []struct { expectedThread thread }{ { - "match", - code.Instr{code.Match, 0, 0}, - []*regexp.Regexp{regexp.MustCompile("a*b")}, - []string{}, - []interface{}{}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{0: {"aaaab"}}}, - }, - { - "cmp lt", - code.Instr{code.Cmp, -1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1, "2"}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp eq", - code.Instr{code.Cmp, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"2", "2"}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp le", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, "2"}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp ne", - code.Instr{code.Cmp, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"1", "2"}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp ge", - code.Instr{code.Cmp, -1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 2}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt float float", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"2.0", "1.0"}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt float int", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"1.0", "2"}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt int float", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"1", "2.0"}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp eq string string false", - code.Instr{code.Cmp, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"abc", "def"}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp eq string string true", - code.Instr{code.Cmp, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"abc", "abc"}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt float float", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2.0, 1.0}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt float int", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cmp gt int float", - code.Instr{code.Cmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1, 2.0}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "jnm", - code.Instr{code.Jnm, 37, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{false}, - []interface{}{}, - thread{pc: 37, matches: map[int][]string{}}, - }, - { - "jm", - code.Instr{code.Jm, 37, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{false}, - []interface{}{}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "jmp", - code.Instr{code.Jmp, 37, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{}, - thread{pc: 37, matches: map[int][]string{}}, - }, - { - "strptime", - code.Instr{code.Strptime, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"2012/01/18 06:25:00", "2006/01/02 15:04:05"}, - []interface{}{}, - thread{ + name: "match", + i: code.Instr{Opcode: code.Match, Operand: 0}, + re: []*regexp.Regexp{regexp.MustCompile("a*b")}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{0: {"aaaab"}}}, + }, + { + name: "cmp lt", + i: code.Instr{Opcode: code.Cmp, Operand: -1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1, "2"}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp eq", + i: code.Instr{Opcode: code.Cmp, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"2", "2"}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp le", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, "2"}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp ne", + i: code.Instr{Opcode: code.Cmp, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"1", "2"}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp ge", + i: code.Instr{Opcode: code.Cmp, Operand: -1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 2}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt float float", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"2.0", "1.0"}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt float int", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"1.0", "2"}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt int float", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"1", "2.0"}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp eq string string false", + i: code.Instr{Opcode: code.Cmp, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"abc", "def"}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp eq string string true", + i: code.Instr{Opcode: code.Cmp, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"abc", "abc"}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt float float", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2.0, 1.0}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt float int", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cmp gt int float", + i: code.Instr{Opcode: code.Cmp, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1, 2.0}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "jnm", + i: code.Instr{Opcode: code.Jnm, Operand: 37}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{false}, + expectedStack: []interface{}{}, + expectedThread: thread{pc: 37, matches: map[int][]string{}}, + }, + { + name: "jm", + i: code.Instr{Opcode: code.Jm, Operand: 37}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{false}, + expectedStack: []interface{}{}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "jmp", + i: code.Instr{Opcode: code.Jmp, Operand: 37}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{}, + expectedThread: thread{pc: 37, matches: map[int][]string{}}, + }, + { + name: "strptime", + i: code.Instr{Opcode: code.Strptime, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"2012/01/18 06:25:00", "2006/01/02 15:04:05"}, + expectedStack: []interface{}{}, + expectedThread: thread{ pc: 0, time: time.Date(2012, 1, 18, 6, 25, 0, 0, time.UTC), matches: map[int][]string{}, }, }, { - "iadd", - code.Instr{code.Iadd, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(3)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "isub", - code.Instr{code.Isub, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(1)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "imul", - code.Instr{code.Imul, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(2)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "idiv", - code.Instr{code.Idiv, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{4, 2}, - []interface{}{int64(2)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "imod", - code.Instr{code.Imod, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{4, 2}, - []interface{}{int64(0)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "imod 2", - code.Instr{code.Imod, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{3, 2}, - []interface{}{int64(1)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "tolower", - code.Instr{code.Tolower, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"mIxeDCasE"}, - []interface{}{"mixedcase"}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "length", - code.Instr{code.Length, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"1234"}, - []interface{}{4}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "length 0", - code.Instr{code.Length, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{""}, - []interface{}{0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "shl", - code.Instr{code.Shl, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(4)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "shr", - code.Instr{code.Shr, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(1)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "and", - code.Instr{code.And, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(0)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "or", - code.Instr{code.Or, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(3)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "xor", - code.Instr{code.Xor, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 1}, - []interface{}{int64(3)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "xor 2", - code.Instr{code.Xor, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 3}, - []interface{}{int64(1)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "xor 3", - code.Instr{code.Xor, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{-1, 3}, - []interface{}{int64(^3)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "neg", - code.Instr{code.Neg, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{0}, - []interface{}{int64(-1)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "not", - code.Instr{code.Not, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{false}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "pow", - code.Instr{code.Ipow, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2, 2}, - []interface{}{int64(4)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "s2i pop", - code.Instr{code.S2i, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"ff", 16}, - []interface{}{int64(255)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "s2i", - code.Instr{code.S2i, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"190"}, - []interface{}{int64(190)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "s2f", - code.Instr{code.S2f, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"1.0"}, - []interface{}{float64(1.0)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "i2f", - code.Instr{code.I2f, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1}, - []interface{}{float64(1.0)}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "settime", - code.Instr{code.Settime, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{int64(0)}, - []interface{}{}, - thread{pc: 0, time: time.Unix(0, 0).UTC(), matches: map[int][]string{}}, - }, - { - "push int", - code.Instr{code.Push, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{1}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "push float", - code.Instr{code.Push, 1.0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{1.0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "setmatched false", - code.Instr{code.Setmatched, false, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{}, - thread{matched: false, pc: 0, matches: map[int][]string{}}, - }, - { - "setmatched true", - code.Instr{code.Setmatched, true, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{}, - thread{matched: true, pc: 0, matches: map[int][]string{}}, - }, - { - "otherwise", - code.Instr{code.Otherwise, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{true}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fadd", - code.Instr{code.Fadd, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2.0}, - []interface{}{3.0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fsub", - code.Instr{code.Fsub, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2.0}, - []interface{}{-1.0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fmul", - code.Instr{code.Fmul, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2.0}, - []interface{}{2.0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fdiv", - code.Instr{code.Fdiv, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2.0}, - []interface{}{0.5}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fmod", - code.Instr{code.Fmod, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2.0}, - []interface{}{1.0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fpow", - code.Instr{code.Fpow, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{2.0, 2.0}, - []interface{}{4.0}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "getfilename", - code.Instr{code.Getfilename, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{}, - []interface{}{testFilename}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "i2s", - code.Instr{code.I2s, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1}, - []interface{}{"1"}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "f2s", - code.Instr{code.F2s, nil, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{3.1}, - []interface{}{"3.1"}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "cat", - code.Instr{code.Cat, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"first", "second"}, - []interface{}{"firstsecond"}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "icmp gt false", - code.Instr{code.Icmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1, 2}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "fcmp gt false", - code.Instr{code.Fcmp, 1, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{1.0, 2.0}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "scmp eq false", - code.Instr{code.Scmp, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"abc", "def"}, - []interface{}{false}, - thread{pc: 0, matches: map[int][]string{}}, - }, - { - "subst", - code.Instr{code.Subst, 0, 0}, - []*regexp.Regexp{}, - []string{}, - []interface{}{"aa" /*old*/, "a" /*new*/, "caat"}, - []interface{}{"cat"}, - thread{pc: 0, matches: map[int][]string{}}, + name: "iadd", + i: code.Instr{Opcode: code.Iadd, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(3)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "isub", + i: code.Instr{Opcode: code.Isub, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(1)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "imul", + i: code.Instr{Opcode: code.Imul, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(2)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "idiv", + i: code.Instr{Opcode: code.Idiv, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{4, 2}, + expectedStack: []interface{}{int64(2)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "imod", + i: code.Instr{Opcode: code.Imod, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{4, 2}, + expectedStack: []interface{}{int64(0)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "imod 2", + i: code.Instr{Opcode: code.Imod, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{3, 2}, + expectedStack: []interface{}{int64(1)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "tolower", + i: code.Instr{Opcode: code.Tolower, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"mIxeDCasE"}, + expectedStack: []interface{}{"mixedcase"}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "length", + i: code.Instr{Opcode: code.Length, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"1234"}, + expectedStack: []interface{}{4}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "length 0", + i: code.Instr{Opcode: code.Length, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{""}, + expectedStack: []interface{}{0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "shl", + i: code.Instr{Opcode: code.Shl, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(4)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "shr", + i: code.Instr{Opcode: code.Shr, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(1)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "and", + i: code.Instr{Opcode: code.And, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(0)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "or", + i: code.Instr{Opcode: code.Or, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(3)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "xor", + i: code.Instr{Opcode: code.Xor, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 1}, + expectedStack: []interface{}{int64(3)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "xor 2", + i: code.Instr{Opcode: code.Xor, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 3}, + expectedStack: []interface{}{int64(1)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "xor 3", + i: code.Instr{Opcode: code.Xor, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{-1, 3}, + expectedStack: []interface{}{int64(^3)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "neg", + i: code.Instr{Opcode: code.Neg, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{0}, + expectedStack: []interface{}{int64(-1)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "not", + i: code.Instr{Opcode: code.Not, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{false}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "pow", + i: code.Instr{Opcode: code.Ipow, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2, 2}, + expectedStack: []interface{}{int64(4)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "s2i pop", + i: code.Instr{Opcode: code.S2i, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"ff", 16}, + expectedStack: []interface{}{int64(255)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "s2i", + i: code.Instr{Opcode: code.S2i}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"190"}, + expectedStack: []interface{}{int64(190)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "s2f", + i: code.Instr{Opcode: code.S2f}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"1.0"}, + expectedStack: []interface{}{float64(1.0)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "i2f", + i: code.Instr{Opcode: code.I2f}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1}, + expectedStack: []interface{}{float64(1.0)}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "settime", + i: code.Instr{Opcode: code.Settime, Operand: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{int64(0)}, + expectedStack: []interface{}{}, + expectedThread: thread{pc: 0, time: time.Unix(0, 0).UTC(), matches: map[int][]string{}}, + }, + { + name: "push int", + i: code.Instr{Opcode: code.Push, Operand: 1}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{1}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "push float", + i: code.Instr{Opcode: code.Push, Operand: 1.0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{1.0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "setmatched false", + i: code.Instr{Opcode: code.Setmatched, Operand: false}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{}, + expectedThread: thread{matched: false, pc: 0, matches: map[int][]string{}}, + }, + { + name: "setmatched true", + i: code.Instr{Opcode: code.Setmatched, Operand: true}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{}, + expectedThread: thread{matched: true, pc: 0, matches: map[int][]string{}}, + }, + { + name: "otherwise", + i: code.Instr{Opcode: code.Otherwise}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{true}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fadd", + i: code.Instr{Opcode: code.Fadd}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2.0}, + expectedStack: []interface{}{3.0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fsub", + i: code.Instr{Opcode: code.Fsub}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2.0}, + expectedStack: []interface{}{-1.0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fmul", + i: code.Instr{Opcode: code.Fmul}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2.0}, + expectedStack: []interface{}{2.0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fdiv", + i: code.Instr{Opcode: code.Fdiv}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2.0}, + expectedStack: []interface{}{0.5}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fmod", + i: code.Instr{Opcode: code.Fmod}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2.0}, + expectedStack: []interface{}{1.0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fpow", + i: code.Instr{Opcode: code.Fpow}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{2.0, 2.0}, + expectedStack: []interface{}{4.0}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "getfilename", + i: code.Instr{Opcode: code.Getfilename}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{}, + expectedStack: []interface{}{testFilename}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "i2s", + i: code.Instr{Opcode: code.I2s}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1}, + expectedStack: []interface{}{"1"}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "f2s", + i: code.Instr{Opcode: code.F2s}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{3.1}, + expectedStack: []interface{}{"3.1"}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "cat", + i: code.Instr{Opcode: code.Cat, Operand: 0, SourceLine: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"first", "second"}, + expectedStack: []interface{}{"firstsecond"}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "icmp gt false", + i: code.Instr{Opcode: code.Icmp, Operand: 1, SourceLine: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1, 2}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "fcmp gt false", + i: code.Instr{Opcode: code.Fcmp, Operand: 1, SourceLine: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{1.0, 2.0}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "scmp eq false", + i: code.Instr{Opcode: code.Scmp, Operand: 0, SourceLine: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"abc", "def"}, + expectedStack: []interface{}{false}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, + }, + { + name: "subst", + i: code.Instr{Opcode: code.Subst, Operand: 0, SourceLine: 0}, + re: []*regexp.Regexp{}, + str: []string{}, + reversedStack: []interface{}{"aa" /*old*/, "a" /*new*/, "caat"}, + expectedStack: []interface{}{"cat"}, + expectedThread: thread{pc: 0, matches: map[int][]string{}}, }, } @@ -661,7 +661,7 @@ func TestDatumSetInstrs(t *testing.T) { tests := []datumStoreTests{ { name: "simple inc", - i: code.Instr{code.Inc, nil, 0}, + i: code.Instr{Opcode: code.Inc}, d: 0, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -670,7 +670,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "inc by int", - i: code.Instr{code.Inc, 0, 0}, + i: code.Instr{Opcode: code.Inc, Operand: 0}, d: 0, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -680,7 +680,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "inc by str", - i: code.Instr{code.Inc, 0, 0}, + i: code.Instr{Opcode: code.Inc, Operand: 0}, d: 0, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -690,7 +690,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "iset", - i: code.Instr{code.Iset, nil, 0}, + i: code.Instr{Opcode: code.Iset}, d: 0, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -700,7 +700,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "iset str", - i: code.Instr{code.Iset, nil, 0}, + i: code.Instr{Opcode: code.Iset}, d: 0, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -710,7 +710,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "fset", - i: code.Instr{code.Fset, nil, 0}, + i: code.Instr{Opcode: code.Fset}, d: 1, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -720,7 +720,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "fset str", - i: code.Instr{code.Fset, nil, 0}, + i: code.Instr{Opcode: code.Fset}, d: 1, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -730,7 +730,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "sset", - i: code.Instr{code.Sset, nil, 0}, + i: code.Instr{Opcode: code.Sset}, d: 2, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -740,7 +740,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "dec", - i: code.Instr{code.Dec, nil, 0}, + i: code.Instr{Opcode: code.Dec}, d: 0, setup: func(t *thread, d datum.Datum) { datum.SetInt(d, 1, time.Now()) @@ -750,7 +750,7 @@ func TestDatumSetInstrs(t *testing.T) { }, { name: "set hist", - i: code.Instr{code.Fset, nil, 0}, + i: code.Instr{Opcode: code.Fset}, d: 3, setup: func(t *thread, d datum.Datum) { t.Push(d) @@ -782,7 +782,7 @@ func TestDatumSetInstrs(t *testing.T) { func TestStrptimeWithTimezone(t *testing.T) { loc, _ := time.LoadLocation("Europe/Berlin") - obj := &code.Object{Program: []code.Instr{{code.Strptime, 0, 0}}} + obj := &code.Object{Program: []code.Instr{{Opcode: code.Strptime, Operand: 0, SourceLine: 0}}} vm := New("strptimezone", obj, true, loc, false, false) vm.t = new(thread) vm.t.stack = make([]interface{}, 0) @@ -795,7 +795,7 @@ func TestStrptimeWithTimezone(t *testing.T) { } func TestStrptimeWithoutTimezone(t *testing.T) { - obj := &code.Object{Program: []code.Instr{{code.Strptime, 0, 0}}} + obj := &code.Object{Program: []code.Instr{{Opcode: code.Strptime, Operand: 0, SourceLine: 0}}} vm := New("strptimezone", obj, true, nil, false, false) vm.t = new(thread) vm.t.stack = make([]interface{}, 0) @@ -817,7 +817,7 @@ func TestDatumFetchInstrs(t *testing.T) { { // iget - v := makeVM(code.Instr{code.Iget, nil, 0}, m) + v := makeVM(code.Instr{Opcode: code.Iget}, m) d, err := m[0].GetDatum() testutil.FatalIfErr(t, err) datum.SetInt(d, 37, time.Now()) @@ -837,7 +837,7 @@ func TestDatumFetchInstrs(t *testing.T) { { // fget - v := makeVM(code.Instr{code.Fget, nil, 0}, m) + v := makeVM(code.Instr{Opcode: code.Fget}, m) d, err := m[1].GetDatum() testutil.FatalIfErr(t, err) datum.SetFloat(d, 12.1, time.Now()) @@ -857,7 +857,7 @@ func TestDatumFetchInstrs(t *testing.T) { { // sget - v := makeVM(code.Instr{code.Sget, nil, 0}, m) + v := makeVM(code.Instr{Opcode: code.Sget}, m) d, err := m[2].GetDatum() testutil.FatalIfErr(t, err) datum.SetString(d, "aba", time.Now()) @@ -885,7 +885,7 @@ func TestDeleteInstrs(t *testing.T) { _, err := m[0].GetDatum("z") testutil.FatalIfErr(t, err) - v := makeVM(code.Instr{code.Expire, 1, 0}, m) + v := makeVM(code.Instr{Opcode: code.Expire, Operand: 1}, m) v.t.Push(time.Hour) v.t.Push("z") v.t.Push(m[0]) @@ -905,7 +905,7 @@ func TestDeleteInstrs(t *testing.T) { func TestTimestampInstr(t *testing.T) { var m []*metrics.Metric now := time.Now().UTC() - v := makeVM(code.Instr{code.Timestamp, nil, 0}, m) + v := makeVM(code.Instr{Opcode: code.Timestamp}, m) v.execute(v.t, v.prog[0]) if v.terminate { t.Fatal("execution failed, see info log") diff --git a/inputs/mtail/internal/tailer/logstream/dgramstream_unix_test.go b/inputs/mtail/internal/tailer/logstream/dgramstream_unix_test.go index b9689994..37c82875 100644 --- a/inputs/mtail/internal/tailer/logstream/dgramstream_unix_test.go +++ b/inputs/mtail/internal/tailer/logstream/dgramstream_unix_test.go @@ -66,7 +66,7 @@ func TestDgramStreamReadCompletedBecauseSocketClosed(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), addr, "1"}, + {Context: context.TODO(), Filename: addr, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -119,7 +119,7 @@ func TestDgramStreamReadCompletedBecauseCancel(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), addr, "1"}, + {Context: context.TODO(), Filename: addr, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) diff --git a/inputs/mtail/internal/tailer/logstream/filestream_test.go b/inputs/mtail/internal/tailer/logstream/filestream_test.go index 9a8fd079..65a3c2f2 100644 --- a/inputs/mtail/internal/tailer/logstream/filestream_test.go +++ b/inputs/mtail/internal/tailer/logstream/filestream_test.go @@ -39,7 +39,7 @@ func TestFileStreamRead(t *testing.T) { close(lines) received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "yo"}, + {Context: context.TODO(), Filename: name, Line: "yo"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -80,7 +80,7 @@ func TestFileStreamReadNonSingleByteEnd(t *testing.T) { close(lines) received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, s}, + {Context: context.TODO(), Filename: name, Line: s}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -128,9 +128,9 @@ func TestFileStreamTruncation(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "1"}, - {context.TODO(), name, "2"}, - {context.TODO(), name, "3"}, + {Context: context.TODO(), Filename: name, Line: "1"}, + {Context: context.TODO(), Filename: name, Line: "2"}, + {Context: context.TODO(), Filename: name, Line: "3"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -164,7 +164,7 @@ func TestFileStreamFinishedBecauseCancel(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "yo"}, + {Context: context.TODO(), Filename: name, Line: "yo"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -205,7 +205,7 @@ func TestFileStreamPartialRead(t *testing.T) { close(lines) received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "yo"}, + {Context: context.TODO(), Filename: name, Line: "yo"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) diff --git a/inputs/mtail/internal/tailer/logstream/filestream_unix_test.go b/inputs/mtail/internal/tailer/logstream/filestream_unix_test.go index a446e9d3..6be978f3 100644 --- a/inputs/mtail/internal/tailer/logstream/filestream_unix_test.go +++ b/inputs/mtail/internal/tailer/logstream/filestream_unix_test.go @@ -68,8 +68,8 @@ func TestFileStreamRotation(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "1"}, - {context.TODO(), name, "2"}, + {Context: context.TODO(), Filename: name, Line: "1"}, + {Context: context.TODO(), Filename: name, Line: "2"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -101,7 +101,7 @@ func TestFileStreamURL(t *testing.T) { close(lines) received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "yo"}, + {Context: context.TODO(), Filename: name, Line: "yo"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) diff --git a/inputs/mtail/internal/tailer/logstream/pipestream_unix_test.go b/inputs/mtail/internal/tailer/logstream/pipestream_unix_test.go index 0fe6b059..46ea0021 100644 --- a/inputs/mtail/internal/tailer/logstream/pipestream_unix_test.go +++ b/inputs/mtail/internal/tailer/logstream/pipestream_unix_test.go @@ -55,7 +55,7 @@ func TestPipeStreamReadCompletedBecauseClosed(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "1"}, + {Context: context.TODO(), Filename: name, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -98,7 +98,7 @@ func TestPipeStreamReadCompletedBecauseCancel(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "1"}, + {Context: context.TODO(), Filename: name, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -136,7 +136,7 @@ func TestPipeStreamReadURL(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), name, "1"}, + {Context: context.TODO(), Filename: name, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) diff --git a/inputs/mtail/internal/tailer/logstream/socketstream_unix_test.go b/inputs/mtail/internal/tailer/logstream/socketstream_unix_test.go index 846e9b57..c91a509c 100644 --- a/inputs/mtail/internal/tailer/logstream/socketstream_unix_test.go +++ b/inputs/mtail/internal/tailer/logstream/socketstream_unix_test.go @@ -63,7 +63,7 @@ func TestSocketStreamReadCompletedBecauseSocketClosed(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), addr, "1"}, + {Context: context.TODO(), Filename: addr, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) @@ -115,7 +115,7 @@ func TestSocketStreamReadCompletedBecauseCancel(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.TODO(), addr, "1"}, + {Context: context.TODO(), Filename: addr, Line: "1"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) diff --git a/inputs/mtail/internal/tailer/tail_test.go b/inputs/mtail/internal/tailer/tail_test.go index 302d4325..2a5d5ffa 100644 --- a/inputs/mtail/internal/tailer/tail_test.go +++ b/inputs/mtail/internal/tailer/tail_test.go @@ -64,10 +64,10 @@ func TestHandleLogUpdate(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.Background(), logfile, "a"}, - {context.Background(), logfile, "b"}, - {context.Background(), logfile, "c"}, - {context.Background(), logfile, "d"}, + {Context: context.Background(), Filename: logfile, Line: "a"}, + {Context: context.Background(), Filename: logfile, Line: "b"}, + {Context: context.Background(), Filename: logfile, Line: "c"}, + {Context: context.Background(), Filename: logfile, Line: "d"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) } @@ -105,11 +105,11 @@ func TestHandleLogTruncate(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.Background(), logfile, "a"}, - {context.Background(), logfile, "b"}, - {context.Background(), logfile, "c"}, - {context.Background(), logfile, "d"}, - {context.Background(), logfile, "e"}, + {Context: context.Background(), Filename: logfile, Line: "a"}, + {Context: context.Background(), Filename: logfile, Line: "b"}, + {Context: context.Background(), Filename: logfile, Line: "c"}, + {Context: context.Background(), Filename: logfile, Line: "d"}, + {Context: context.Background(), Filename: logfile, Line: "e"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) } @@ -137,7 +137,7 @@ func TestHandleLogUpdatePartialLine(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.Background(), logfile, "ab"}, + {Context: context.Background(), Filename: logfile, Line: "ab"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) } @@ -167,7 +167,7 @@ func TestTailerUnreadableFile(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.Background(), logfile, ""}, + {Context: context.Background(), Filename: logfile, Line: ""}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) } @@ -232,8 +232,8 @@ func TestTailExpireStaleHandles(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.Background(), log1, "1"}, - {context.Background(), log2, "2"}, + {Context: context.Background(), Filename: log1, Line: "1"}, + {Context: context.Background(), Filename: log2, Line: "2"}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) diff --git a/inputs/mtail/internal/tailer/tail_unix_test.go b/inputs/mtail/internal/tailer/tail_unix_test.go index 862f19f8..551008e9 100644 --- a/inputs/mtail/internal/tailer/tail_unix_test.go +++ b/inputs/mtail/internal/tailer/tail_unix_test.go @@ -63,7 +63,7 @@ func TestTailerOpenRetries(t *testing.T) { received := testutil.LinesReceived(lines) expected := []*logline.LogLine{ - {context.Background(), logfile, ""}, + {Context: context.Background(), Filename: logfile, Line: ""}, } testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context")) } diff --git a/scripts/ci/go_version_check.sh b/scripts/ci/go_version_check.sh new file mode 100644 index 00000000..a2441ffa --- /dev/null +++ b/scripts/ci/go_version_check.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -eo pipefail + +function main () { + local -r required_version="1.21" # 设置所需的最低 Go 版本 + + local -r current_version=$(go version | awk '{print $3}') # 获取当前 Go 版本 + + if [[ "$(printf '%s\n' "$required_version" "$current_version" | sort -V | head -n1)" != "$required_version" ]]; then + >&2 echo "Error: Go version $required_version or higher is required, but found $current_version" + exit 1 + fi +} + +main \ No newline at end of file diff --git a/scripts/ci/go_vet.sh b/scripts/ci/go_vet.sh new file mode 100644 index 00000000..5a741d60 --- /dev/null +++ b/scripts/ci/go_vet.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +go list ./... | grep -vE "/inputs/mtail/internal/runtime/compiler/parser|pkg/otel/fanoutconsumer|pkg/otel/pipelines|agent/install|agent/update" | xargs go vet -tests=false \ No newline at end of file diff --git a/scripts/ci/static_check.sh b/scripts/ci/static_check.sh new file mode 100644 index 00000000..bee82fbf --- /dev/null +++ b/scripts/ci/static_check.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -e + +# static check docs: https://staticcheck.dev/docs/checks/ + +( +GOOS=linux go list ./... | xargs staticcheck -go=1.21 -tests=false -f binary +GOOS=darwin go list ./... | xargs staticcheck -go=1.21 -tests=false -f binary +) | staticcheck -merge -f=text | tee static-check.log +lines=$(cat static-check.log | wc -l) +rm -f static-check.log +if [[ $lines -eq 0 ]]; then + echo "static check pass" + exit 0 +else + echo "static check failed" + exit 1 +fi \ No newline at end of file