-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cbdd72
commit 03d8428
Showing
16 changed files
with
114 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package php | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// Getcwd gets the current working directory, it will return empty string when error occurs | ||
func Getcwd() string { | ||
dir, _ := os.Getwd() | ||
return dir | ||
} | ||
|
||
// Chdir changes current directory to dir | ||
func Chdir(dir string) error { | ||
return os.Chdir(dir) | ||
} | ||
|
||
// Scandir lists files and directories inside the specified path | ||
func Scandir(dir string) ([]string, error) { | ||
f, err := os.Open(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
names, err := f.Readdirnames(-1) | ||
f.Close() | ||
|
||
return names, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package php_test | ||
|
||
import ( | ||
"github.com/hyperjiang/php" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Directory Functions", func() { | ||
It("Chdir and Getcwd", func() { | ||
var dir = php.Getcwd() | ||
Expect(dir).NotTo(BeEmpty()) | ||
|
||
var err = php.Chdir(dir + "/tmp") | ||
Expect(err).To(HaveOccurred(), "no such file or directory") | ||
}) | ||
|
||
It("Scandir", func() { | ||
var names, err = php.Scandir(".") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(names).NotTo(BeEmpty()) | ||
|
||
_, err = php.Scandir("./tmp") | ||
Expect(err).To(HaveOccurred(), "no such directory") | ||
|
||
_, err = php.Scandir("./README.md") | ||
Expect(err).To(HaveOccurred(), "no such directory") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module github.com/hyperjiang/php | ||
|
||
go 1.11 | ||
|
||
require ( | ||
github.com/onsi/ginkgo v1.10.3 | ||
github.com/onsi/gomega v1.7.1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters