Skip to content

Commit

Permalink
Merge pull request #1403 from urfave/gfmrun-current
Browse files Browse the repository at this point in the history
Run docs tests against current work tree
  • Loading branch information
meatballhat committed May 23, 2022
2 parents 2419700 + 8f47e6d commit 595cabc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/v2/manual.md
Expand Up @@ -363,7 +363,7 @@ For example this:

<!-- {
"args": ["&#45;&#45;help"],
"output": "add a task to the list\n.*complete a task on the list\n.*\n\n.*\n.*Load configuration from FILE\n.*Language for the greeting.*"
"output": ".*Load configuration from FILE\n.*\n.*Language for the greeting.*"
} -->
``` go
package main
Expand Down
45 changes: 42 additions & 3 deletions internal/build/build.go
Expand Up @@ -179,8 +179,43 @@ func testCleanup(packages []string) error {
return os.WriteFile("coverage.txt", out.Bytes(), 0644)
}

func GfmrunActionFunc(c *cli.Context) error {
filename := c.Args().Get(0)
func GfmrunActionFunc(cCtx *cli.Context) error {
top := cCtx.Path("top")

bash, err := exec.LookPath("bash")
if err != nil {
return err
}

os.Setenv("SHELL", bash)

tmpDir, err := os.MkdirTemp("", "urfave-cli*")
if err != nil {
return err
}

wd, err := os.Getwd()
if err != nil {
return err
}

if err := os.Chdir(tmpDir); err != nil {
return err
}

fmt.Fprintf(cCtx.App.ErrWriter, "# ---> workspace/TMPDIR is %q\n", tmpDir)

if err := runCmd("go", "work", "init", top); err != nil {
return err
}

os.Setenv("TMPDIR", tmpDir)

if err := os.Chdir(wd); err != nil {
return err
}

filename := cCtx.Args().Get(0)
if filename == "" {
filename = "README.md"
}
Expand Down Expand Up @@ -209,7 +244,11 @@ func GfmrunActionFunc(c *cli.Context) error {
return err
}

return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", filename)
if err := runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", filename); err != nil {
return err
}

return os.RemoveAll(tmpDir)
}

// checkBinarySizeActionFunc checks the size of an example binary to ensure that we are keeping size down
Expand Down

0 comments on commit 595cabc

Please sign in to comment.