<commit_before>/**
 * (C) Copyright 2013, Deft Labs
 *
 * 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 dlshared

import (
	"bytes"
	"testing"
)

func TestCmdExecWithMaxTimeNoWait(t *testing.T) {

	if killed, err := CmdExecWithMaxTime("uptime", 2000, nil, nil); err != nil || killed {
		t.Errorf("CmdExecWithMaxTime is broken:", err)
	}

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("uptime", 1000, &stdout, &stderr); err != nil || killed {
		t.Errorf("CmdExecWithMaxTime is broken: %v", err)
	}

	if stdout.Len() <= 0 {
		t.Errorf("CmdExecWithMaxTime is broken - no data in stdout")
	}

	if stderr.Len() > 0 {
		t.Errorf("CmdExecWithMaxTime is broken - data in stderr")
	}
}

func TestCmdExecWithMaxTimeWithWait(t *testing.T) {

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("test/exec_test.sh", 250, &stdout, &stderr); err != nil || !killed {
		t.Errorf("CmdExecWithMaxTime is broken: %v", err)
	}

	if stdout.Len() <= 0 {
		t.Errorf("CmdExecWithMaxTime is broken - no data in stdout")
	}

	if stderr.Len() > 0 {
		t.Errorf("CmdExecWithMaxTime is broken - data in stderr")
	}
}

func TestCmdExecWithMaxTimeWithBwmNg(t *testing.T) {

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("bwm-ng", 250, &stdout, &stderr); err != nil || !killed {
		t.Errorf("CmdExecWithMaxTime is broken %v", err)
	}

	if stdout.Len() <= 0 {
		t.Errorf("CmdExecWithMaxTime is broken - no data in stdout")
	}

	if stderr.Len() > 0 {
		t.Errorf("CmdExecWithMaxTime is broken - data in stderr")
	}
}

func TestCmdExecWithMaxTimeWithCat(t *testing.T) {

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("cat", 250, &stdout, &stderr, "/dev/urandom"); err != nil || !killed {
		t.Errorf("CmdExecWithMaxTime is broken: %v", err)
	}
<commit_msg>removed test for old cmd<commit_after>/**
 * (C) Copyright 2013, Deft Labs
 *
 * 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 dlshared

import (
	"bytes"
	"testing"
)

func TestCmdExecWithMaxTimeNoWait(t *testing.T) {

	if killed, err := CmdExecWithMaxTime("uptime", 2000, nil, nil); err != nil || killed {
		t.Errorf("CmdExecWithMaxTime is broken:", err)
	}

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("uptime", 1000, &stdout, &stderr); err != nil || killed {
		t.Errorf("CmdExecWithMaxTime is broken: %v", err)
	}

	if stdout.Len() <= 0 {
		t.Errorf("CmdExecWithMaxTime is broken - no data in stdout")
	}

	if stderr.Len() > 0 {
		t.Errorf("CmdExecWithMaxTime is broken - data in stderr")
	}
}

func TestCmdExecWithMaxTimeWithWait(t *testing.T) {

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("test/exec_test.sh", 250, &stdout, &stderr); err != nil || !killed {
		t.Errorf("CmdExecWithMaxTime is broken: %v", err)
	}

	if stdout.Len() <= 0 {
		t.Errorf("CmdExecWithMaxTime is broken - no data in stdout")
	}

	if stderr.Len() > 0 {
		t.Errorf("CmdExecWithMaxTime is broken - data in stderr")
	}
}

/*
func TestCmdExecWithMaxTimeWithBwmNg(t *testing.T) {

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("bwm-ng", 250, &stdout, &stderr); err != nil || !killed {
		t.Errorf("CmdExecWithMaxTime is broken %v", err)
	}

	if stdout.Len() <= 0 {
		t.Errorf("CmdExecWithMaxTime is broken - no data in stdout")
	}

	if stderr.Len() > 0 {
		t.Errorf("CmdExecWithMaxTime is broken - data in stderr")
	}
}
*/

func TestCmdExecWithMaxTimeWithCat(t *testing.T) {

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	if killed, err := CmdExecWithMaxTime("cat", 250, &stdout, &stderr, "/dev/urandom"); err != nil || !killed {
		t.Errorf("CmdExecWithMaxTime is broken: %v", err)
	}

{'fraction_non_alphanumeric': 0.12668743509865005, 'fraction_numerical': 0.012876427829698858, 'mean_word_length': 4.0535152151101785, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '63172', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1613, 'n_words': 518}