src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/mods/doc/doc_test.go (about)

     1  package doc_test
     2  
     3  import (
     4  	"embed"
     5  	"io/fs"
     6  	"testing"
     7  
     8  	"src.elv.sh/pkg/elvdoc"
     9  	"src.elv.sh/pkg/eval/evaltest"
    10  	"src.elv.sh/pkg/mods/doc"
    11  	"src.elv.sh/pkg/must"
    12  	"src.elv.sh/pkg/testutil"
    13  )
    14  
    15  //go:embed fakepkg
    16  var fakepkg embed.FS
    17  
    18  //go:embed *.elvts
    19  var transcripts embed.FS
    20  
    21  func TestDocExtractionError(t *testing.T) {
    22  	_, err := (*doc.DocsMapWithError)()
    23  	if err != nil {
    24  		t.Errorf("doc extraction has error: %v", err)
    25  	}
    26  }
    27  
    28  func TestTranscripts(t *testing.T) {
    29  	testutil.Set(t, doc.DocsMapWithError, func() (map[string]elvdoc.Docs, error) {
    30  		return must.OK1(elvdoc.ExtractAllFromFS(must.OK1(fs.Sub(fakepkg, "fakepkg")))), nil
    31  	})
    32  	// The result of reading the FS is cached. As a result, this override can't
    33  	// be reverted, so we just do it here instead of properly inside a setup
    34  	// function.
    35  	evaltest.TestTranscriptsInFS(t, transcripts)
    36  }