<commit_before>package main

import (
	"io/ioutil"
	"log"
	"strings"
	"testing"
	"time"
)

func init() {
	// Discard default log output
	log.SetOutput(ioutil.Discard)
}

func TestRateValidation(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, output := defaultArguments()
	rate = 0

	err := run(rate, duration, targetsf, ordering, reporter, output)
	if err == nil || (err != nil && !strings.HasPrefix(err.Error(), errRatePrefix)) {
		t.Errorf("Rate 0 shouldn't be valid: %s", err)
	}
}

func TestDurationValidation(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, output := defaultArguments()
	duration = 0

	err := run(rate, duration, targetsf, ordering, reporter, output)
	if err == nil || (err != nil && !strings.HasPrefix(err.Error(), errDurationPrefix)) {
		t.Errorf("Duration 0 shouldn't be valid: %s", err)
	}
}

func TestOutputValidation(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, _ := defaultArguments()

	// Good cases
	for _, output := range []string{"stdout", "/dev/null"} {
		err := run(rate, duration, targetsf, ordering, reporter, output)
		if err != nil {
			t.Errorf("Output file `%s` should be valid: %s", output, err)
		}
	}

	// Bad case
	badOutput := ""
	err := run(rate, duration, targetsf, ordering, reporter, badOutput)
	if err == nil || (err != nil && !strings.HasPrefix(err.Error(), errOutputFilePrefix)) {
		t.Errorf("Output file `%s` shouldn't be valid: %s", badOutput, err)
	}
}

func TestReporter(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, output := defaultArguments()

	err := run(rate, duration, targetsf, ordering, reporter, output)
	if err != nil {
		t.Errorf("Reporter shouldn't return an error: %s", err)
	}<commit_msg>Add plot:timings CLI test<commit_after>package main

import (
	"io/ioutil"
	"log"
	"strings"
	"testing"
	"time"
)

func init() {
	// Discard default log output
	log.SetOutput(ioutil.Discard)
}

func TestRateValidation(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, output := defaultArguments()
	rate = 0

	err := run(rate, duration, targetsf, ordering, reporter, output)
	if err == nil || (err != nil && !strings.HasPrefix(err.Error(), errRatePrefix)) {
		t.Errorf("Rate 0 shouldn't be valid: %s", err)
	}
}

func TestDurationValidation(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, output := defaultArguments()
	duration = 0

	err := run(rate, duration, targetsf, ordering, reporter, output)
	if err == nil || (err != nil && !strings.HasPrefix(err.Error(), errDurationPrefix)) {
		t.Errorf("Duration 0 shouldn't be valid: %s", err)
	}
}

func TestOutputValidation(t *testing.T) {
	rate, duration, targetsf, ordering, reporter, _ := defaultArguments()

	// Good cases
	for _, output := range []string{"stdout", "/dev/null"} {
		err := run(rate, duration, targetsf, ordering, reporter, output)
		if err != nil {
			t.Errorf("Output file `%s` should be valid: %s", output, err)
		}
	}

	// Bad case
	badOutput := ""
	err := run(rate, duration, targetsf, ordering, reporter, badOutput)
	if err == nil || (err != nil && !strings.HasPrefix(err.Error(), errOutputFilePrefix)) {
		t.Errorf("Output file `%s` shouldn't be valid: %s", badOutput, err)
	}
}

func TestReporter(t *testing.T) {
	rate, duration, targetsf, ordering, _, output := defaultArguments()

	for _, reporter := range []string{"text", "plot:timings"} {
		err := run(rate, duration, targetsf, ordering, reporter, output)
		if err != nil {
			t.Errorf("Reporter `%s` shouldn't return an error: %s", reporter, err)
		}
	}
{'fraction_non_alphanumeric': 0.16185625353706848, 'fraction_numerical': 0.0022637238256932655, 'mean_word_length': 4.549450549450549, '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': '6664454', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1164, 'n_words': 347}