<commit_before>// Copyright 2019 Google Inc. All Rights Reserved.
// This file is available under the Apache license.

package testutil

import (
	"flag"
	"testing"
)

// TestSetFlag sets the value of the commandline flag, and returns a cleanup function that restores the flag value.
func TestSetFlag(tb testing.TB, name, value string) func() {
	tb.Helper()
	val := flag.Lookup(name)

	if err := flag.Set(name, value); err != nil {
		tb.Fatal(err)
	}
	flag.Parse()

	return func() {
		if val != nil {
			if err := flag.Set(name, val.Value.String()); err != nil {
				tb.Fatal(err)
			}
		}
	}
}
<commit_msg>No need to parse the commandline args a second time.<commit_after>// Copyright 2019 Google Inc. All Rights Reserved.
// This file is available under the Apache license.

package testutil

import (
	"flag"
	"testing"
)

// TestSetFlag sets the value of the commandline flag, and returns a cleanup function that restores the flag value.
func TestSetFlag(tb testing.TB, name, value string) func() {
	tb.Helper()
	val := flag.Lookup(name)

	if err := flag.Set(name, value); err != nil {
		tb.Fatal(err)
	}

	return func() {
		if val != nil {
			if err := flag.Set(name, val.Value.String()); err != nil {
				tb.Fatal(err)
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.1275221953188055, 'fraction_numerical': 0.00645682001614205, 'mean_word_length': 3.335664335664336, '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': '4479658', 'n_tokens_mistral': 443, 'n_tokens_neox': 404, 'n_words': 146}