elvish/pkg/pprof/pprof_test.go
Qi Xiao 33a04f8dc1 Revamp flag handling in pkg/prog.
Instead of putting all possible flags in prog.Flags, flags are now registered by
the individual subprograms. The 3 flags -sock, -db and -json are shared by
multiple subprograms and still handled by the prog package.

This new design allows separating the support for -cpuprofile into a separate
subprogram, which is no longer included by the default entry point, making the
binary slightly smaller. A new entrypoint "withpprof" is created.

Also include the LSP subprogram in the nodaemon entry point.
2022-02-05 14:52:29 +00:00

39 lines
889 B
Go

package pprof_test
import (
"os"
"testing"
. "src.elv.sh/pkg/pprof"
"src.elv.sh/pkg/prog"
"src.elv.sh/pkg/prog/progtest"
"src.elv.sh/pkg/testutil"
)
var (
Test = progtest.Test
ThatElvish = progtest.ThatElvish
)
func TestProgram(t *testing.T) {
testutil.InTempDir(t)
Test(t, prog.Composite(&Program{}, noopProgram{}),
ThatElvish("-cpuprofile", "cpuprof").DoesNothing(),
ThatElvish("-cpuprofile", "/a/bad/path").
WritesStderrContaining("Warning: cannot create CPU profile:"),
)
// Check for the effect of -cpuprofile. There isn't much to test beyond a
// sanity check that the profile file now exists.
_, err := os.Stat("cpuprof")
if err != nil {
t.Errorf("CPU profile file does not exist: %v", err)
}
}
type noopProgram struct{}
func (noopProgram) RegisterFlags(*prog.FlagSet) {}
func (noopProgram) Run([3]*os.File, []string) error { return nil }