forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
13 changed files
with
164 additions
and
27 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
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,16 @@ | ||
// Package main A helper to run go test on CI with the right environment variables. | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/go-rod/rod/lib/utils" | ||
) | ||
|
||
func main() { | ||
for k, v := range utils.TestEnvs { | ||
err := os.Setenv(k, v) | ||
utils.E(err) | ||
} | ||
utils.Exec("go test", os.Args[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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,10 @@ | |
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/go-rod/rod/lib/utils" | ||
) | ||
|
||
func main() { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}() | ||
|
||
utils.Exec("npx -ys -- [email protected] --no-progress **") | ||
|
||
utils.Exec("npx -ys -- [email protected] --config=lib/utils/lint/eslint.yml --ext=.js,.html --fix --ignore-path=.gitignore .") | ||
|
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 main It helps to launcher a transparent shell under the current shell with | ||
// some extra environment variables that are required by rod testing. | ||
package main | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/go-rod/rod/lib/utils" | ||
) | ||
|
||
func main() { | ||
list := []string{} | ||
for k, v := range utils.TestEnvs { | ||
list = append(list, k+"="+v) | ||
} | ||
|
||
bin, err := Shell() | ||
utils.E(err) | ||
|
||
cmd := exec.Command(bin) | ||
cmd.Env = append(os.Environ(), list...) | ||
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
|
||
_ = cmd.Run() | ||
os.Exit(cmd.ProcessState.ExitCode()) | ||
} |
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,94 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"os/user" | ||
"regexp" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
// Shell https://github.com/riywo/loginshell/blob/master/loginshell.go | ||
func Shell() (string, error) { | ||
switch runtime.GOOS { | ||
case "plan9": | ||
return plan9Shell() | ||
case "linux": | ||
return nixShell() | ||
case "openbsd": | ||
return nixShell() | ||
case "freebsd": | ||
return nixShell() | ||
case "android": | ||
return androidShell() | ||
case "darwin": | ||
return darwinShell() | ||
case "windows": | ||
return windowsShell() | ||
} | ||
|
||
return "", errors.New("Undefined GOOS: " + runtime.GOOS) | ||
} | ||
|
||
func plan9Shell() (string, error) { | ||
if _, err := os.Stat("/dev/osversion"); err != nil { | ||
if os.IsNotExist(err) { | ||
return "", err | ||
} | ||
return "", errors.New("/dev/osversion check failed") | ||
} | ||
|
||
return "/bin/rc", nil | ||
} | ||
|
||
func nixShell() (string, error) { | ||
user, err := user.Current() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
out, err := exec.Command("getent", "passwd", user.Uid).Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
ent := strings.Split(strings.TrimSuffix(string(out), "\n"), ":") | ||
return ent[6], nil | ||
} | ||
|
||
func androidShell() (string, error) { | ||
shell := os.Getenv("SHELL") | ||
if shell == "" { | ||
return "", errors.New("shell not defined in android") | ||
} | ||
return shell, nil | ||
} | ||
|
||
func darwinShell() (string, error) { | ||
dir := "Local/Default/Users/" + os.Getenv("USER") | ||
out, err := exec.Command("dscl", "localhost", "-read", dir, "UserShell").Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
re := regexp.MustCompile("UserShell: (/[^ ]+)\n") | ||
matched := re.FindStringSubmatch(string(out)) | ||
shell := matched[1] | ||
if shell == "" { | ||
return "", fmt.Errorf("Invalid output: %s", string(out)) | ||
} | ||
|
||
return shell, nil | ||
} | ||
|
||
func windowsShell() (string, error) { | ||
consoleApp := os.Getenv("COMSPEC") | ||
if consoleApp == "" { | ||
consoleApp = "cmd.exe" | ||
} | ||
|
||
return consoleApp, nil | ||
} |
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