131 pointsby reisinge5 months ago3 comments
  • everybodyknows5 months ago
    > We named the package hello_test instead of hello. This is possible and it allows for writing tests that use only the public API (identifiers starting with a capital letter) of the tested package as a real user would.

    Would be good to highlight here that *_test packages are the sole exception from Go's standard rule of one-package-only per source directory -- special cases being always an unfortunate additional heightening of the beginner's learning curve.

    • ttz5 months ago
      You can also include

      package main

      files in a non-main package directory (usually sed when implementing go generate)

      • arp2425 months ago
        What people usually do is add a build tag to the file(s) with package main, so they're not compiled on a regular compile/test run. But you can't combine them as such (and you can do this with any package name – there's nothing special about the main package here).
        • ttz5 months ago
          Yep - my point was that _test is not the only exception to the "rule"
          • arp2425 months ago
            No, there is no exception for the "main" package. It's just build tag trickery. You can do this with any package names (although it doesn't make much sense to do so).
            • ttz5 months ago
              Ah, I see what you're objecting to. Yes, it is build tag trickery, and wouldn't work without it
  • mrbluecoat5 months ago
    I really like this style of showing steps that would be logical for those new to Go even if they're wrong then showing why it didn't work and walking through the fix. Nice linear progression of real-world learning.
  • pentaphobe5 months ago
    Nice! You packed in so many things which are often drip fed, and take folk a while to find

    Kudos