<commit_before>package functionalTests.processbuilder.test;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.objectweb.proactive.extensions.processbuilder.OSProcessBuilder;
import org.objectweb.proactive.extensions.processbuilder.OSProcessBuilderFactory;
import org.objectweb.proactive.extensions.processbuilder.OSRuntime;
import org.objectweb.proactive.extensions.processbuilder.OSUser;
import org.objectweb.proactive.extensions.processbuilder.exception.OSUserException;
import org.objectweb.proactive.extensions.processbuilder.stream.LineReader;


public class WindowsAndLinuxTester {
    final static boolean isLinux = System.getProperty("os.name").toLowerCase().startsWith("linux");

    // Modify these to fit your environment
    OSUser user = new OSUser(System.getenv("OSPB_TEST_USER"));
    OSUser userWPass = new OSUser(System.getenv("OSPB_TEST_USER"), System.getenv("OSPB_TEST_PASS"));
    String tempPath = (System.getenv("OSPB_TEST_TEMP"));

    /*
     * It is assumed that the user given for testing purposes can both sudo and su into an other
     * user.
     */

    // ------------------------------------ 
    @Test
    public void fallTroughIfNoUser() {
        String[] lc = { "/bin/sh", "-c", "echo 111 && (echo 222 >&2)" };
        String[] wc = { "cmd.exe", "/c", "@(echo 111)&&(echo 222>&2)" };
        String[] cmd = (isLinux) ? lc : wc;
        File dir = null;
        HashMap<String, String> env = null;

        String[] expectedOut = { "111" };
        String[] expectedErr = { "222" };

        try {
            runAndMatch(cmd, null, dir, env, expectedOut, expectedErr, 0);
        } catch (Exception e) {
            assertNull(e.getMessage(), e);
        }

    }

    @Test
    public void OutAndErrorChannelsExist() {
        String[] lc = { "/bin/sh", "-c", "echo 111 && (echo 222 >&2)" };
        String[] wc = { "cmd.exe", "/c", "@(echo 111)&& (echo 222>&2)" };
        String[] cmd = (isLinux) ? lc : wc;
        File dir = null;
        HashMap<String, String> env = null;

        String[] expectedOut = { "111" };
        String[] expectedErr = { "222" };

        try {<commit_msg>PROACTIVE-910: Avoid to run process build tests is the environment is not configured<commit_after>package functionalTests.processbuilder.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.proactive.core.ProActiveException;
import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
import org.objectweb.proactive.extensions.processbuilder.OSProcessBuilder;
import org.objectweb.proactive.extensions.processbuilder.OSProcessBuilderFactory;
import org.objectweb.proactive.extensions.processbuilder.OSRuntime;
import org.objectweb.proactive.extensions.processbuilder.OSUser;
import org.objectweb.proactive.extensions.processbuilder.exception.OSUserException;
import org.objectweb.proactive.extensions.processbuilder.stream.LineReader;

import functionalTests.FunctionalTest;


public class WindowsAndLinuxTester extends FunctionalTest {
    final static boolean isLinux = System.getProperty("os.name").toLowerCase().startsWith("linux");

    // Modify these to fit your environment
    OSUser user;
    OSUser userWPass;
    String tempPath;

    /*
     * It is assumed that the user given for testing purposes can both sudo and su into an other
     * user.
     */

    // ------------------------------------ 
    @Before
    public void shouldRun() throws ProActiveException {

        String suser = System.getenv("OSPB_TEST_USER");
        Assume.assumeNotNull(suser, "process builder not tested because OSPB_TEST_USER is not set");
        user = new OSUser(System.getenv("OSPB_TEST_USER"));

        String pass = System.getenv("OSPB_TEST_PASS");
        Assume.assumeNotNull(pass, "process builder not tested because OSPB_TEST_PASS is not set");
        userWPass = new OSUser(suser, pass);

        tempPath = System.getenv("OSPB_TEST_TEMP");
        Assume.assumeNotNull(tempPath, "process builder not tested because OSPB_TEST_TEMP is not set");

        if (isLinux) {
            String paHome = ProActiveRuntimeImpl.getProActiveRuntime().getProActiveHome();
            File s32 = new File(paHome, "dist/scripts/processbuilder/linux/suer32");
            File s64 = new File(paHome, "dist/scripts/processbuilder/linux/suer64");
            Assume.assumeTrue(s32.exists() || s64.exists());
        }
    }

    @Test
    public void fallTroughIfNoUser() {
        String[] lc = { "/bin/sh", "-c", "echo 111 && (echo 222 >&2)" };
        String[] wc = { "cmd.exe", "/c", "@(echo 111)&&(echo 222>&2)" };
        String[] cmd = (isLinux) ? lc : wc;
        File dir = null;
        HashMap<String, String> env = null;

        String[] expectedOut = { "111" };
        String[] expectedErr = { "222" };

        try {
            runAndMatch(cmd, null, dir, env, expectedOut, expectedErr, 0);
        } catch (Exception e) {
            assertNull(e.getMessage(), e);
        }

    }

    @Test
    public void OutAndErrorChannelsExist() {
        String[] lc = { "/bin/sh", "-c", "echo 111 && (echo 222 >&2)" };
        String[] wc = { "cmd.exe", "/c", "@(echo 111)&& (echo 222>&2)" };
        String[] cmd = (isLinux) ? lc : wc;
        File dir = null;
        HashMap<String, String> env = null;

        String[] expectedOut = { "111" };
        String[] expectedErr = { "222" };

        try {
{'fraction_non_alphanumeric': 0.1393470212049815, 'fraction_numerical': 0.016324469875462808, 'mean_word_length': 3.0705479452054796, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '140906', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1753, 'n_words': 432}