Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests for unions; several fixes #75

Merged
merged 4 commits into from
Sep 10, 2020
Merged

Conversation

warpfork
Copy link
Collaborator

@warpfork warpfork commented Sep 5, 2020

Update the tests targeting codegen'd unions to use the new test helper system introduced in #66 .

The increased coverage found an infinite loop in iterators, so the fix for this is included. Similarly, a bug in the assembler's reset mechanism was found, and is fixed.

With these two fixes, I'm also coincidentally able now able to use codegen'd unions in some pretty interesting larger demos without incident. More news on that shortly ;)

The increased coverage found an infinite loop in iterators, so the
fix for this is included in this commit.
Interesting to note that this causes the go-wish library to drop out of
the imports list entirely.
This is probably now one of the nicer (directly-exercised) examples we
have for how the type-level and representation-level views of data can
differ with the use of schemas.
@@ -35,36 +31,46 @@ func TestUnionKinded(t *testing.T) {
}),
))

// These are the same *type-level* as in TestUnionKeyedComplexChildren,
// but (of course) have very different representations.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been entertaining the thought of putting some methods on this testcase structure so that one can "derive" variations of them with only some fields changed, which could be useful for tests like this that poke at variations in representation.

Could be a future work thing.

},
}

test := func(t *testing.T, getPrototypeByName func(string) ipld.NodePrototype) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These setup blocks (this and a dozen or so lines below) are getting somewhat redundant. It might soon be time to try to extract something here.

I've been wary to do this prematurely, and it'll be a bit tricky because reasons for doing distinct gen invocation are various (e.g. in these tests, it's always poking CfgUnionMemlayout; but that's not true in other tests which don't show up in this diff). But it's getting to the point it might be worth some looking into soon.

Copy link
Contributor

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take my approval with a grain of salt, as I'm still getting used to the codebase. but generally LGTM

}
}

t.Run("union-using-embed", func(t *testing.T) {
Copy link
Contributor

@mvdan mvdan Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking some more, but these should be CamelCase for the sake of consistency. There are some examples in https://golang.org/pkg/testing/ too.

@@ -162,3 +178,77 @@ func TestUnionKeyedComplexChildren(t *testing.T) {
})
})
}

// TestUnionKeyedReset puts a union inside a list, so that we can use the list's reuse of assembler as a test of the assembler's reset feature.
// The value inside the union is also more complex than a scalar value so that we test resetting gets passed down, too.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so that we test that resetting...

I'm pretty sure, but not 100% sure :)

typePoints: []testcasePoint{
{"", ipld.ReprKind_Map},
{"String", "whee"},
//{"SmolStruct", ipld.ErrNotExists{}}, // TODO: need better error typing from traversal package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: link to the issue in these TODOs? that way when the issue gets fixed, it's trivial to find the spots that can be improved

@warpfork warpfork merged commit beba587 into master Sep 10, 2020
@warpfork warpfork deleted the union-tests-and-fixes branch September 10, 2020 12:01
@aschmahmann aschmahmann mentioned this pull request Feb 18, 2021
73 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants