How to use BuildOutlineCommand method of outline Package

Best Ginkgo code snippet using outline.BuildOutlineCommand

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

outline_command.go

Source: outline_command.go Github

copy
1package main
2
3import (
4	"encoding/json"
5	"flag"
6	"fmt"
7	"go/parser"
8	"go/token"
9	"os"
10
11	"github.com/onsi/ginkgo/ginkgo/outline"
12)
13
14const (
15	// indentWidth is the width used by the 'indent' output
16	indentWidth = 4
17	// stdinAlias is a portable alias for stdin. This convention is used in
18	// other CLIs, e.g., kubectl.
19	stdinAlias   = "-"
20	usageCommand = "ginkgo outline <filename>"
21)
22
23func BuildOutlineCommand() *Command {
24	const defaultFormat = "csv"
25	var format string
26	flagSet := flag.NewFlagSet("outline", flag.ExitOnError)
27	flagSet.StringVar(&format, "format", defaultFormat, "Format of outline. Accepted: 'csv', 'indent', 'json'")
28	return &Command{
29		Name:         "outline",
30		FlagSet:      flagSet,
31		UsageCommand: usageCommand,
32		Usage: []string{
33			"Create an outline of Ginkgo symbols for a file",
34			"To read from stdin, use: `ginkgo outline -`",
35			"Accepts the following flags:",
36		},
37		Command: func(args []string, additionalArgs []string) {
38			outlineFile(args, format)
39		},
40	}
41}
42
43func outlineFile(args []string, format string) {
44	if len(args) != 1 {
45		println(fmt.Sprintf("usage: %s", usageCommand))
46		os.Exit(1)
47	}
48
49	filename := args[0]
50	var src *os.File
51	if filename == stdinAlias {
52		src = os.Stdin
53	} else {
54		var err error
55		src, err = os.Open(filename)
56		if err != nil {
57			println(fmt.Sprintf("error opening file: %s", err))
58			os.Exit(1)
59		}
60	}
61
62	fset := token.NewFileSet()
63
64	parsedSrc, err := parser.ParseFile(fset, filename, src, 0)
65	if err != nil {
66		println(fmt.Sprintf("error parsing source: %s", err))
67		os.Exit(1)
68	}
69
70	o, err := outline.FromASTFile(fset, parsedSrc)
71	if err != nil {
72		println(fmt.Sprintf("error creating outline: %s", err))
73		os.Exit(1)
74	}
75
76	var oerr error
77	switch format {
78	case "csv":
79		_, oerr = fmt.Print(o)
80	case "indent":
81		_, oerr = fmt.Print(o.StringIndent(indentWidth))
82	case "json":
83		b, err := json.Marshal(o)
84		if err != nil {
85			println(fmt.Sprintf("error marshalling to json: %s", err))
86		}
87		_, oerr = fmt.Println(string(b))
88	default:
89		complainAndQuit(fmt.Sprintf("format %s not accepted", format))
90	}
91	if oerr != nil {
92		println(fmt.Sprintf("error writing outline: %s", oerr))
93		os.Exit(1)
94	}
95}
96
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger BuildOutlineCommand code on LambdaTest Cloud Grid

Execute automation tests with BuildOutlineCommand on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)