<commit_before>#!/usr/bin/python

import argparse
import os
import os.path
import re
import sys
import subprocess
import time

"""
replacement for runtest target in Makefile
arg 1:  test dir or test file
"""

testsfx = "_test.cpp"

def stop_err( msg, returncode ):
    sys.stderr.write( '%s\n' % msg )
    sys.stderr.write( 'exit now ( %s)\n' % time.strftime('%x %X %Z'))
    sys.exit(returncode)

def doCommand(command):
    p1 = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    (sout,serr) = p1.communicate()
    if (sout != None):
        sys.stdout.write(sout.decode())
    if (serr != None):
        sys.stderr.write(serr.decode())
    if (not(p1.returncode == None) and not(p1.returncode == 0)):
        stop_err('%s failed' % command, p1.returncode)

def generateTests(j):
    command = 'make -j%d generate-tests -s' % j
    print(command)
    doCommand(command)

def makeTest( name, j ):
    name = name.replace("src/","",1)
    name = name.replace(testsfx,"");
    command = 'make -j%d %s' % (j,name)
    print(command)
    doCommand(command)
    
def makeTests( dirname, filenames, j ):
    dirname = dirname.replace("src/","",1)
    targets = list()
    for name in filenames:
        if (name.endswith(testsfx)):
            target = name.replace(testsfx,"");
            targets.append(os.sep.join([dirname,target]))
    command = 'make -j%d %s' % (j,' '.join(targets))
    print(command)
    doCommand(command)

    
def runTest( name ):
    name = name.replace("src/","",1)
    name = name.replace(testsfx,"");
    print(name)
    doCommand(name)


    
def main():
    if (len(sys.argv) < 2):
        useage()

    j = 1
    start = 1
    if (sys.argv[1].startswith("-j")):
        start = 2
        if (len(sys.argv) < 3):
            useage()
        else:
            j = sys.argv[1].replace("-j","")
            try:
                jprime = int(j)
                if (jprime < 1 or jprime > 16):
                    stop_err("bad value for -j flag",-1)                    <commit_msg>added usage message to runTests.py<commit_after>#!/usr/bin/python

import argparse
import os
import os.path
import re
import sys
import subprocess
import time

"""
replacement for runtest target in Makefile
arg 1:  test dir or test file
"""

testsfx = "_test.cpp"

def usage():
    sys.stdout.write('usage: %s <path/test/dir(/files)>\n' % sys.argv[0])
    sys.stdout.write('or\n')
    sys.stdout.write('       %s -j<#cores> <path/test/dir(/files)>\n' % sys.argv[0])
    sys.exit(0)

def stop_err( msg, returncode ):
    sys.stderr.write( '%s\n' % msg )
    sys.stderr.write( 'exit now ( %s)\n' % time.strftime('%x %X %Z'))
    sys.exit(returncode)

def doCommand(command):
    p1 = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    (sout,serr) = p1.communicate()
    if (sout != None):
        sys.stdout.write(sout.decode())
    if (serr != None):
        sys.stderr.write(serr.decode())
    if (not(p1.returncode == None) and not(p1.returncode == 0)):
        stop_err('%s failed' % command, p1.returncode)

def generateTests(j):
    command = 'make -j%d generate-tests -s' % j
    print(command)
    doCommand(command)

def makeTest( name, j ):
    name = name.replace("src/","",1)
    name = name.replace(testsfx,"");
    command = 'make -j%d %s' % (j,name)
    doCommand(command)
    
def makeTests( dirname, filenames, j ):
    dirname = dirname.replace("src/","",1)
    targets = list()
    for name in filenames:
        if (name.endswith(testsfx)):
            target = name.replace(testsfx,"");
            targets.append(os.sep.join([dirname,target]))
    if (len(targets) > 0):
        command = 'make -j%d %s' % (j,' '.join(targets))
        print(command)
        doCommand(command)
    
def runTest( name ):
    name = name.replace("src/","",1)
    name = name.replace(testsfx,"");
    print(name)
    doCommand(name)


    
def main():
    if (len(sys.argv) < 2):
        usage()

    j = 1
    start = 1
    if (sys.argv[1].startswith("-j")):
        start = 2
        if (len(sys.argv) < 3):
            usage()
        else:
            j = sys.argv[1].replace("-j","")
            try:
                jprime = int(j)
                if (jprime < 1 or jprime > 16):
                    stop_err("bad value for -j flag",-1)                    
{'fraction_non_alphanumeric': 0.1655918931368033, 'fraction_numerical': 0.010594196222938737, 'mean_word_length': 2.395621579358874, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, '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': '2581704', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1518, 'n_words': 347}