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

Add more integration tests #747

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use OS path separator in managed output
  • Loading branch information
twpayne committed May 12, 2020
commit 57b144e0eceab01187250b3093ab27c9ad8e06b9
2 changes: 1 addition & 1 deletion cmd/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Config) runManagedCmd(cmd *cobra.Command, args []string) error {
if ts.TargetIgnore.Match(targetName) {
continue
}
fmt.Fprintln(c.Stdout, filepath.Join(ts.DestDir, targetName))
fmt.Fprintln(c.Stdout, filepath.FromSlash(filepath.Join(ts.DestDir, targetName)))
}

return nil
Expand Down
17 changes: 5 additions & 12 deletions cmd/managed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,26 @@ func TestManagedCmd(t *testing.T) {
}),
)
assert.NoError(t, c.runManagedCmd(nil, nil))
posixTargetNames, err := extractPOSIXTargetNames(stdout.Bytes())
require.NoError(t, err)
assert.Equal(t, tc.expectedTargetNames, posixTargetNames)
actualTargetNames, err := extractTargetNames(stdout.Bytes())
require.NoError(t, err)
assert.Equal(t, tc.expectedTargetNames, actualTargetNames)
})
}
}

// extractPOSIXTargetNames extracts all target names from b and coverts them to
// POSIX-like names.
func extractPOSIXTargetNames(b []byte) ([]string, error) {
func extractTargetNames(b []byte) ([]string, error) {
var targetNames []string
s := bufio.NewScanner(bytes.NewBuffer(b))
for s.Scan() {
targetNames = append(targetNames, posixify(s.Text()))
targetNames = append(targetNames, filepath.ToSlash(s.Text()))
}
if err := s.Err(); err != nil {
return nil, err
}
return targetNames, nil
}

// posixify returns a POSIX-like path based on path, stripping any volume name
// and converting backward slashes.
func posixify(path string) string {
return filepath.ToSlash(strings.TrimPrefix(path, filepath.VolumeName(path)))
}

func withManaged(managed managedCmdConfig) configOption {
return func(c *Config) {
c.managed = managed
Expand Down
18 changes: 8 additions & 10 deletions testdata/scripts/managed.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
[windows] stop 'https://github.com/twpayne/chezmoi/issues/745'

chezmoi managed
cmpenv stdout golden/managed

chezmoi --include=dirs managed
chezmoi --include=dirs managed
cmpenv stdout golden/managed-dirs

chezmoi --include=files managed
chezmoi --include=files managed
cmpenv stdout golden/managed-files

-- golden/managed --
$HOME/.bashrc
$HOME/.ssh
$HOME/.ssh/config
$HOME${/}.bashrc
$HOME${/}.ssh
$HOME${/}.ssh/config
-- golden/managed-dirs --
$HOME/.ssh
$HOME${/}.ssh
-- golden/managed-files --
$HOME/.bashrc
$HOME/.ssh/config
$HOME${/}.bashrc
$HOME${/}.ssh/config
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
-- home/user/.local/share/chezmoi/dot_ssh/config --
Expand Down