Skip to content

Commit 02ed942

Browse files
authored
Merge pull request #331 from metrumresearchgroup/feature/2.0.2-validation
2 parents a7c4a78 + 765933d commit 02ed942

File tree

2,007 files changed

+66939
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,007 files changed

+66939
-584
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ logfile.txt
55
.idea
66
pkgr
77
pkgr.go
8-
pkgr.yml
98
goreleaser.yml

cmd/add_test.go

Lines changed: 118 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -14,140 +14,127 @@
1414

1515
package cmd
1616

17-
import (
18-
"bytes"
19-
"fmt"
20-
"os"
21-
"os/exec"
22-
"path/filepath"
23-
"testing"
24-
25-
"github.com/spf13/afero"
26-
"github.com/spf13/cobra"
27-
"github.com/stretchr/testify/assert"
28-
)
29-
30-
type pkgData struct {
31-
name string
32-
folder string
33-
}
34-
35-
type testData struct {
36-
ymlfolder string
37-
data []pkgData
38-
}
39-
40-
func Test_rAddAndDelete(t *testing.T) {
41-
type args struct {
42-
ccmd *cobra.Command
43-
args []string
44-
}
45-
46-
tests := []testData{
47-
{
48-
ymlfolder: "testsite/golden/simple",
49-
data: []pkgData{
50-
{
51-
name: "R6",
52-
folder: "testsite/golden/simple/test-library/shiny",
53-
},
54-
{
55-
name: "jsonlite",
56-
folder: "testsite/golden//simple/test-library/abc",
57-
},
58-
},
59-
},
60-
// Note: before adding a test, make sure the base test "pkgr install" works before testing "pkgr add --install"
61-
}
62-
fs := afero.NewOsFs()
63-
//fs := afero.NewMemMapFs()
64-
pkgrYamlContent := []byte(`
65-
Version: 1
66-
67-
Packages:
68-
- fansi
69-
Repos:
70-
- MPN: "https://mpn.metworx.com/snapshots/stable/2019-12-02"
71-
72-
Library: "test-library"
73-
`)
74-
75-
afero.WriteFile(fs, "testsite/golden/simple/pkgr.yml", pkgrYamlContent, 0755)
76-
77-
defer fs.RemoveAll("testsite/golden/simple/test-library")
78-
for _, tt := range tests {
79-
80-
ymlFilename := filepath.Join(tt.ymlfolder, "pkgr.yml")
81-
b, _ := afero.Exists(fs, ymlFilename)
82-
assert.Equal(t, true, b, fmt.Sprintf("yml file not found:%s", ymlFilename))
83-
ymlStart, _ := afero.ReadFile(fs, ymlFilename)
84-
85-
t.Log("testing add ...")
86-
errstr, err := pkgrCommand("add", tt, "--install")
87-
assert.Equal(t, nil, err, fmt.Sprintf("Package add error. Check state of yml file <%s>. <%s> ", tt.ymlfolder, errstr))
88-
89-
for _, d := range tt.data {
90-
b, _ := afero.FileContainsBytes(fs, filepath.Join(tt.ymlfolder, "pkgr.yml"), []byte(d.name))
91-
installed, _ := afero.DirExists(fs, filepath.Join(tt.ymlfolder, "test-library", d.name)) // make sure packages were installed with --install flag
92-
assert.Equal(t, true, b, fmt.Sprintf("Package not added:%s", d.name))
93-
assert.Equal(t, true, installed, fmt.Sprintf("Package not installed after being added:%s", d.name))
94-
}
95-
96-
t.Log("testing remove ...")
97-
errstr, err = pkgrCommand("remove", tt, "")
98-
assert.Equal(t, nil, err, fmt.Sprintf("Package remove error. Check state of yml file <%s>. <%s> ", tt.ymlfolder, errstr))
99-
100-
for _, d := range tt.data {
101-
b, _ := afero.FileContainsBytes(fs, filepath.Join(tt.ymlfolder, "pkgr.yml"), []byte(d.name))
102-
assert.Equal(t, !true, b, fmt.Sprintf("Package not removed:%s", d.name))
103-
}
104-
105-
t.Log("testing pkgr.yml for difference ...")
106-
ymlEnd, _ := afero.ReadFile(fs, ymlFilename)
107-
n := bytes.Compare(cleanWs(ymlStart), cleanWs(ymlEnd))
108-
assert.Equal(t, 0, n, fmt.Sprintf("Yml file differs"))
109-
110-
t.Log("restoring yml file ...")
111-
fi, _ := os.Stat(ymlFilename)
112-
err = afero.WriteFile(fs, ymlFilename, ymlStart, fi.Mode())
113-
assert.Equal(t, nil, err, "Error restoring yml file")
114-
}
115-
}
116-
117-
func pkgrCommand(cmd string, test testData, flag string) (string, error) {
118-
var stderr bytes.Buffer
119-
pkgr := filepath.Join(os.Getenv("HOME"), "/go/bin/pkgr")
120-
args := []string{cmd}
121-
for _, d := range test.data {
122-
args = append(args, d.name)
123-
}
124-
125-
if len(flag) > 0 {
126-
args = append(args, flag)
127-
}
128-
129-
command := exec.Command(pkgr, args...)
130-
command.Dir = test.ymlfolder
131-
command.Stderr = &stderr
132-
133-
err := command.Run()
134-
errstr := string(stderr.Bytes())
135-
return errstr, err
136-
}
17+
//type pkgData struct {
18+
// name string
19+
// folder string
20+
//}
21+
//
22+
//type testData struct {
23+
// ymlfolder string
24+
// data []pkgData
25+
//}
26+
27+
//func Test_rAddAndDelete(t *testing.T) {
28+
// type args struct {
29+
// ccmd *cobra.Command
30+
// args []string
31+
// }
32+
//
33+
// tests := []testData{
34+
// {
35+
// ymlfolder: "testsite/golden/simple",
36+
// data: []pkgData{
37+
// {
38+
// name: "R6",
39+
// folder: "testsite/golden/simple/test-library/shiny",
40+
// },
41+
// {
42+
// name: "jsonlite",
43+
// folder: "testsite/golden//simple/test-library/abc",
44+
// },
45+
// },
46+
// },
47+
// // Note: before adding a test, make sure the base test "pkgr install" works before testing "pkgr add --install"
48+
// }
49+
// fs := afero.NewOsFs()
50+
// //fs := afero.NewMemMapFs()
51+
// pkgrYamlContent := []byte(`
52+
//Version: 1
53+
//
54+
//Packages:
55+
// - fansi
56+
//Repos:
57+
// - MPN: "https://mpn.metworx.com/snapshots/stable/2019-12-02"
58+
//
59+
//Library: "test-library"
60+
//`)
61+
//
62+
// afero.WriteFile(fs, "testsite/golden/simple/pkgr.yml", pkgrYamlContent, 0755)
63+
//
64+
// defer fs.RemoveAll("testsite/golden/simple/test-library")
65+
// for _, tt := range tests {
66+
//
67+
// ymlFilename := filepath.Join(tt.ymlfolder, "pkgr.yml")
68+
// b, _ := afero.Exists(fs, ymlFilename)
69+
// assert.Equal(t, true, b, fmt.Sprintf("yml file not found:%s", ymlFilename))
70+
// ymlStart, _ := afero.ReadFile(fs, ymlFilename)
71+
//
72+
// t.Log("testing add ...")
73+
// errstr, err := pkgrCommand("add", tt, "--install")
74+
// assert.Equal(t, nil, err, fmt.Sprintf("Package add error. Check state of yml file <%s>. <%s> ", tt.ymlfolder, errstr))
75+
//
76+
// for _, d := range tt.data {
77+
// b, _ := afero.FileContainsBytes(fs, filepath.Join(tt.ymlfolder, "pkgr.yml"), []byte(d.name))
78+
// installed, _ := afero.DirExists(fs, filepath.Join(tt.ymlfolder, "test-library", d.name)) // make sure packages were installed with --install flag
79+
// assert.Equal(t, true, b, fmt.Sprintf("Package not added:%s", d.name))
80+
// assert.Equal(t, true, installed, fmt.Sprintf("Package not installed after being added:%s", d.name))
81+
// }
82+
//
83+
// t.Log("testing remove ...")
84+
// errstr, err = pkgrCommand("remove", tt, "")
85+
// assert.Equal(t, nil, err, fmt.Sprintf("Package remove error. Check state of yml file <%s>. <%s> ", tt.ymlfolder, errstr))
86+
//
87+
// for _, d := range tt.data {
88+
// b, _ := afero.FileContainsBytes(fs, filepath.Join(tt.ymlfolder, "pkgr.yml"), []byte(d.name))
89+
// assert.Equal(t, !true, b, fmt.Sprintf("Package not removed:%s", d.name))
90+
// }
91+
//
92+
// t.Log("testing pkgr.yml for difference ...")
93+
// ymlEnd, _ := afero.ReadFile(fs, ymlFilename)
94+
// n := bytes.Compare(cleanWs(ymlStart), cleanWs(ymlEnd))
95+
// assert.Equal(t, 0, n, fmt.Sprintf("Yml file differs"))
96+
//
97+
// t.Log("restoring yml file ...")
98+
// fi, _ := os.Stat(ymlFilename)
99+
// err = afero.WriteFile(fs, ymlFilename, ymlStart, fi.Mode())
100+
// assert.Equal(t, nil, err, "Error restoring yml file")
101+
// }
102+
//}
103+
104+
//func pkgrCommand(cmd string, test testData, flag string) (string, error) {
105+
// var stderr bytes.Buffer
106+
// pkgr := filepath.Join(os.Getenv("HOME"), "/go/bin/pkgr")
107+
// args := []string{cmd}
108+
// for _, d := range test.data {
109+
// args = append(args, d.name)
110+
// }
111+
//
112+
// if len(flag) > 0 {
113+
// args = append(args, flag)
114+
// }
115+
//
116+
// command := exec.Command(pkgr, args...)
117+
// command.Dir = test.ymlfolder
118+
// command.Stderr = &stderr
119+
//
120+
// err := command.Run()
121+
// errstr := string(stderr.Bytes())
122+
// return errstr, err
123+
//}
137124

138125
// cleanWs removes blank lines and leading and trailing white space
139126
// it makes the above bytes.Compare(..) equivilent to: /usr/bin/diff -wB
140-
func cleanWs(b []byte) []byte {
141-
var cb []byte
142-
lines := bytes.Split(b, []byte("\n"))
143-
for _, line := range lines {
144-
tl := bytes.Trim(line, " ")
145-
if len(tl) > 0 {
146-
cb = append(cb, line...)
147-
}
148-
}
149-
return cb
150-
}
127+
//func cleanWs(b []byte) []byte {
128+
// var cb []byte
129+
// lines := bytes.Split(b, []byte("\n"))
130+
// for _, line := range lines {
131+
// tl := bytes.Trim(line, " ")
132+
// if len(tl) > 0 {
133+
// cb = append(cb, line...)
134+
// }
135+
// }
136+
// return cb
137+
//}
151138

152139
// // saving in case ...
153140
// func diff(file1, file2 string) bool {

cmd/install_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/spf13/afero"
88
"github.com/spf13/cobra"
99
"github.com/stretchr/testify/assert"
10+
"os"
1011
"path/filepath"
1112
"testing"
1213
)
@@ -39,12 +40,14 @@ func InitializeGoldenTestSiteWorking(goldenSet string) string {
3940

4041
// Initializes a symlink to "test-library" in the testsite for the goldenSet. Links to the provided LibraryToUse and returns the symlink.
4142
func InitializeTestLibrary(goldenSet, libraryToUse string) string {
42-
fs := &afero.OsFs{}
43+
//fs := &afero.OsFs{}
4344

44-
testLibrary := filepath.Join("testsite", "working", goldenSet, "test-library")
45-
err := fs.SymlinkIfPossible(testLibrary, libraryToUse)
45+
testLibrary := filepath.Join("testsite", "working", "test-library")
46+
err := os.Symlink(libraryToUse, testLibrary)
47+
//err := fs.SymlinkIfPossible(testLibrary, libraryToUse)
4648
if err != nil {
47-
fmt.Errorf("error creating symlink for test library: %s", err)
49+
fmt.Sprintf("error creating symlink for test library: %s", err)
50+
panic("could not symlink test-library")
4851
}
4952
return testLibrary
5053

cmd/load_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ func TestLoadSucceeds(t *testing.T) {
3434

3535
// Setup
3636
rDir := InitializeGoldenTestSiteWorking("load")
37-
libraryPath := InitializeTestLibrary("load", filepath.Join("testsite", "golden", "load", "test-library-4.0"))// set library to "test-library-3.0" if user R 3.X
37+
38+
// Needed for symlinking library
39+
globalPathPrefix, err := filepath.Abs("./")
40+
if err != nil {
41+
t.Fail()
42+
}
43+
44+
libraryPath := InitializeTestLibrary("load", filepath.Join(globalPathPrefix, "testsite", "golden", "load", "test-library-4.0"))// set library to "test-library-3.0" if user R 3.X
3845
InitializeGlobalsForTest()
3946

4047
localRepoPath := filepath.Join("..", "localrepos", "simple")
@@ -102,7 +109,14 @@ func TestLoadFails(t *testing.T) {
102109
// Setup
103110
rDir := InitializeGoldenTestSiteWorking("load-fail")
104111
InitializeGlobalsForTest()
105-
libraryPath := InitializeTestLibrary("load-fail", filepath.Join("testsite", "golden", "load-fail", "test-library-4.0"))// set library to "test-library-3.0" if user R 3.X
112+
113+
// Needed for symlinking library
114+
globalPathPrefix, err := filepath.Abs("./")
115+
if err != nil {
116+
t.Fail()
117+
}
118+
119+
libraryPath := InitializeTestLibrary("load", filepath.Join(globalPathPrefix, "testsite", "golden", "load-fail", "test-library-4.0"))// set library to "test-library-3.0" if user R 3.X
106120
localRepoPath := filepath.Join("..", "localrepos", "simple")
107121

108122
userPackages := []string{

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
// VERSION is the current pkgr version
31-
var VERSION = "2.0.1"
31+
var VERSION = "2.0.2"
3232

3333
var fs afero.Fs
3434
var cfg configlib.PkgrConfig

cmd/testsite/golden/load-fail/test-library-4.0/R6/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Maintainer: Winston Chang <winston@stdout.org>
2222
OriginalRepository: CRAN
2323
Repository: local
2424
Date/Publication: 2019-02-14 19:42:14 UTC
25-
Built: R 4.0.2; ; 2021-01-07 00:21:53 UTC; unix
25+
Built: R 4.0.2; ; 2021-01-07 00:26:02 UTC; unix
2626
PkgrVersion: v2.0.1
2727
PkgrInstallType: binary
2828
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cmd/testsite/golden/load-fail/test-library-4.0/assertthat/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Maintainer: Hadley Wickham <hadley@rstudio.com>
2222
OriginalRepository: CRAN
2323
Repository: local
2424
Date/Publication: 2019-03-21 14:53:46 UTC
25-
Built: R 4.0.2; ; 2021-01-07 00:21:58 UTC; unix
25+
Built: R 4.0.2; ; 2021-01-07 00:26:02 UTC; unix
2626
PkgrVersion: v2.0.1
2727
PkgrInstallType: binary
2828
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cmd/testsite/golden/load-fail/test-library-4.0/cli/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Maintainer: Gábor Csárdi <csardi.gabor@gmail.com>
2727
OriginalRepository: CRAN
2828
Repository: local
2929
Date/Publication: 2019-03-19 10:43:26 UTC
30-
Built: R 4.0.2; ; 2021-01-07 00:22:02 UTC; unix
30+
Built: R 4.0.2; ; 2021-01-07 00:26:06 UTC; unix
3131
PkgrVersion: v2.0.1
3232
PkgrInstallType: binary
3333
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cmd/testsite/golden/load-fail/test-library-4.0/crayon/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Maintainer: Gábor Csárdi <csardi.gabor@gmail.com>
3333
OriginalRepository: CRAN
3434
Repository: local
3535
Date/Publication: 2017-09-16 19:49:46 UTC
36-
Built: R 4.0.2; ; 2021-01-07 00:21:59 UTC; unix
36+
Built: R 4.0.2; ; 2021-01-07 00:26:04 UTC; unix
3737
PkgrVersion: v2.0.1
3838
PkgrInstallType: binary
3939
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cmd/testsite/golden/load-fail/test-library-4.0/fansi/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Maintainer: Brodie Gaslam <brodie.gaslam@yahoo.com>
3232
OriginalRepository: CRAN
3333
Repository: local
3434
Date/Publication: 2018-10-05 05:10:12 UTC
35-
Built: R 4.0.2; x86_64-apple-darwin17.0; 2021-01-07 00:21:49 UTC; unix
35+
Built: R 4.0.2; x86_64-apple-darwin17.0; 2021-01-07 00:25:54 UTC; unix
3636
PkgrVersion: v2.0.1
3737
PkgrInstallType: binary
3838
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cmd/testsite/golden/load-fail/test-library-4.0/pillar/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Maintainer: Kirill Müller <krlmlr+r@mailbox.org>
3333
OriginalRepository: CRAN
3434
Repository: local
3535
Date/Publication: 2018-12-15 17:00:03 UTC
36-
Built: R 4.0.2; ; 2021-01-07 00:22:04 UTC; unix
36+
Built: R 4.0.2; ; 2021-01-07 00:26:08 UTC; unix
3737
PkgrVersion: v2.0.1
3838
PkgrInstallType: binary
3939
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cmd/testsite/golden/load-fail/test-library-4.0/rlang/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Maintainer: Lionel Henry <lionel@rstudio.com>
2929
OriginalRepository: CRAN
3030
Repository: local
3131
Date/Publication: 2019-04-07 09:30:15 UTC
32-
Built: R 4.0.2; x86_64-apple-darwin17.0; 2021-01-07 00:21:50 UTC; unix
32+
Built: R 4.0.2; x86_64-apple-darwin17.0; 2021-01-07 00:25:54 UTC; unix
3333
PkgrVersion: v2.0.1
3434
PkgrInstallType: binary
3535
PkgrRepositoryURL: ../../../../localrepos/simple
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)