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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance on how to test scaffolds #122

Closed
alexeagle opened this issue May 6, 2024 · 2 comments · Fixed by #123
Closed

Guidance on how to test scaffolds #122

alexeagle opened this issue May 6, 2024 · 2 comments · Fixed by #123

Comments

@alexeagle
Copy link

I'd like to know that the content of the scaffold produces a working output, by writing a simple automation to call scaffold, then cd into the new folder and run something on the code inside.

I tried several of the techniques on https://www.baeldung.com/linux/bash-interactive-prompts to supply prompt answers over stdin, but have errors like:

% yes | scaffold new $PWD

   starter                                                             
                                                                              
  Generate boilerplate code for a new project


? Project name panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10095a128]

goroutine 1 [running]:
github.com/AlecAivazis/survey/v2/terminal.(*RuneReader).ReadLineWithDefault.func2(...)
        /home/runner/go/pkg/mod/github.com/!alec!aivazis/survey/v2@v2.3.7/terminal/runereader.go:65
github.com/AlecAivazis/survey/v2/terminal.(*RuneReader).ReadLineWithDefault(0x140001439e0, 0x0, {0x0, 0x0, 0x0}, {0x14000680f20?, 0x14000680e48?, 0x1004f0e08?})

Alternatively I suppose you could have a first-class support for testing by allowing the scaffold CLI to accept a "script" with expected prompts and supplied answers.

@hay-kot
Copy link
Owner

hay-kot commented May 6, 2024

You can supply arguments after the path, we do some "basic" logic to turn those arguments into variables

See

rest := ctx.Args().Tail()
ctrl.vars = make(map[string]string, len(rest))
for _, v := range rest {
kv := strings.Split(v, "=")
ctrl.vars[kv[0]] = kv[1]
}

This isn't something I thought a ton about so I'm happy to consider alternative APIs and/or fix issues with this approach.

@hay-kot
Copy link
Owner

hay-kot commented May 7, 2024

Okay, I did some more digging and it looks like this isn't possible, you will always be prompted. I see two options here

Option 1

Add --no-interaction flag that skips Q/A and just use the arguments like I show above

Option 2

Add a --test flag and introduce a test top level property into the scaffold file that will be used as variables for test

test:
  Var1: value 1
  Var2: value 2

I'm more keen on option 2, but I'm open to any suggestions you have

@hay-kot hay-kot linked a pull request May 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants