github.com/NeowayLabs/nash@v0.2.2-0.20200127205349-a227041ffd50/tests/cfg.go (about)

     1  package tests
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"runtime"
     7  	"strings"
     8  )
     9  
    10  var (
    11  	// Nashcmd is the nash's absolute binary path in source
    12  	Nashcmd string
    13  
    14  	// Projectpath is the path to nash source code
    15  	Projectpath string
    16  
    17  	// Testdir is the test assets directory
    18  	Testdir string
    19  
    20  	// Stdbindir is the stdbin directory
    21  	Stdbindir string
    22  )
    23  
    24  func init() {
    25  	project := "github.com/madlambda/nash"
    26  	wd, err := os.Getwd()
    27  	if err != nil {
    28  		panic("failed to get current directory")
    29  	}
    30  
    31  	pos := strings.Index(wd, project) + len(project)
    32  	Projectpath = wd[:pos]
    33  
    34  	Testdir = filepath.Join(Projectpath, "testfiles")
    35  	Nashcmd = filepath.Join(Projectpath, "cmd", "nash", "nash")
    36  	Stdbindir = filepath.Join(Projectpath, "stdbin")
    37  
    38  	if runtime.GOOS == "windows" {
    39  		Nashcmd += ".exe"
    40  	}
    41  
    42  	if _, err := os.Stat(Nashcmd); err != nil {
    43  		panic("Please, run make build before running tests")
    44  	}
    45  }