Skip to content

Commit

Permalink
@confdir is always slash-delimited. Fix tests on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
cortesi committed Aug 16, 2019
1 parent 19bdfd7 commit 8c214cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions conf/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package conf

import (
"fmt"
"path/filepath"
"path"
"runtime"
"strings"
)
Expand All @@ -24,7 +24,7 @@ type parser struct {
peekItem *item
}

// Dreadfully naive at the momet, but then so is the lexer.
// Dreadfully naive at the moment, but then so is the lexer.
func unquote(s string) string {
quote := s[0:1]
s = s[1 : len(s)-1]
Expand Down Expand Up @@ -165,7 +165,7 @@ func (p *parser) parse() (err error) {

// Store path to conf in variable if not empty
if p.name != "" {
p.config.addVariable(confVarName, filepath.Dir(p.name))
p.config.addVariable(confVarName, path.Dir(p.name))
}

for {
Expand Down Expand Up @@ -244,7 +244,9 @@ Loop:
p.errorf("indir can only be used once per block")
}
// Replace @confdir here instead of at command runtime
dir = strings.Replace(dir, confVarName, p.config.variables[confVarName], -1)
dir = strings.Replace(
dir, confVarName, p.config.variables[confVarName], -1,
)
block.InDir = dir
case itemDaemon:
options := p.collectValues(itemBareString)
Expand Down
5 changes: 2 additions & 3 deletions conf/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package conf

import (
"path/filepath"
"syscall"
"testing"

Expand Down Expand Up @@ -275,7 +274,7 @@ var parseTests = []struct {
"",
&Config{
variables: map[string]string{
"@confdir": filepath.Join("path", "to"),
"@confdir": "path/to",
},
},
},
Expand All @@ -287,7 +286,7 @@ var parseTests = []struct {
{InDir: "path/to/foo"},
},
variables: map[string]string{
"@confdir": filepath.Join("path", "to"),
"@confdir": "path/to",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions prep.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func RunPreps(
if mod != nil {
modified = mod.All()
}

vcmd := varcmd.VarCmd{Block: &b, Modified: modified, Vars: vars}
for _, p := range b.Preps {
cmd, err := vcmd.Render(p.Command)
Expand Down
15 changes: 11 additions & 4 deletions test/indir.conf
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
{
prep: "
echo Should be in source dir
pwd
"
}

{
indir: ..
prep: "
echo Should be in top level
ls
pwd
"
}

{
indir: "./test"
prep: "
echo Should be in test
ls
pwd
"
}

{
indir: ..
prep: "
echo Should be in top level
ls
pwd
"
}

{
indir: "@confdir"
prep: "
echo Should be in test
ls
pwd
"
}

0 comments on commit 8c214cd

Please sign in to comment.