<commit_before>package main

import (
	"bytes"
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"regexp"
	"strings"
	"text/template"
	"time"

	"github.com/flynn/flynn/Godeps/_workspace/src/code.google.com/p/go.crypto/ssh"
	"github.com/flynn/flynn/Godeps/_workspace/src/gopkg.in/check.v1"
	"github.com/flynn/flynn/test/arg"
	"github.com/flynn/flynn/test/cluster"
)

var sshWrapper = template.Must(template.New("ssh").Parse(`
#!/bin/bash

ssh -o LogLevel=FATAL -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{.SSHKey}} "$@"
`[1:]))

var args *arg.Args
var flynnrc string
var routerIP string

func init() {
	args = arg.Parse()
	log.SetFlags(log.Lshortfile)
}

func main() {
	var err error
	var res *check.Result
	// defer exiting so it runs after all other defers
	defer func() {
		if err != nil || res != nil && !res.Passed() {
			os.Exit(1)
		}
	}()

	flynnrc = args.Flynnrc
	routerIP = args.RouterIP
	if flynnrc == "" {
		var rootFS string
		c := cluster.New(args.BootConfig, os.Stdout)
		rootFS, err = c.BuildFlynn(args.RootFS, "origin/master", false)
		if err != nil {
			c.Shutdown()
			log.Println("could not build flynn: ", err)
			return
		}
		if args.KeepRootFS {
			fmt.Println("Built Flynn in rootfs:", rootFS)
		} else {
			defer os.RemoveAll(rootFS)
		}
		if err = c.Boot(args.Backend, rootFS, 1); err != nil {
			log.Println("could not boot cluster: ", err)
			return
		}
		if args.Kill {
			defer c.Shutdown()
		}

		if err = createFlynnrc(c); err != nil {
			log.Println(err)
			return
		}
		defer os.RemoveAll(flynnrc)

		routerIP = c.RouterIP
	}

	defer func() {
		if args.Debug && (err != nil || res != nil && !res.Passed()) {
			dumpLogs()
		}
	}()

	res = check.RunAll(&check.RunConf{
		Filter:      args.Run,
		Stream:      true,
		Verbose:     true,
		KeepWorkDir: args.Debug,
	})
	fmt.Println(res)
}

type sshData struct {
	Key     string
	Pub     string
	Env     []string
	Cleanup func()<commit_msg>test: Dump logs if any error occurs<commit_after>package main

import (
	"bytes"
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"regexp"
	"strings"
	"text/template"
	"time"

	"github.com/flynn/flynn/Godeps/_workspace/src/code.google.com/p/go.crypto/ssh"
	"github.com/flynn/flynn/Godeps/_workspace/src/gopkg.in/check.v1"
	"github.com/flynn/flynn/test/arg"
	"github.com/flynn/flynn/test/cluster"
)

var sshWrapper = template.Must(template.New("ssh").Parse(`
#!/bin/bash

ssh -o LogLevel=FATAL -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{.SSHKey}} "$@"
`[1:]))

var args *arg.Args
var flynnrc string
var routerIP string

func init() {
	args = arg.Parse()
	log.SetFlags(log.Lshortfile)
}

func main() {
	var err error
	var res *check.Result
	// defer exiting here so it runs after all other defers
	defer func() {
		if err != nil || res != nil && !res.Passed() {
			if args.Debug {
				dumpLogs()
			}
			os.Exit(1)
		}
	}()

	flynnrc = args.Flynnrc
	routerIP = args.RouterIP
	if flynnrc == "" {
		var rootFS string
		c := cluster.New(args.BootConfig, os.Stdout)
		rootFS, err = c.BuildFlynn(args.RootFS, "origin/master", false)
		if err != nil {
			c.Shutdown()
			log.Println("could not build flynn: ", err)
			return
		}
		if args.KeepRootFS {
			fmt.Println("Built Flynn in rootfs:", rootFS)
		} else {
			defer os.RemoveAll(rootFS)
		}
		if err = c.Boot(args.Backend, rootFS, 1); err != nil {
			log.Println("could not boot cluster: ", err)
			return
		}
		if args.Kill {
			defer c.Shutdown()
		}

		if err = createFlynnrc(c); err != nil {
			log.Println(err)
			return
		}
		defer os.RemoveAll(flynnrc)

		routerIP = c.RouterIP
	}

	res = check.RunAll(&check.RunConf{
		Filter:      args.Run,
		Stream:      true,
		Verbose:     true,
		KeepWorkDir: args.Debug,
	})
	fmt.Println(res)
}

type sshData struct {
	Key     string
	Pub     string
	Env     []string
	Cleanup func()
{'fraction_non_alphanumeric': 0.15497878712253557, 'fraction_numerical': 0.0034938857000249564, 'mean_word_length': 3.170655567117586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5343154', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1621, 'n_words': 349}