{"id":18696189,"url":"https://github.com/apitoolkit/doctests","last_synced_at":"2025-04-12T07:30:57.146Z","repository":{"id":37569162,"uuid":"505790340","full_name":"apitoolkit/doctests","owner":"apitoolkit","description":"Doctests: Test interactive Golang examples in your code comments","archived":false,"fork":false,"pushed_at":"2024-07-08T11:02:13.000Z","size":43,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-09T11:01:59.670Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apitoolkit.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-21T10:13:15.000Z","updated_at":"2024-07-25T19:46:40.000Z","dependencies_parsed_at":"2022-09-14T13:11:27.825Z","dependency_job_id":null,"html_url":"https://github.com/apitoolkit/doctests","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apitoolkit%2Fdoctests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apitoolkit%2Fdoctests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apitoolkit%2Fdoctests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apitoolkit%2Fdoctests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apitoolkit","download_url":"https://codeload.github.com/apitoolkit/doctests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248533590,"owners_count":21120125,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-07T11:17:28.387Z","updated_at":"2025-04-12T07:30:56.890Z","avatar_url":"https://github.com/apitoolkit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Doctests: Test interactive Golang examples in your code comments\n\n`doctest` is a tool that checks code examples and properties in Go comments.\nIt is similar in spirit to the [popular Python module with the same name](https://docs.python.org/3/library/doctest.html) and [Haskell library with same name](https://github.com/sol/doctest).\n\n## Getting Started\n\n\nhttps://github.com/apitoolkit/doctests/assets/6564482/e94dbbbf-224f-4c52-9ad6-36cc3767e645\n\n\n### Installation\n\nYou can install Doctests via go modules via:\n\n```go\ngo install github.com/apitoolkit/doctests@latest\n```\n\n### Setup Doctests in nvim/vim via lspconfig\n\nDoctest includes an lsp client, which is installed via the command above. \nBut to use it in your nvim editor, simply add the following code to your nvim lua config, to instruct your editor on how to use it. Note that this depends on the [lspconfig lua plugin](https://github.com/neovim/nvim-lspconfig).\n\n```lua\n\nlocal lspconfig = require 'lspconfig'\nlocal configs = require 'lspconfig.configs'\nlocal util = require 'lspconfig.util'\n\n-- Check if the config is already defined (useful when reloading this file)\nif not configs.doctests then\n configs.doctests = {\n   default_config = {\n     cmd = {'doctests', 'lsp'};\n     settings = {};\n     filetypes = { 'go', 'gomod', 'gotmpl' },\n     root_dir = function(fname)\n       return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname)\n     end,\n     single_file_support = true,\n   };\n }\nend\n\nlspconfig.doctests.setup{}\n\n```\n\n### Running Doctest from CI or command line\n\nThe easiest way to run a doctest is via the CLI. To execute Doctest in the current Directory, simply run the doctest command with no arguments in the given directory. \n\n```go\ndoctests\n```\n\nOr give it a path or list of file paths or filepath glob\n\n```go\ndoctests ./main.go\n```\nOR\n\n```go\ndoctests ./main.go ./abc.go\n```\nOR (For every file in a project tree) \n```go\ndoctests ./**/*.go\n```\n\n### Wrting Doctests\n\n`Doctest` comment lines always start with `// \u003e\u003e\u003e`. The 3 greater than signs allows Doctest to detect that those lines are to be executed. The result is always inserted into the next line.\n\n```go\npackage adder\n\n// Add adds two numbers\n// \u003e\u003e\u003e adder.Add(1, 2)\n// 3\nfunc Add(a int, b int) int {\n  return a+b\n}\n```\nNotice that it's important to include the package name when calling functions.\n\n## Contributors\n- Anthony Alaribe\n- Arne Wielding\n- Mohamed Nabil \n- Omar Ahmed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapitoolkit%2Fdoctests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapitoolkit%2Fdoctests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapitoolkit%2Fdoctests/lists"}