pax_global_header00006660000000000000000000000064147365672240014532gustar00rootroot0000000000000052 comment=a01170a978007125c8843f5231015d8e9c4d47be success-1.0.3/000077500000000000000000000000001473656722400132035ustar00rootroot00000000000000success-1.0.3/.devcontainer/000077500000000000000000000000001473656722400157425ustar00rootroot00000000000000success-1.0.3/.devcontainer/devcontainer.json000066400000000000000000000022231473656722400213150ustar00rootroot00000000000000{ "name": "success", "portsAttributes": { "6060": { "label": "success package documentation", "onAutoForward": "notify", "protocol": "http" } }, "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", "features": { "ghcr.io/thediveo/devcontainer-features/local-pkgsite:0": {}, "ghcr.io/thediveo/devcontainer-features/goreportcard:0": {}, "ghcr.io/thediveo/devcontainer-features/go-mod-upgrade:0": {}, "ghcr.io/thediveo/devcontainer-features/gocover:0": { "num-programs": "1", "race": true, "verbose": true, "html": true }, "ghcr.io/thediveo/devcontainer-features/pin-github-action:0": {} }, "remoteEnv": { "GOPATH": "/home/vscode/go", "PATH": "/home/vscode/go/bin:/go/bin:/usr/local/go/bin:${localEnv:PATH}" }, "customizations": { "vscode": { "extensions": [ "stkb.rewrap", "brunnerh.insert-unicode", "mhutchie.git-graph", "ms-vscode.makefile-tools" ] } } }success-1.0.3/.github/000077500000000000000000000000001473656722400145435ustar00rootroot00000000000000success-1.0.3/.github/workflows/000077500000000000000000000000001473656722400166005ustar00rootroot00000000000000success-1.0.3/.github/workflows/buildandtest.yaml000066400000000000000000000012701473656722400221460ustar00rootroot00000000000000name: build and test on: push: branches: - master pull_request: branches: - master - develop jobs: buildandtest: name: Build and Test on Go ${{matrix.go}} runs-on: ubuntu-latest strategy: matrix: go: [ 'stable', 'oldstable' ] steps: - name: Set up Go ${{matrix.go}} uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # pin@v5 with: go-version: ${{matrix.go}} id: go - name: Check out code into the Go module directory uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4 - name: Test Go packages run: go test -v -p 1 -race ./... success-1.0.3/.github/workflows/codeql-analysis.yaml000066400000000000000000000021121473656722400225500ustar00rootroot00000000000000name: "CodeQL" on: push: branches: - master pull_request: branches: - master - develop schedule: - cron: '21 14 * * 1' jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read # for github/codeql-action/init to get workflow details contents: read # for actions/checkout to fetch code security-events: write # for github/codeql-action/analyze to upload SARIF results strategy: fail-fast: false matrix: language: [ 'go' ] steps: - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4 - name: Initialize CodeQL uses: github/codeql-action/init@673cceb2b4886e2dfff697ab64a1ecd1c0a14a05 # pin@v2 with: languages: ${{ matrix.language }} - name: Autobuild uses: github/codeql-action/autobuild@673cceb2b4886e2dfff697ab64a1ecd1c0a14a05 # pin@v2 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@673cceb2b4886e2dfff697ab64a1ecd1c0a14a05 # pin@v2 success-1.0.3/.gitignore000066400000000000000000000000651473656722400151740ustar00rootroot00000000000000__debug_bin .vscode/*.log coverage.out coverage.html success-1.0.3/LICENSE000066400000000000000000000236751473656722400142250ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS success-1.0.3/Makefile000066400000000000000000000011671473656722400146500ustar00rootroot00000000000000.PHONY: help clean coverage report test help: ## list available targets @# Shamelessly stolen from Gomega's Makefile @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}' clean: ## cleans up build and testing artefacts rm -f coverage.* test: ## run unit tests go test -v -p=1 -race ./... report: ## run goreportcard-cli on this module # from ghcr.io/thediveo/devcontainer-features/goreportcard goreportcard-cli -v ./.. coverage: ## gathers coverage and updates README badge # from ghcr.io/thediveo/devcontainer-features/gocover gocover success-1.0.3/README.md000066400000000000000000000036231473656722400144660ustar00rootroot00000000000000# `success` [![Go Reference](https://pkg.go.dev/badge/github.com/thediveo/success.svg)](https://pkg.go.dev/github.com/thediveo/success) ![GitHub](https://img.shields.io/github/license/thediveo/success) ![build and test](https://github.com/TheDiveO/success/actions/workflows/buildandtest.yaml/badge.svg?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/thediveo/success)](https://goreportcard.com/report/github.com/thediveo/success) ![Coverage](https://img.shields.io/badge/Coverage-100.0%25-brightgreen) This tiny Go module improves your testing feng shui tremendiously by shimming in Gomega error detection whenever trying to be `Successful()`. All your software will immediately look so much better by importing success! For devcontainer instructions, please see the [section "DevContainer" below](#devcontainer). #### Before ```go sekret, err := Foo(42) Expect(err).NotTo(HaveOccured()) ``` #### After ```go // You might want to dot-import for convenience. import . "github.com/thediveo/success" sekret := Successful(Foo(42)) // analogous... sekret, moresekret := Successful2R(Bar(12345)) sekret, moresekret, nosekretanymore := Successful3R(Baz()) ``` ## DevContainer > [!CAUTION] > > Do **not** use VSCode's "~~Dev Containers: Clone Repository in Container > Volume~~" command, as it is utterly broken by design, ignoring > `.devcontainer/devcontainer.json`. 1. `git clone https://github.com/thediveo/enumflag` 2. in VSCode: Ctrl+Shift+P, "Dev Containers: Open Workspace in Container..." 3. select `enumflag.code-workspace` and off you go... ## Go Version Support `success` supports versions of Go that are noted by the [Go release policy](https://golang.org/doc/devel/release.html#policy), that is, major versions _N_ and _N_-1 (where _N_ is the current major version). ## Copyright and License `success` is Copyright 2023 Harald Albrecht, and licensed under the Apache License, Version 2.0. success-1.0.3/doc.go000066400000000000000000000002361473656722400143000ustar00rootroot00000000000000/* Package success improves your testing feng shui tremendiously by shimming in Gomega error detection whenever trying to be Successful(). */ package success success-1.0.3/go.mod000066400000000000000000000010411473656722400143050ustar00rootroot00000000000000module github.com/thediveo/success go 1.22.0 require ( github.com/onsi/ginkgo/v2 v2.22.2 github.com/onsi/gomega v1.36.2 ) require ( github.com/go-logr/logr v1.4.2 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/tools v0.28.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) success-1.0.3/go.sum000066400000000000000000000052701473656722400143420ustar00rootroot00000000000000github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU= github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk= github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= success-1.0.3/success.code-workspace000066400000000000000000000000741473656722400175040ustar00rootroot00000000000000{ "folders": [ { "path": "." } ], "settings": {} }success-1.0.3/success.go000066400000000000000000000032551473656722400152070ustar00rootroot00000000000000// Copyright 2023 Harald Albrecht. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package success import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) // Successful takes a return value together with an error return value, // returning only the value (without the error return value) and at the same // time asserting that the error return value is nil. func Successful[R any](r R, err error) R { GinkgoHelper() Expect(err).NotTo(HaveOccurred()) return r } // Successful2R takes two return values together with an error return value, // returning only both value (without the error return value) and at the same // time asserting that the error return value is nil. func Successful2R[R1 any, R2 any](r1 R1, r2 R2, err error) (R1, R2) { GinkgoHelper() Expect(err).NotTo(HaveOccurred()) return r1, r2 } // Successful2R takes two return values together with an error return value, // returning only both value (without the error return value) and at the same // time asserting that the error return value is nil. func Successful3R[R1 any, R2 any, R3 any](r1 R1, r2 R2, r3 R3, err error) (R1, R2, R3) { GinkgoHelper() Expect(err).NotTo(HaveOccurred()) return r1, r2, r3 } success-1.0.3/success_test.go000066400000000000000000000037741473656722400162540ustar00rootroot00000000000000// Copyright 2023 Harald Albrecht. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package success import ( "errors" "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) func TestSuccess(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "success package") } var _ = Describe("ensuring success", func() { It("bails out where there is no success", func() { msgs := InterceptGomegaFailures(func() { _ = Successful(func() (int, error) { return 0, errors.New("D'OH!") }()) }) Expect(msgs).To(ConsistOf(MatchRegexp(`(?s)Unexpected error:.*D'OH!`))) msgs = InterceptGomegaFailures(func() { _, _ = Successful2R(func() (int, string, error) { return 0, "uhoh", errors.New("D'OH!") }()) }) Expect(msgs).To(ConsistOf(MatchRegexp(`(?s)Unexpected error:.*D'OH!`))) msgs = InterceptGomegaFailures(func() { _, _, _ = Successful3R(func() (int, string, bool, error) { return 0, "", false, errors.New("D'OH!") }()) }) Expect(msgs).To(ConsistOf(MatchRegexp(`(?s)Unexpected error:.*D'OH!`))) }) It("succeeds", func() { answer := Successful(func() (int, error) { return 42, nil }()) Expect(answer).To(Equal(42)) answer, answer2 := Successful2R(func() (int, string, error) { return 42, "foo", nil }()) Expect(answer).To(Equal(42)) Expect(answer2).To(Equal("foo")) answer, answer2, answer3 := Successful3R(func() (int, string, bool, error) { return 42, "foo", true, nil }()) Expect(answer).To(Equal(42)) Expect(answer2).To(Equal("foo")) Expect(answer3).To(BeTrue()) }) })