// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package testtrace

import (
	
	
	
	
	
)

// ParseFile parses a test file generated by the testgen package.
func ( string) (io.Reader, *Expectation, error) {
	,  := txtar.ParseFile()
	if  != nil {
		return nil, nil, fmt.Errorf("failed to read test file for %s: %v", , )
	}
	if len(.Files) != 2 {
		return nil, nil, fmt.Errorf("malformed test %s: wrong number of files", )
	}
	if .Files[0].Name != "expect" {
		return nil, nil, fmt.Errorf("malformed test %s: bad filename %s", , .Files[0].Name)
	}
	if .Files[1].Name != "trace" {
		return nil, nil, fmt.Errorf("malformed test %s: bad filename %s", , .Files[1].Name)
	}
	,  := raw.NewTextReader(bytes.NewReader(.Files[1].Data))
	if  != nil {
		return nil, nil, fmt.Errorf("malformed test %s: bad trace file: %v", , )
	}
	var  bytes.Buffer
	,  := raw.NewWriter(&, .Version())
	if  != nil {
		return nil, nil, fmt.Errorf("failed to create trace byte writer: %v", )
	}
	for {
		,  := .ReadEvent()
		if  == io.EOF {
			break
		}
		if  != nil {
			return nil, nil, fmt.Errorf("malformed test %s: bad trace file: %v", , )
		}
		if  := .WriteEvent();  != nil {
			return nil, nil, fmt.Errorf("internal error during %s: failed to write trace bytes: %v", , )
		}
	}
	,  := ParseExpectation(.Files[0].Data)
	if  != nil {
		return nil, nil, fmt.Errorf("internal error during %s: failed to parse expectation %q: %v", , string(.Files[0].Data), )
	}
	return &, , nil
}