Giter Club home page Giter Club logo

Comments (2)

waymobetta avatar waymobetta commented on June 24, 2024 2

Irrespective of fmt involvement in tests, it's also referenced in a realm within the how-to guide. We can replace this specific usage with ufmt in the meantime until a more long-term solution is provided that addresses what you've touched on, etc. @thehowl

from gno.

thehowl avatar thehowl commented on June 24, 2024

imo better to explain it. There is a "test context" and a normal "execution context", and there will likely continue to be.

You can find a list of all of the "extra packages" and their functions here:

gno/gnovm/tests/imports.go

Lines 103 to 114 in b2046c5

if pkgPath == "os" || // special cases even when StdlibsOnly (for tests).
pkgPath == "fmt" || // TODO: try to minimize these exceptions over time.
pkgPath == "log" ||
pkgPath == "crypto/rand" ||
pkgPath == "crypto/md5" ||
pkgPath == "crypto/sha1" ||
pkgPath == "encoding/binary" ||
pkgPath == "encoding/json" ||
pkgPath == "encoding/xml" ||
pkgPath == "internal/os_test" ||
pkgPath == "math/big" ||
pkgPath == "math/rand" ||

The functions, variables and types they expose are below in the switch statement. Note that not all of the package names in the switch cases are available in test contexts; only the ones in the if statement.

Why is that?

Essentially, it's all a bit screwed, we have the directory gnovm/tests/files which works with the semantics of filetests, except it doesn't and it actually has some more superpowers. It has a bunch of stdlibs registered using "gonative", a system to run Go code in Gno (similar to native bindings) which is very problematic for a variety of reasons. fmt is currently implemented that way, and gonative is essentially the reason why fmt.Println(struct{a string}{"x"}) fails.

These work together with the "testing stdlibs", available here: https://github.com/gnolang/gno/tree/master/gnovm/tests/stdlibs -- currently it only covers a few functions in std.

The long term plan (2-3 months down the line, at least): have fmt use reflection, and not be "special" to test contests, together with other useful "test-specific" packages (crypto/md5 and sha1 maybe, encoding/binary, encoding/json, encoding/xml, math/big, math/rand).

We will continue having test-specific functions in std, and likely introduce debug which is also test-specific; so they have to be documented anyway. I suggest making a list of the functions that are currently exported in tests through gonative, and listing them referencing just the Go documentation directly, saying that most of them will eventually be ported over to Gno and be available for docs with gno doc.

Test specific stdlibs will also be available in gno doc eventually :)

from gno.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.