2018-08-10 02:29:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
2018-08-12 03:21:32 +00:00
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
2018-08-10 02:29:32 +00:00
|
|
|
|
2019-09-09 23:08:19 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2019-09-09 22:39:31 +00:00
|
|
|
"github.com/hashicorp/hcl/v2/hclparse"
|
2018-08-10 02:29:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
os.Exit(realMain(os.Args[1:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func realMain(args []string) int {
|
|
|
|
if len(args) != 2 {
|
|
|
|
fmt.Fprintf(os.Stderr, "Usage: hclspecsuite <tests-dir> <hcldec-file>\n")
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
testsDir := args[0]
|
|
|
|
hcldecPath := args[1]
|
|
|
|
|
|
|
|
hcldecPath, err := exec.LookPath(hcldecPath)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
parser := hclparse.NewParser()
|
|
|
|
|
2018-08-13 01:22:10 +00:00
|
|
|
color := terminal.IsTerminal(int(os.Stderr.Fd()))
|
|
|
|
w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
|
|
|
|
if err != nil {
|
|
|
|
w = 80
|
|
|
|
}
|
|
|
|
diagWr := hcl.NewDiagnosticTextWriter(os.Stderr, parser.Files(), uint(w), color)
|
|
|
|
var diagCount int
|
|
|
|
|
2018-08-10 02:29:32 +00:00
|
|
|
runner := &Runner{
|
|
|
|
parser: parser,
|
|
|
|
hcldecPath: hcldecPath,
|
|
|
|
baseDir: testsDir,
|
2018-08-13 01:22:10 +00:00
|
|
|
logBegin: func(name string, file *TestFile) {
|
|
|
|
fmt.Printf("- %s\n", name)
|
|
|
|
},
|
|
|
|
logProblems: func(name string, file *TestFile, diags hcl.Diagnostics) {
|
|
|
|
if len(diags) != 0 {
|
|
|
|
os.Stderr.WriteString("\n")
|
|
|
|
diagWr.WriteDiagnostics(diags)
|
|
|
|
diagCount += len(diags)
|
|
|
|
}
|
2018-08-10 02:29:32 +00:00
|
|
|
fmt.Printf("- %s\n", name)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
diags := runner.Run()
|
|
|
|
|
|
|
|
if len(diags) != 0 {
|
2018-08-13 01:22:10 +00:00
|
|
|
os.Stderr.WriteString("\n\n\n== Test harness problems:\n\n")
|
2018-08-10 02:29:32 +00:00
|
|
|
diagWr.WriteDiagnostics(diags)
|
2018-08-13 01:22:10 +00:00
|
|
|
diagCount += len(diags)
|
2018-08-10 02:29:32 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 01:22:10 +00:00
|
|
|
if diagCount > 0 {
|
|
|
|
return 2
|
|
|
|
}
|
2018-08-10 02:29:32 +00:00
|
|
|
return 0
|
|
|
|
}
|