<commit_before>import subprocess
import sys
import unittest

from test.util import ClangTest


def run(args):
    if hasattr(subprocess, 'run'):
        p = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, stderr = p.stdout.decode(), p.stderr.decode()
        return p, output, stderr
    else:
        p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1)
        output, stderr = p.communicate()
        return p, output, stderr


class InputOutput(ClangTest):
    def test_stdout_default(self):
        """run clang2py test/data/test-includes.h"""
        p, output, stderr = run(['clang2py', 'test/data/test-includes.h'])
        self.assertEqual(p.returncode, 0)
        self.assertIn("WORD_SIZE is:", output)

    def test_stdout_with_minus_sign(self):
        """run clang2py test/data/test-includes.h -o -"""
        p, output, stderr = run(['clang2py', 'test/data/test-includes.h', '-o', '-'])
        self.assertEqual(p.returncode, 0)
        self.assertIn("WORD_SIZE is:", output)

    def test_stdin_fail(self):
        """Support of stdin is on the TODO list"""
        # run cat  test/data/test-includes.h | clang2py -
        p, output, stderr = run(['clang2py', '-'])
        self.assertEqual(p.returncode, 1)
        self.assertIn("ValueError: stdin is not supported", stderr)

    def test_no_files(self):
        """run cat  test/data/test-includes.h | clang2py"""
        p, output, stderr = run(['clang2py', '-o', '/dev/null'])
        self.assertEqual(p.returncode, 2)
        if sys.version_info[0] < 3:
            self.assertIn("error: too few arguments", stderr) # py2
        else:
            self.assertIn("error: the following arguments are required", stderr)


class ArgumentInclude(ClangTest):
    def test_include_with(self):
        """run clang2py -i test/data/test-includes.h"""
        p, output, stderr = run(['clang2py', '-i', 'test/data/test-includes.h'])
        self.assertEqual(p.returncode, 0)
        # struct_name are defined in another include file
        self.assertIn("struct_Name", output)
        self.assertIn("struct_Name2", output)
        self.assertIn("struct_Name3", output)

    def test_include_without(self):<commit_msg>add a test case for multiple source files<commit_after>import subprocess
import sys
import unittest

from test.util import ClangTest


def run(args):
    if hasattr(subprocess, 'run'):
        p = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, stderr = p.stdout.decode(), p.stderr.decode()
        return p, output, stderr
    else:
        p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1)
        output, stderr = p.communicate()
        return p, output, stderr


class InputOutput(ClangTest):
    def test_stdout_default(self):
        """run clang2py test/data/test-includes.h"""
        p, output, stderr = run(['clang2py', 'test/data/test-includes.h'])
        self.assertEqual(p.returncode, 0)
        self.assertIn("WORD_SIZE is:", output)

    def test_stdout_with_minus_sign(self):
        """run clang2py test/data/test-includes.h -o -"""
        p, output, stderr = run(['clang2py', 'test/data/test-includes.h', '-o', '-'])
        self.assertEqual(p.returncode, 0)
        self.assertIn("WORD_SIZE is:", output)

    def test_stdin_fail(self):
        """Support of stdin is on the TODO list"""
        # run cat  test/data/test-includes.h | clang2py -
        p, output, stderr = run(['clang2py', '-'])
        self.assertEqual(p.returncode, 1)
        self.assertIn("ValueError: stdin is not supported", stderr)

    def test_no_files(self):
        """run cat  test/data/test-includes.h | clang2py"""
        p, output, stderr = run(['clang2py', '-o', '/dev/null'])
        self.assertEqual(p.returncode, 2)
        if sys.version_info[0] < 3:
            self.assertIn("error: too few arguments", stderr) # py2
        else:
            self.assertIn("error: the following arguments are required", stderr)

    def test_multiple_source_files(self):
        """run clang2py -i test/data/test-basic-types.c test/data/test-bitfield.c"""
        p, output, stderr = run(['clang2py', '-i', 'test/data/test-basic-types.c', 'test/data/test-bitfield.c'])
        self.assertEqual(p.returncode, 0)
        self.assertIn("WORD_SIZE is:", output)
        self.assertIn("_long = ", output)
        self.assertIn("my__quad_t ", output)
        self.assertIn("class struct_bytes4(", output)


class ArgumentInclude(ClangTest):
    def test_include_with(self):
        """run clang2py -i test/data/test-includes.h"""
        p, output, stderr = run(['clang2py', '-i', 'test/data/test-includes.h'])
        self.assertEqual(p.returncode, 0)
        # struct_name are defined in another include file
        self.assertIn("struct_Name", output)
        self.assertIn("struct_Name2", output)
        self.assertIn("struct_Name3", output)

    def test_include_without(self):
{'fraction_non_alphanumeric': 0.14162247102730308, 'fraction_numerical': 0.009035552936554704, 'mean_word_length': 2.9874706342991386, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6776507', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1643, 'n_words': 360}