GoTests.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:GoTests-Sublime 作者: cweill 项目源码 文件源码
def run(self, edit):
        settings = sublime.load_settings("GoTests.sublime-settings")
        gopath = settings.get("GOPATH", "")
        if os.environ.get("GOPATH") == None:
            if gopath != "":
                # Set $GOPATH in this shell and add $GOPATH/bin to $PATH.
                os.environ["GOPATH"] = gopath
                os.environ["PATH"] += os.pathsep + os.path.join(gopath, "bin")
            else:
                sublime.message_dialog("GoTests: GOPATH is not set.")
                return False
        fn = self.view.file_name()
        if fn and fn.endswith('.go') and not fn.endswith('_test.go'):
            fs = []
            for s in self.view.sel():
                line = self.function_line(s.begin())
                i = line.begin()
                while i <= s.end():
                    f = self.function_name(line)
                    i = line.end() + 1
                    line = self.view.line(i)
                    if not f:
                        continue
                    fs.append(f)
            try:
                gotests = settings.get("gotests_cmd", "gotests")
                cmd = [gotests, '-w', '-only=(?i)^(' + "|".join(fs) + ')$', fn]
                proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
                print(proc.stdout.read().decode("utf-8").replace('\r\n', '\n'))
            except OSError as e:
                sublime.message_dialog("GoTests error: " + str(e) + ".")
                return False
            return True
        return False

    # Returns a function signature's line from a point in its body.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号