{"id":40843241,"url":"https://github.com/pierrre/assert","last_synced_at":"2026-01-21T23:08:35.402Z","repository":{"id":65518406,"uuid":"580457369","full_name":"pierrre/assert","owner":"pierrre","description":"Go test assertion library","archived":false,"fork":false,"pushed_at":"2026-01-12T16:30:22.000Z","size":389,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T21:59:22.131Z","etag":null,"topics":["assertions","go","golang","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pierrre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-20T15:57:04.000Z","updated_at":"2026-01-12T16:30:26.000Z","dependencies_parsed_at":"2023-02-15T01:47:01.176Z","dependency_job_id":"5c95e048-6b42-4eac-9409-7fd9a1bd7b76","html_url":"https://github.com/pierrre/assert","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.19354838709677424","last_synced_commit":"0d70be1fe754d1b202e0d96238d795069ee2868d"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"purl":"pkg:github/pierrre/assert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierrre%2Fassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierrre%2Fassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierrre%2Fassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierrre%2Fassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pierrre","download_url":"https://codeload.github.com/pierrre/assert/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierrre%2Fassert/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28646754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T21:29:11.980Z","status":"ssl_error","status_checked_at":"2026-01-21T21:24:31.872Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assertions","go","golang","testing"],"created_at":"2026-01-21T23:08:35.312Z","updated_at":"2026-01-21T23:08:35.396Z","avatar_url":"https://github.com/pierrre.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assert\n\nGo test assertion library.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/pierrre/assert.svg)](https://pkg.go.dev/github.com/pierrre/assert)\n\n## Features\n\n- [Test assertion (equal, comparison, nil, empty, length, error, etc...)](#assertions)\n- [No reflection (uses generics)](#why-)\n- [Customization (print and compare values)](#customization)\n\n## Assertions\n\nA simple assertion:\n\n```go\nassert.Equal(t, value, 1)\n```\n\nBy default, assertions fail with `Fatal()`.\nIt can be changed with the `Report()` option:\n\n```go\nassert.Equal(t, value, 1, assert.Report(t.Error))\n```\n\nThe report message can be customized:\n\n```go\nassert.Equal(t, value, 1, assert.MessageWrap(\"test\"))\n```\n\n## Why ?\n\nThis assertion library is an experiment to see if it is possible to do better than `github.com/stretchr/testify`, by using generics.\n\nHere is an example of an issue with `github.com/stretchr/testify`:\n\n```go\nfunc Test(t *testing.T) {\n    value := getValue()\n    require.Equal(t, 1, value)\n}\n\nfunc getValue() int64 {\n    return 1\n}\n```\n\nSurprinsingly, this test fails with this error:\n\n```text\nError: Not equal:\nexpected: int(1)\nactual  : int64(1)\n```\n\nThis issue is caused by the types, which are no identical (the `1` constant is an `int` and not an `int64`), and it's possible to fix it:\n\nConvert the value to `int64`:\n\n```go\nrequire.Equal(t, int64(1), value)\n```\n\nUse `EqualValues()` which converts the values to the same type:\n\n```go\nrequire.EqualValues(t, 1, value)\n```\n\nBut the internal implementation is not simple: it requires [heavy usage of reflection](https://github.com/stretchr/testify/blob/master/assert/assertion_compare.go), and the code is [quite complex](https://github.com/stretchr/testify/blob/master/assert/assertions.go).\n\nWhat if we could simply use the `==` operator ?\nThis is the solution chosen by this library.\nIt uses generics to do the comparison, and it works with any comparable type:\n\n```go\nfunc Equal[T comparable](tb testing.TB, v1, v2 T, opts ...Option) bool {\n    tb.Helper()\n    ok := v1 == v2\n    if !ok {\n        Fail(...)\n    }\n    return ok\n}\n```\n\n```go\nassert.Equal(t, 1, value)\n```\n\nThe constant `1` is automatically converted to the type of the `value` variable without using reflection.\n\nHowever, this approchach has a limitation: it requires to write a different assertion function for each \"kind\" (map, slice, etc...)\n\n## Customization\n\nThe default behavior can be customized:\n\n- [`DeepEqualer`](https://pkg.go.dev/github.com/pierrre/assert#DeepEqualer) allows to customize how values are compared with [`DeepEqual()`](https://pkg.go.dev/github.com/pierrre/assert#DeepEqual).\n- [`ValueStringer`](https://pkg.go.dev/github.com/pierrre/assert#ValueStringer) allows to customize how values are printed.\n- [`ErrorStringer`](https://pkg.go.dev/github.com/pierrre/assert#ErrorStringer) allows to customize how errors are printed.\n\n## FAQ\n\n### Why not use `github.com/stretchr/testify` ?\n\nI think it's a great library, but I wanted to [try something different](#why-).\nI also wanted to try generics, and to see if it was possible to make an assertion library without reflection.\n\n### Where are `Nil()` and `NotNil()` ?\n\n- For slices use [SliceNil()](https://pkg.go.dev/github.com/pierrre/assert#SliceNil) and [SliceNotNil()](https://pkg.go.dev/github.com/pierrre/assert#SliceNotNil)\n- For maps use [MapNil()](https://pkg.go.dev/github.com/pierrre/assert#MapNil) and [MapNotNil()](https://pkg.go.dev/github.com/pierrre/assert#MapNotNil)\n- For comparable types use [Zero()](https://pkg.go.dev/github.com/pierrre/assert#Zero) and [NotZero()](https://pkg.go.dev/github.com/pierrre/assert#NotZero)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpierrre%2Fassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpierrre%2Fassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpierrre%2Fassert/lists"}