GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Is there any way to make our example code in docstrings part of the test suite? · Issue #598 · googleapis/google-cloud-node

Is there any way to make our example code in docstrings part of the test suite? #598

New issue
Copy link
New issue
Copy link
Closed
#627
Closed
Is there any way to make our example code in docstrings part of the test suite?#598
#627
Copy link
Assignees
stephenplusplus
Labels
type: questionRequest for information or clarification. Not an issue.
Milestone
Core Future

Description

@jgeewax
jgeewax
opened on May 14, 2015
Issue body actions

I'm worried about code rot and typos -- is there any way we can make it so that the snippets we have are actually tested ? Could we pull them out of a unit test somewhere? or a test suite that is specifically samples and we load based on an ID of sorts?

Activity

Next
  1. jgeewax
    added
    type: questionRequest for information or clarification. Not an issue.
    docs
    on May 14, 2015
  2. jgeewax
    added this to the Core Future milestone on May 14, 2015
  3. jgeewax
    added
    testing
    on May 14, 2015
  4. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    We don't have assertions in our code examples and we probably shouldn't. This would make our examples gross. If they want examples that definitely work and have assertions, they can look at the tests. :)

  5. jgeewax commented on May 14, 2015

    @jgeewax
    jgeewax
    on May 14, 2015
    ContributorAuthor
    More actions

    We don't have assertions in our code examples and we probably shouldn't.

    Maybe we could put asserts in there and strip them out as part of populating the examples?

    If they want examples that definitely work and have assertions, they can look at the tests. :)

    That seems kind of crappy... I think we owe users of the library examples that work... :(

  6. brendandburns commented on May 14, 2015

    @brendandburns
    brendandburns
    on May 14, 2015
    More actions

    In kubernetes open source, we explicitly have a unit test that scrapes all
    of our docs looking for examples like this and making sure that they still
    work.

    It's 100% do-able, and I think we should prioritize it. The number of out
    of date examples, when I was initially learning the Google Cloud Platform
    was really bad.

    Brendan
    On May 14, 2015 2:12 PM, "JJ Geewax" [email protected] wrote:

    We don't have assertions in our code examples and we probably shouldn't.

    Maybe we could put asserts in there and strip them out as part of
    populating the examples?

    If they want examples that definitely work and have assertions, they can
    look at the tests. :)

    That seems kind of crappy... I think we owe users of the library examples
    that work... :(

    —
    Reply to this email directly or view it on GitHub
    #598 (comment)
    .

  7. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    Personally, I don't like the idea of docs and tests being so closely linked. We talk to computers with tests, we talk to humans with docs. I like the flexibility that our docs give us and the ability to be clear and concise. If we change this, our examples need to be as verbose as our tests in which case, why don't we just scrap the examples and copy and paste our tests into the docs?

    I do understand the appeal, don't get me wrong, so if we can make this not as painful as I envision it, then I'd be happy to explore the idea.

    @brendandburns can you link me to code on how this is done in kubernetes?

    As an aside, I think our developers.google.com docs are always out of date. :( The struggle is so real.

  8. jgeewax commented on May 14, 2015

    @jgeewax
    jgeewax
    on May 14, 2015
    ContributorAuthor
    More actions

    If we change this, our examples need to be as verbose as our tests

    To be more clear: I'm not saying our docs need to be as verbose as tests. I'm saying that they need to work -- always.

    I'd really love it if we had a check at pull-request time to make sure all the examples still work... How we do this is in the air, but the goal is that if I were to check in a typo, Travis would reject it...

    As an aside, I think our developers.google.com docs are always out of date. :( The struggle is so real.

    And it sucks. Big time. This is just adding fuel to the fire of "let's make sure our examples work..."

  9. brendandburns commented on May 14, 2015

    @brendandburns
    brendandburns
    on May 14, 2015
    More actions

    Here is the code:

    https://github.com/GoogleCloudPlatform/kubernetes/blob/master/examples/examples_test.go

    The basic approach is:

    • Scrape through the docs, look for things that start with ```
    • Try and extract that thingy
    • Try to parse that data object into a sensible object
    • Validate with a rule in the test that indicates what the object
      should be.

    Concretely for developers.google.com, I think this would look like, writing
    a unit test for each API, that scrapes through the relevant
    developer.google.com content, extracts source code, and attempts to compile
    it using the appropriate library. That way, if a developer modifies
    something that breaks the example, they have to fix the docs as well as
    the change their making.

    A different option would be to figure out a way to automatically include
    the source code from original source files, if you do that, then you can
    just write traditional unit tests that live alongside the example source
    files.

    On Thu, May 14, 2015 at 2:39 PM, JJ Geewax [email protected] wrote:

    If we change this, our examples need to be as verbose as our tests

    To be more clear: I'm not saying our docs need to be as verbose as tests.
    I'm saying that they need to work -- always.

    I'd really love it if we had a check at pull-request time to make sure all
    the examples still work... How we do this is in the air, but the goal is
    that if I were to check in a typo, Travis would reject it...

    As an aside, I think our developers.google.com docs are always out of
    date. :( The struggle is so real.

    And it sucks. Big time. This is just adding fuel to the fire of "let's
    make sure our examples work..."

    —
    Reply to this email directly or view it on GitHub
    #598 (comment)
    .

  10. tmatsuo commented on May 14, 2015

    @tmatsuo
    tmatsuo
    on May 14, 2015
    Contributor
    More actions

    @elibixby

    FYI, for cloud.google.com (cloud instance of developers.google.com) sample code, we will go to the latter option.

  11. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    Like thinking hypothetically, we should just split each line and run it through the node REPL. If it doesn't throw up somewhere along the way, good2go?

  12. jgeewax commented on May 14, 2015

    @jgeewax
    jgeewax
    on May 14, 2015
    ContributorAuthor
    More actions

    You mean all the lines as a whole right? Ie, this should fail:

    var gcloud = require('gcloud');
    var dataset = gcloud.datastore.dataset();
    dataset.save({
      key: datastore.key('Company'),
      data: {name: 'Google'}
    });
  13. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    Oh yeah sorry, it's too early. That sounds reasonable yes?

  14. jgeewax commented on May 14, 2015

    @jgeewax
    jgeewax
    on May 14, 2015
    ContributorAuthor
    More actions

    If the snippet runs successfully, that's a good thing...

    I think it's safe to assume that the methods we're calling work as expected, and are tested to do so in a unit test. So the following "test" wouldn't be in the docs:

    var key = dataset.key('Company');
    assert(key.path[0] == 'Company');

    We're not trying to check that methods do the right things (ie, that creating a key with 'Company' as the first argument sets the kind). We're trying to check that our examples use methods in the right ways. That is, I'm looking primary for typos, invalid method parameters (ie, dataset.key('too', 'many', 'arguments')), invalid method names (ie, datastore.key('Company') instead of dataset.key('Company')), and other things like that.

    Figuring out if calling the right method does what it should do is a job for tests IMO. And we always have the "report an issue" button and pull requests for people who find broken code that slips into the gaps...

    @brendandburns , can you comment and tell me if I'm way out of line here?

  15. 17 remaining items

  16. sofisl
    added 2 commits that reference this issue on Feb 3, 2026

    chore(deps): update dependency eslint-plugin-node to v11 (#598)

    150aa2f

    migrate code from googleapis/cloud-profiler-nodejs (#7087)

    288deb4
  17. GautamSharda
    added a commit that references this issue on Feb 5, 2026

    build: enable release-trigger bot (#1212) (#598)

    a32f547
  18. GautamSharda
    added 3 commits that reference this issue on Feb 23, 2026

    build: enable release-trigger bot (#1212) (#598)

    531af56

    ci: catch error when fetching dataset metadata on cleanup (#598)

    22f6d0b

    build: enable release-trigger bot (#1212) (#598)

    8594e68
  19. sofisl
    added a commit that references this issue on Feb 26, 2026

    fix: DEADLINE_EXCEEDED is no longer retried (#598)

    5d76bf7
  20. GautamSharda
    added 3 commits that reference this issue on Mar 5, 2026

    chore: release 5.4.0 (#598)

    8e42d66

    build: allow Node 10 on presubmit to push to codecov (#598)

    de8499f

    chore: release 3.3.2 (#598)

    43b0f01
  21. sofisl
    added a commit that references this issue on Mar 17, 2026

    feat: Support URL objects (#598)

    1a6355e
  22. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    chore(deps): update dependency eslint-plugin-node to v11 (#598)

    86fc374

    chore(deps): update dependency eslint-plugin-node to v11 (#598)

    40b8560
  23. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    chore(deps): update dependency eslint-plugin-node to v11 (#598)

    ac906ba
  24. thiyaguk09
    added a commit that references this issue on May 5, 2026

    chore(deps): update dependency eslint-plugin-node to v11 (googleapis#598

    d5056e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    • Core Future

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.