Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run docs tests against current work tree #1403

Merged
merged 2 commits into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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": ".*Language for the greeting.*"
} -->
``` go
package main
Expand Down
39 changes: 36 additions & 3 deletions internal/build/build.go
Expand Up @@ -179,8 +179,37 @@ 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")

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)
os.Setenv("SHELL", "bash")
meatballhat marked this conversation as resolved.
Show resolved Hide resolved

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 +238,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