<commit_before>/*
 * Copyright 2018-2019 Authors of Cilium
 * Copyright 2017 Mirantis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ginkgoext

import (
	"bytes"
	"flag"
	"fmt"
	"os"
	"reflect"
	"regexp"
	"strings"
	"sync/atomic"
	"time"

	"github.com/cilium/cilium/pkg/lock"
	ciliumTestConfig "github.com/cilium/cilium/test/config"

	"github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/config"
)

type scope struct {
	parent        *scope
	children      []*scope
	counter       int32
	mutex         *lock.Mutex
	before        []func()
	after         []func()
	afterEach     []func()
	justAfterEach []func()
	afterFail     []func()
	started       int32
	failed        bool
	normalTests   int
	focusedTests  int
	focused       bool
	text          string
}

var (
	currentScope = &scope{
		text:    "EntireTestsuite",
		counter: -1,
		mutex:   &lock.Mutex{},
	}

	rootScope = currentScope

	// failEnabled for tests that have failed on JustAfterEach function we need
	// to handle differently, because `ginkgo.Fail` do a panic, and all the
	// following functions will not be called. With the WrapFailfn if the fail
	// is on any After function, will not panic, will mark the test as failed,
	// and will trigger the Fail function at the end.
	failEnabled     = true
	afterEachFailed = map[string]bool{}
	afterEachCB     = map[string]func(){}

	// We wrap various ginkgo function here to track invocations and determine
	// when to call AfterAll. When using a new ginkgo equivalent to It or
	// Measure, it may need a matching wrapper similar to wrapItFunc.

	Context                               = wrapContextFunc(ginkgo.Context, false)
	FContext                              = wrapContextFunc(ginkgo.FContext, true)
	PContext                              = wrapNilContextFunc(ginkgo.PContext)
	XContext                              = wrapNilContextFunc(ginkgo.XContext)
	Describe                              = wrapContextFunc(ginkgo.Describe, false)
	FDescribe                             = wrapContextFunc(ginkgo.FDescribe, true)
	PDescribe                             = wrapNilContextFunc(ginkgo.PDescribe)
	XDescribe                             = wrapNilContextFunc(ginkgo.XDescribe)
	It                                    = wrapItFunc(ginkgo.It, false)
	FIt                                   = wrapItFunc(ginkgo.FIt, true)
	PIt                                   = ginkgo.PIt
	XIt                                   = ginkgo.XIt
	Measure                               = wrapMeasureFunc(ginkgo.Measure, false)
	JustBeforeEach                        = ginkgo.JustBeforeEach
	BeforeSuite                           = ginkgo.BeforeSuite
	AfterSuite                            = ginkgo.AfterSuite
	Skip                                  = ginkgo.Skip
	Fail                                  = FailWithToggle
	CurrentGinkgoTestDescription          = ginkgo.CurrentGinkgoTestDescription
	GinkgoRecover                         = ginkgo.GinkgoRecover
	GinkgoT                               = ginkgo.GinkgoT
	RunSpecs                              = ginkgo.RunSpecs
	RunSpecsWithCustomReporters           = ginkgo.RunSpecsWithCustomReporters
	RunSpecsWithDefaultAndCustomReporters = ginkgo.RunSpecsWithDefaultAndCustomReporters
	GinkgoWriter                          = NewWriter(ginkgo.GinkgoWriter)
)

type Done ginkgo.Done

func init() {
	// Only use the Ginkgo options and discard all other options
	args := []string{}
	for _, arg := range os.Args[1:] {
		if strings.Contains(arg, "--ginkgo") {
			args = append(args, arg)
		}
	}

	//Get GinkgoConfig flags
	commandFlags := flag.NewFlagSet("ginkgo", flag.ContinueOnError)
	commandFlags.SetOutput(new(bytes.Buffer))

	config.Flags(commandFlags, "ginkgo", true)
	commandFlags.Parse(args)
	ciliumTestConfig.CiliumTestConfig.ParseFlags()
}

func (s *scope) isUnset() bool {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return (s.counter == -1)
}

func (s *scope) isZero() bool {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return (s.counter == 0)
}

func (s *scope) setSafely(val int) {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.counter = int32(val)
}

func (s *scope) decrementSafely() {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.counter--
	if s.counter < 0 {
		panic(fmt.Sprintf("ERROR: unexpected negative scope counter value: %d", s.counter))
	}
}<commit_msg>test: make ginkgo run in verbose mode by default<commit_after>/*
 * Copyright 2018-2019 Authors of Cilium
 * Copyright 2017 Mirantis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ginkgoext

import (
	"bytes"
	"flag"
	"fmt"
	"os"
	"reflect"
	"regexp"
	"strings"
	"sync/atomic"
	"time"

	"github.com/cilium/cilium/pkg/lock"
	ciliumTestConfig "github.com/cilium/cilium/test/config"

	"github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/config"
)

type scope struct {
	parent        *scope
	children      []*scope
	counter       int32
	mutex         *lock.Mutex
	before        []func()
	after         []func()
	afterEach     []func()
	justAfterEach []func()
	afterFail     []func()
	started       int32
	failed        bool
	normalTests   int
	focusedTests  int
	focused       bool
	text          string
}

var (
	currentScope = &scope{
		text:    "EntireTestsuite",
		counter: -1,
		mutex:   &lock.Mutex{},
	}

	rootScope = currentScope

	// failEnabled for tests that have failed on JustAfterEach function we need
	// to handle differently, because `ginkgo.Fail` do a panic, and all the
	// following functions will not be called. With the WrapFailfn if the fail
	// is on any After function, will not panic, will mark the test as failed,
	// and will trigger the Fail function at the end.
	failEnabled     = true
	afterEachFailed = map[string]bool{}
	afterEachCB     = map[string]func(){}

	// We wrap various ginkgo function here to track invocations and determine
	// when to call AfterAll. When using a new ginkgo equivalent to It or
	// Measure, it may need a matching wrapper similar to wrapItFunc.

	Context                               = wrapContextFunc(ginkgo.Context, false)
	FContext                              = wrapContextFunc(ginkgo.FContext, true)
	PContext                              = wrapNilContextFunc(ginkgo.PContext)
	XContext                              = wrapNilContextFunc(ginkgo.XContext)
	Describe                              = wrapContextFunc(ginkgo.Describe, false)
	FDescribe                             = wrapContextFunc(ginkgo.FDescribe, true)
	PDescribe                             = wrapNilContextFunc(ginkgo.PDescribe)
	XDescribe                             = wrapNilContextFunc(ginkgo.XDescribe)
	It                                    = wrapItFunc(ginkgo.It, false)
	FIt                                   = wrapItFunc(ginkgo.FIt, true)
	PIt                                   = ginkgo.PIt
	XIt                                   = ginkgo.XIt
	Measure                               = wrapMeasureFunc(ginkgo.Measure, false)
	JustBeforeEach                        = ginkgo.JustBeforeEach
	BeforeSuite                           = ginkgo.BeforeSuite
	AfterSuite                            = ginkgo.AfterSuite
	Skip                                  = ginkgo.Skip
	Fail                                  = FailWithToggle
	CurrentGinkgoTestDescription          = ginkgo.CurrentGinkgoTestDescription
	GinkgoRecover                         = ginkgo.GinkgoRecover
	GinkgoT                               = ginkgo.GinkgoT
	RunSpecs                              = ginkgo.RunSpecs
	RunSpecsWithCustomReporters           = ginkgo.RunSpecsWithCustomReporters
	RunSpecsWithDefaultAndCustomReporters = ginkgo.RunSpecsWithDefaultAndCustomReporters
	GinkgoWriter                          = NewWriter(ginkgo.GinkgoWriter)
)

type Done ginkgo.Done

func init() {
	// Only use the Ginkgo options and discard all other options
	args := []string{}
	for _, arg := range os.Args[1:] {
		if strings.Contains(arg, "--ginkgo") {
			args = append(args, arg)
		}
	}

	//Get GinkgoConfig flags
	commandFlags := flag.NewFlagSet("ginkgo", flag.ContinueOnError)
	commandFlags.SetOutput(new(bytes.Buffer))

	config.Flags(commandFlags, "ginkgo", true)
	commandFlags.Parse(args)
	ciliumTestConfig.CiliumTestConfig.ParseFlags()

	if !config.DefaultReporterConfig.Succinct {
		config.DefaultReporterConfig.Verbose = true
	}
}

func (s *scope) isUnset() bool {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return (s.counter == -1)
}

func (s *scope) isZero() bool {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return (s.counter == 0)
}

func (s *scope) setSafely(val int) {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.counter = int32(val)
}

func (s *scope) decrementSafely() {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.counter--
	if s.counter < 0 {
		panic(fmt.Sprintf("ERROR: unexpected negative scope counter value: %d", s.counter))
	}
}
{'fraction_non_alphanumeric': 0.08753071253071253, 'fraction_numerical': 0.005528255528255528, 'mean_word_length': 2.2230287033982186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6169324', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2932, 'n_words': 796}