hopefully fix stack overflow

cc @kbuzby
add basic test for document printing
Merge remote-tracking branch 'upstream/master'