diff options
| author | Martin Hořeňovský | 2019-12-06 11:53:31 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-12-06 11:53:31 +0100 |
| commit | 91ee07e08c5a72536834960ecf2527fa90244046 (patch) | |
| tree | ee7bf0251c746a50e6e871cf00ea52baf9ed44ec /tools | |
| parent | 6eb04667ad4f571f20b040c5e7a4e0c25e99787c (diff) | |
| download | catch3-91ee07e08c5a72536834960ecf2527fa90244046.tar.gz | |
Moved scripts/ to tools/scripts/
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/scripts/approvalTests.py | 215 | ||||
| -rwxr-xr-x | tools/scripts/approve.py | 33 | ||||
| -rwxr-xr-x | tools/scripts/benchmarkCompile.py | 148 | ||||
| -rwxr-xr-x | tools/scripts/benchmarkRunner.py | 56 | ||||
| -rwxr-xr-x | tools/scripts/developBuild.py | 10 | ||||
| -rw-r--r-- | tools/scripts/embed.py | 63 | ||||
| -rwxr-xr-x | tools/scripts/embedClara.py | 27 | ||||
| -rw-r--r-- | tools/scripts/extractFeaturesFromReleaseNotes.py | 94 | ||||
| -rwxr-xr-x | tools/scripts/fixWhitespace.py | 52 | ||||
| -rwxr-xr-x | tools/scripts/generateSingleHeader.py | 129 | ||||
| -rwxr-xr-x | tools/scripts/majorRelease.py | 10 | ||||
| -rwxr-xr-x | tools/scripts/minorRelease.py | 10 | ||||
| -rwxr-xr-x | tools/scripts/patchRelease.py | 10 | ||||
| -rw-r--r-- | tools/scripts/releaseCommon.py | 166 | ||||
| -rwxr-xr-x | tools/scripts/releaseNotes.py | 65 | ||||
| -rw-r--r-- | tools/scripts/scriptCommon.py | 31 | ||||
| -rw-r--r-- | tools/scripts/updateDocumentToC.py | 449 | ||||
| -rw-r--r-- | tools/scripts/updateWandbox.py | 47 |
18 files changed, 1615 insertions, 0 deletions
diff --git a/tools/scripts/approvalTests.py b/tools/scripts/approvalTests.py new file mode 100755 index 00000000..18a34959 --- /dev/null +++ b/tools/scripts/approvalTests.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import io +import os +import sys +import subprocess +import re +import difflib + +import scriptCommon +from scriptCommon import catchPath + +if os.name == 'nt': + # Enable console colours on windows + os.system('') + +rootPath = os.path.join(catchPath, 'tests/SelfTest/Baselines') + +langFilenameParser = re.compile(r'(.+\.[ch]pp)') +filelocParser = re.compile(r''' + .*/ + (.+\.[ch]pp) # filename + (?::|\() # : is starting separator between filename and line number on Linux, ( on Windows + ([0-9]*) # line number + \)? # Windows also has an ending separator, ) +''', re.VERBOSE) +lineNumberParser = re.compile(r' line="[0-9]*"') +hexParser = re.compile(r'\b(0[xX][0-9a-fA-F]+)\b') +durationsParser = re.compile(r' time="[0-9]*\.[0-9]*"') +sonarqubeDurationParser = re.compile(r' duration="[0-9]+"') +timestampsParser = re.compile(r'\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z') +versionParser = re.compile(r'Catch v[0-9]+\.[0-9]+\.[0-9]+(-develop\.[0-9]+)?') +nullParser = re.compile(r'\b(__null|nullptr)\b') +exeNameParser = re.compile(r''' + \b + (CatchSelfTest|SelfTest) # Expected executable name + (?:.exe)? # Executable name contains .exe on Windows. + \b +''', re.VERBOSE) +# This is a hack until something more reasonable is figured out +specialCaseParser = re.compile(r'file\((\d+)\)') + +# errno macro expands into various names depending on platform, so we need to fix them up as well +errnoParser = re.compile(r''' + \(\*__errno_location\ \(\)\) + | + \(\*__error\(\)\) + | + \(\*_errno\(\)\) +''', re.VERBOSE) +sinceEpochParser = re.compile(r'\d+ .+ since epoch') +infParser = re.compile(r''' + \(\(float\)\(1e\+300\ \*\ 1e\+300\)\) # MSVC INFINITY macro + | + \(__builtin_inff\(\)\) # Linux (ubuntu) INFINITY macro + | + \(__builtin_inff\ \(\)\) # Fedora INFINITY macro + | + __builtin_huge_valf\(\) # OSX macro +''', re.VERBOSE) +nanParser = re.compile(r''' + \(\(float\)\(\(\(float\)\(1e\+300\ \*\ 1e\+300\)\)\ \*\ 0\.0F\)\) # MSVC NAN macro + | + \(\(float\)\(INFINITY\ \*\ 0\.0F\)\) # Yet another MSVC NAN macro + | + \(__builtin_nanf\ \(""\)\) # Linux (ubuntu) NAN macro + | + __builtin_nanf\("0x<hex\ digits>"\) # The weird content of the brackets is there because a different parser has already ran before this one +''', re.VERBOSE) + + +if len(sys.argv) == 2: + cmdPath = sys.argv[1] +else: + cmdPath = os.path.join(catchPath, scriptCommon.getBuildExecutable()) + +overallResult = 0 + + +def diffFiles(fileA, fileB): + with io.open(fileA, 'r', encoding='utf-8', errors='surrogateescape') as file: + aLines = [line.rstrip() for line in file.readlines()] + with io.open(fileB, 'r', encoding='utf-8', errors='surrogateescape') as file: + bLines = [line.rstrip() for line in file.readlines()] + + shortenedFilenameA = fileA.rsplit(os.sep, 1)[-1] + shortenedFilenameB = fileB.rsplit(os.sep, 1)[-1] + + diff = difflib.unified_diff(aLines, bLines, fromfile=shortenedFilenameA, tofile=shortenedFilenameB, n=0) + return [line for line in diff if line[0] in ('+', '-')] + + +def normalizeFilepath(line): + if catchPath in line: + # make paths relative to Catch root + line = line.replace(catchPath + os.sep, '') + + m = langFilenameParser.match(line) + if m: + filepath = m.group(0) + # go from \ in windows paths to / + filepath = filepath.replace('\\', '/') + # remove start of relative path + filepath = filepath.replace('../', '') + line = line[:m.start()] + filepath + line[m.end():] + + return line + +def filterLine(line, isCompact): + line = normalizeFilepath(line) + + # strip source line numbers + m = filelocParser.match(line) + if m: + # note that this also strips directories, leaving only the filename + filename, lnum = m.groups() + lnum = ":<line number>" if lnum else "" + line = filename + lnum + line[m.end():] + else: + line = lineNumberParser.sub(" ", line) + + if isCompact: + line = line.replace(': FAILED', ': failed') + line = line.replace(': PASSED', ': passed') + + # strip Catch version number + line = versionParser.sub("<version>", line) + + # replace *null* with 0 + line = nullParser.sub("0", line) + + # strip executable name + line = exeNameParser.sub("<exe-name>", line) + + # strip hexadecimal numbers (presumably pointer values) + line = hexParser.sub("0x<hex digits>", line) + + # strip durations and timestamps + line = durationsParser.sub(' time="{duration}"', line) + line = sonarqubeDurationParser.sub(' duration="{duration}"', line) + line = timestampsParser.sub('{iso8601-timestamp}', line) + line = specialCaseParser.sub('file:\g<1>', line) + line = errnoParser.sub('errno', line) + line = sinceEpochParser.sub('{since-epoch-report}', line) + line = infParser.sub('INFINITY', line) + line = nanParser.sub('NAN', line) + return line + + +def approve(baseName, args): + global overallResult + args[0:0] = [cmdPath] + if not os.path.exists(cmdPath): + raise Exception("Executable doesn't exist at " + cmdPath) + baselinesPath = os.path.join(rootPath, '{0}.approved.txt'.format(baseName)) + rawResultsPath = os.path.join(rootPath, '_{0}.tmp'.format(baseName)) + filteredResultsPath = os.path.join(rootPath, '{0}.unapproved.txt'.format(baseName)) + + f = open(rawResultsPath, 'w') + subprocess.call(args, stdout=f, stderr=f) + f.close() + + rawFile = io.open(rawResultsPath, 'r', encoding='utf-8', errors='surrogateescape') + filteredFile = io.open(filteredResultsPath, 'w', encoding='utf-8', errors='surrogateescape') + for line in rawFile: + filteredFile.write(filterLine(line, 'compact' in baseName).rstrip() + "\n") + filteredFile.close() + rawFile.close() + + os.remove(rawResultsPath) + print() + print(baseName + ":") + if os.path.exists(baselinesPath): + diffResult = diffFiles(baselinesPath, filteredResultsPath) + if diffResult: + print('\n'.join(diffResult)) + print(" \n****************************\n \033[91mResults differed") + if len(diffResult) > overallResult: + overallResult = len(diffResult) + else: + os.remove(filteredResultsPath) + print(" \033[92mResults matched") + print("\033[0m") + else: + print(" first approval") + if overallResult == 0: + overallResult = 1 + + +print("Running approvals against executable:") +print(" " + cmdPath) + + +# ## Keep default reporters here ## +# Standard console reporter +approve("console.std", ["~[!nonportable]~[!benchmark]~[approvals] *", "--order", "lex", "--rng-seed", "1"]) +# console reporter, include passes, warn about No Assertions +approve("console.sw", ["~[!nonportable]~[!benchmark]~[approvals] *", "-s", "-w", "NoAssertions", "--order", "lex", "--rng-seed", "1"]) +# console reporter, include passes, warn about No Assertions, limit failures to first 4 +approve("console.swa4", ["~[!nonportable]~[!benchmark]~[approvals] *", "-s", "-w", "NoAssertions", "-x", "4", "--order", "lex", "--rng-seed", "1"]) +# junit reporter, include passes, warn about No Assertions +approve("junit.sw", ["~[!nonportable]~[!benchmark]~[approvals] *", "-s", "-w", "NoAssertions", "-r", "junit", "--order", "lex", "--rng-seed", "1"]) +# xml reporter, include passes, warn about No Assertions +approve("xml.sw", ["~[!nonportable]~[!benchmark]~[approvals] *", "-s", "-w", "NoAssertions", "-r", "xml", "--order", "lex", "--rng-seed", "1"]) +# compact reporter, include passes, warn about No Assertions +approve('compact.sw', ['~[!nonportable]~[!benchmark]~[approvals] *', '-s', '-w', 'NoAssertions', '-r', 'compact', '--order', 'lex', "--rng-seed", "1"]) +# sonarqube reporter, include passes, warn about No Assertions +approve("sonarqube.sw", ["~[!nonportable]~[!benchmark]~[approvals] *", "-s", "-w", "NoAssertions", "-r", "sonarqube", "--order", "lex", "--rng-seed", "1"]) + + +if overallResult != 0: + print("If these differences are expected, run approve.py to approve new baselines.") +exit(overallResult) diff --git a/tools/scripts/approve.py b/tools/scripts/approve.py new file mode 100755 index 00000000..252d08ec --- /dev/null +++ b/tools/scripts/approve.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import os +import sys +import shutil +import glob +from scriptCommon import catchPath + +rootPath = os.path.join( catchPath, 'tests/SelfTest/Baselines' ) + +if len(sys.argv) > 1: + files = [os.path.join( rootPath, f ) for f in sys.argv[1:]] +else: + files = glob.glob( os.path.join( rootPath, "*.unapproved.txt" ) ) + + +def approveFile( approvedFile, unapprovedFile ): + justFilename = unapprovedFile[len(rootPath)+1:] + if os.path.exists( unapprovedFile ): + if os.path.exists( approvedFile ): + os.remove( approvedFile ) + os.rename( unapprovedFile, approvedFile ) + print( "approved " + justFilename ) + else: + print( "approval file " + justFilename + " does not exist" ) + +if files: + for unapprovedFile in files: + approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile ) +else: + print( "no files to approve" ) diff --git a/tools/scripts/benchmarkCompile.py b/tools/scripts/benchmarkCompile.py new file mode 100755 index 00000000..586c26ac --- /dev/null +++ b/tools/scripts/benchmarkCompile.py @@ -0,0 +1,148 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import time, subprocess, sys, os, shutil, glob, random +import argparse + +def median(lst): + lst = sorted(lst) + mid, odd = divmod(len(lst), 2) + if odd: + return lst[mid] + else: + return (lst[mid - 1] + lst[mid]) / 2.0 + +def mean(lst): + return float(sum(lst)) / max(len(lst), 1) + +compiler_path = '' +flags = [] + +main_file = r''' +#define CATCH_CONFIG_MAIN +#include "catch.hpp" +''' +main_name = 'catch-main.cpp' + +dir_name = 'benchmark-dir' + +files = 20 +test_cases_in_file = 20 +sections_in_file = 4 +assertions_per_section = 5 + +checks = [ + 'a != b', 'a != c', 'a != d', 'a != e', 'b != c', 'b != d', 'b != e', 'c != d', 'c != e', 'd != e', 'a + a == a', + 'a + b == b', 'a + c == c', 'a + d == d', 'a + e == e', 'b + a == b', 'b + b == c', 'b + c == d', + 'b + d == e', 'c + a == c', 'c + b == d', 'c + c == e', 'd + a == d', 'd + b == e', 'e + a == e', + 'a + a + a == a', 'b + c == a + d', 'c + a + a == a + b + b + a', + 'a < b', 'b < c', 'c < d', 'd < e', 'a >= a', 'd >= b', +] + +def create_temp_dir(): + if os.path.exists(dir_name): + shutil.rmtree(dir_name) + os.mkdir(dir_name) + +def copy_catch(path_to_catch): + shutil.copy(path_to_catch, dir_name) + +def create_catch_main(): + with open(main_name, 'w') as f: + f.write(main_file) + +def compile_main(): + start_t = time.time() + subprocess.check_call([compiler_path, main_name, '-c'] + flags) + end_t = time.time() + return end_t - start_t + +def compile_files(): + cpp_files = glob.glob('tests*.cpp') + start_t = time.time() + subprocess.check_call([compiler_path, '-c'] + flags + cpp_files) + end_t = time.time() + return end_t - start_t + +def link_files(): + obj_files = glob.glob('*.o') + start_t = time.time() + subprocess.check_call([compiler_path] + flags + obj_files) + end_t = time.time() + return end_t - start_t + +def benchmark(func): + results = [func() for i in range(10)] + return mean(results), median(results) + +def char_range(start, end): + for c in range(ord(start), ord(end)): + yield chr(c) + +def generate_sections(fd): + for i in range(sections_in_file): + fd.write(' SECTION("Section {}") {{\n'.format(i)) + fd.write('\n'.join(' CHECK({});'.format(check) for check in random.sample(checks, assertions_per_section))) + fd.write(' }\n') + + +def generate_file(file_no): + with open('tests{}.cpp'.format(file_no), 'w') as f: + f.write('#include "catch.hpp"\n\n') + for i in range(test_cases_in_file): + f.write('TEST_CASE("File {} test {}", "[.compile]"){{\n'.format(file_no, i)) + for i, c in enumerate(char_range('a', 'f')): + f.write(' int {} = {};\n'.format(c, i)) + generate_sections(f) + f.write('}\n\n') + + +def generate_files(): + create_catch_main() + for i in range(files): + generate_file(i) + + +options = ['all', 'main', 'files', 'link'] + +parser = argparse.ArgumentParser(description='Benchmarks Catch\'s compile times against some synthetic tests') +# Add first arg -- benchmark type +parser.add_argument('benchmark_kind', nargs='?', default='all', choices=options, help='What kind of benchmark to run, default: all') + +# Args to allow changing header/compiler +parser.add_argument('-I', '--catch-header', default='catch.hpp', help = 'Path to catch.hpp, default: catch.hpp') +parser.add_argument('-c', '--compiler', default='g++', help = 'Compiler to use, default: g++') + +parser.add_argument('-f', '--flags', help = 'Flags to be passed to the compiler. Pass as "," separated list') + +# Allow creating files only, without running the whole thing +parser.add_argument('-g', '--generate-files', action='store_true', help='Generate test files and quit') + +args = parser.parse_args() + +compiler_path = args.compiler +catch_path = args.catch_header + +if args.generate_files: + create_temp_dir() + copy_catch(catch_path) + os.chdir(dir_name) + # now create the fake test files + generate_files() + # Early exit + print('Finished generating files') + exit(1) + +os.chdir(dir_name) + +if args.flags: + flags = args.flags.split(',') + +print('Time needed for ...') +if args.benchmark_kind in ('all', 'main'): + print(' ... compiling main, mean: {:.2f}, median: {:.2f} s'.format(*benchmark(compile_main))) +if args.benchmark_kind in ('all', 'files'): + print(' ... compiling test files, mean: {:.2f}, median: {:.2f} s'.format(*benchmark(compile_files))) +if args.benchmark_kind in ('all', 'link'): + print(' ... linking everything, mean: {:.2f}, median: {:.2f} s'.format(*benchmark(link_files))) diff --git a/tools/scripts/benchmarkRunner.py b/tools/scripts/benchmarkRunner.py new file mode 100755 index 00000000..dc753cf0 --- /dev/null +++ b/tools/scripts/benchmarkRunner.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +import subprocess, os, sys +import xml.etree.ElementTree as ET +from collections import defaultdict +from statistics import median, stdev +from datetime import datetime + +def get_commit_hash(): + res = subprocess.run('git rev-parse HEAD'.split(), check=True, stdout=subprocess.PIPE, universal_newlines=True) + return res.stdout.strip() + +if len(sys.argv) < 2: + print('Usage: {} benchmark-binary'.format(sys.argv[0])) + exit(1) + + +num_runs = 10 +data = defaultdict(list) + + +def parse_file(file): + + def recursive_search(node): + if node.tag == 'TestCase': + results = node.find('OverallResult') + time = results.get('durationInSeconds') + data[node.get('name')].append(float(time)) + elif node.tag in ('Group', 'Catch'): + for child in node: + recursive_search(child) + + tree = ET.parse(file) + recursive_search(tree.getroot()) + +def run_benchmarks(binary): + call = [binary] + '-d yes -r xml -o'.split() + for i in range(num_runs): + file = 'temp{}.xml'.format(i) + print('Run number {}'.format(i)) + subprocess.run(call + [file]) + parse_file(file) + # Remove file right after parsing, because benchmark output can be big + os.remove(file) + + +# Run benchmarks +run_benchmarks(sys.argv[1]) + +result_file = '{:%Y-%m-%dT%H-%M-%S}-{}.result'.format(datetime.now(), get_commit_hash()) + + +print('Writing results to {}'.format(result_file)) +with open(result_file, 'w') as file: + for k in sorted(data): + file.write('{}: median: {} (s), stddev: {} (s)\n'.format(k, median(data[k]), stdev(data[k]))) diff --git a/tools/scripts/developBuild.py b/tools/scripts/developBuild.py new file mode 100755 index 00000000..a8115fe2 --- /dev/null +++ b/tools/scripts/developBuild.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +from __future__ import print_function +import releaseCommon + +v = releaseCommon.Version() +v.incrementBuildNumber() +releaseCommon.performUpdates(v) + +print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) ) diff --git a/tools/scripts/embed.py b/tools/scripts/embed.py new file mode 100644 index 00000000..66757033 --- /dev/null +++ b/tools/scripts/embed.py @@ -0,0 +1,63 @@ +import re + +preprocessorRe = re.compile( r'\s*#.*' ) + +fdefineRe = re.compile( r'\s*#\s*define\s*(\S*)\s*\(' ) # #defines that take arguments +defineRe = re.compile( r'\s*#\s*define\s*(\S*)(\s+)(.*)' ) # all #defines +undefRe = re.compile( r'\s*#\s*undef\s*(\S*)' ) # all #undefs + +ifdefCommonRe = re.compile( r'\s*#\s*if' ) # all #ifdefs +ifdefRe = re.compile( r'\s*#\s*ifdef\s*(\S*)' ) +ifndefRe = re.compile( r'\s*#\s*ifndef\s*(\S*)' ) +endifRe = re.compile( r'\s*#\s*endif\s*//\s*(.*)' ) +elseRe = re.compile( r'\s*#\s*else' ) +ifRe = re.compile( r'\s*#\s*if\s+(.*)' ) + +nsRe = re.compile( r'(.*?\s*\s*namespace\s+)(\w+)(\s*{?)(.*)' ) +nsCloseRe = re.compile( r'(.*\s*})(\s*\/\/\s*namespace\s+)(\w+)(\s*)(.*)' ) + + +class LineMapper: + def __init__( self, idMap, outerNamespace ): + self.idMap = idMap + self.outerNamespace = outerNamespace + + # TBD: + # #if, #ifdef, comments after #else + def mapLine( self, lineNo, line ): + for idFrom, idTo in self.idMap.items(): + r = re.compile("(.*)" + idFrom + "(.*)") + + m = r.match( line ) + if m: + line = m.group(1) + idTo + m.group(2) + "\n" + + m = nsCloseRe.match( line ) + if m: + originalNs = m.group(3) + # print("[{0}] originalNs: '{1}' - closing".format(lineNo, originalNs)) + # print( " " + line ) + # print( " 1:[{0}]\n 2:[{1}]\n 3:[{2}]\n 4:[{3}]\n 5:[{4}]".format( m.group(1), m.group(2), m.group(3), m.group(4), m.group(5) ) ) + if originalNs in self.outerNamespace: + outerNs, innerNs = self.outerNamespace[originalNs] + return "{0}}}{1}{2}::{3}{4}{5}\n".format( m.group(1), m.group(2), outerNs, innerNs, m.group(4), m.group(5)) + m = nsRe.match( line ) + if m: + originalNs = m.group(2) + # print("[{0}] originalNs: '{1}'".format(lineNo, originalNs)) + # print( " " + line ) + # print( " 1:[{0}]\n 2:[{1}]\n 3:[{2}]\n 4:[{3}]".format( m.group(1), m.group(2), m.group(3), m.group(4) ) ) + if originalNs in self.outerNamespace: + outerNs, innerNs = self.outerNamespace[originalNs] + return "{0}{1} {{ namespace {2}{3}{4}\n".format( m.group(1), outerNs, innerNs, m.group(3), m.group(4) ) + + return line + + def mapFile(self, filenameIn, filenameOut ): + print( "Embedding:\n {0}\nas:\n {1}".format( filenameIn, filenameOut ) ) + with open( filenameIn, 'r' ) as f, open( filenameOut, 'w' ) as outf: + lineNo = 1 + for line in f: + outf.write( self.mapLine( lineNo, line ) ) + lineNo = lineNo + 1 + print( "Written {0} lines".format( lineNo ) )
\ No newline at end of file diff --git a/tools/scripts/embedClara.py b/tools/scripts/embedClara.py new file mode 100755 index 00000000..7ceb3e32 --- /dev/null +++ b/tools/scripts/embedClara.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +# Execute this script any time you import a new copy of Clara into the third_party area +import os +import sys +import embed + +rootPath = os.path.dirname(os.path.realpath( os.path.dirname(sys.argv[0]))) + +filename = os.path.join( rootPath, "third_party", "clara.hpp" ) +outfilename = os.path.join( rootPath, "include", "external", "clara.hpp" ) + + +# Mapping of pre-processor identifiers +idMap = { + "CLARA_HPP_INCLUDED": "CATCH_CLARA_HPP_INCLUDED", + "CLARA_CONFIG_CONSOLE_WIDTH": "CATCH_CLARA_CONFIG_CONSOLE_WIDTH", + "CLARA_TEXTFLOW_HPP_INCLUDED": "CATCH_CLARA_TEXTFLOW_HPP_INCLUDED", + "CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH": "CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH", + "CLARA_PLATFORM_WINDOWS": "CATCH_PLATFORM_WINDOWS" + } + +# outer namespace to add +outerNamespace = { "clara": ("Catch", "clara") } + +mapper = embed.LineMapper( idMap, outerNamespace ) +mapper.mapFile( filename, outfilename )
\ No newline at end of file diff --git a/tools/scripts/extractFeaturesFromReleaseNotes.py b/tools/scripts/extractFeaturesFromReleaseNotes.py new file mode 100644 index 00000000..090f4772 --- /dev/null +++ b/tools/scripts/extractFeaturesFromReleaseNotes.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python + +# +# extractFeaturesFromReleaseNotes.py +# +# Read the release notes - docs/release-notes.md - and generate text +# for pasting in to individual documentation pages, to indicate which +# versions recent features were released in. +# +# Using the output of the file is easier than manually constructing +# the text to paste in to documentation pages. +# +# One way to use this: +# - run this script, saving the output to some temporary file +# - diff this output with the actual release notes page +# - the differences are Markdown text that can be pasted in to the +# appropriate documentation pages in the docs/ directory. +# - each release also has a github link to show which documentation files +# were changed in it. +# This can be helpful to see which documentation pages +# to add the 'Introduced in Catch ...' snippets to the relevant pages. +# + +from __future__ import print_function + +import re + + +def create_introduced_in_text(version, bug_number = None): + """Generate text to paste in to documentation file""" + if bug_number: + return '> [Introduced](https://github.com/catchorg/Catch2/issues/%s) in Catch %s.' % (bug_number, version) + else: + # Use this text for changes that don't have issue numbers + return '> Introduced in Catch %s.' % version + + +def link_to_changes_in_release(release, releases): + """ + Markdown text for a hyperlink showing all edits in a release, or empty string + + :param release: A release version, as a string + :param releases: A container of releases, in descending order - newest to oldest + :return: Markdown text for a hyperlink showing the differences between the give release and the prior one, + or empty string, if the previous release is not known + """ + + if release == releases[-1]: + # This is the earliest release we know about + return '' + index = releases.index(release) + previous_release = releases[index + 1] + return '\n[Changes in %s](https://github.com/catchorg/Catch2/compare/v%s...v%s)' % (release, previous_release, release) + + +def write_recent_release_notes_with_introduced_text(): + current_version = None + release_toc_regex = r'\[(\d.\d.\d)\]\(#\d+\)<br>' + issue_number_regex = r'#[0-9]+' + releases = [] + with open('../docs/release-notes.md') as release_notes: + for line in release_notes: + line = line[:-1] + print(line) + + # Extract version number from table of contents + match = re.search(release_toc_regex, line) + if match: + release_name = match.group(1) + releases.append(release_name) + + if line.startswith('## '): + # It's a section with version number + current_version = line.replace('## ', '') + + # We decided not to add released-date info for older versions + if current_version == 'Older versions': + break + + print(create_introduced_in_text(current_version)) + print(link_to_changes_in_release(current_version, releases)) + + # Not yet found a version number, so to avoid picking up hyperlinks to + # version numbers in the index, keep going + if not current_version: + continue + + for bug_link in re.findall(issue_number_regex, line): + bug_number = bug_link.replace('#', '') + print(create_introduced_in_text(current_version, bug_number)) + + +if __name__ == '__main__': + write_recent_release_notes_with_introduced_text() diff --git a/tools/scripts/fixWhitespace.py b/tools/scripts/fixWhitespace.py new file mode 100755 index 00000000..bfa4aa08 --- /dev/null +++ b/tools/scripts/fixWhitespace.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +from __future__ import print_function +import os +from scriptCommon import catchPath + +def isSourceFile( path ): + return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" ) + +def fixAllFilesInDir( dir ): + changedFiles = 0 + for f in os.listdir( dir ): + path = os.path.join( dir,f ) + if os.path.isfile( path ): + if isSourceFile( path ): + if fixFile( path ): + changedFiles += 1 + else: + fixAllFilesInDir( path ) + return changedFiles + +def fixFile( path ): + f = open( path, 'r' ) + lines = [] + changed = 0 + for line in f: + trimmed = line.rstrip() + "\n" + trimmed = trimmed.replace('\t', ' ') + if trimmed != line: + changed = changed +1 + lines.append( trimmed ) + f.close() + if changed > 0: + global changedFiles + changedFiles = changedFiles + 1 + print( path + ":" ) + print( " - fixed " + str(changed) + " line(s)" ) + altPath = path + ".backup" + os.rename( path, altPath ) + f2 = open( path, 'w' ) + for line in lines: + f2.write( line ) + f2.close() + os.remove( altPath ) + return True + return False + +changedFiles = fixAllFilesInDir(catchPath) +if changedFiles > 0: + print( "Fixed " + str(changedFiles) + " file(s)" ) +else: + print( "No trailing whitespace found" ) diff --git a/tools/scripts/generateSingleHeader.py b/tools/scripts/generateSingleHeader.py new file mode 100755 index 00000000..f8968774 --- /dev/null +++ b/tools/scripts/generateSingleHeader.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import os +import io +import sys +import re +import datetime +from glob import glob + +from scriptCommon import catchPath + +def generate(v): + includesParser = re.compile( r'\s*#\s*include\s*"(.*)"' ) + guardParser = re.compile( r'\s*#.*(TWOBLUECUBES_)?CATCH_.*_INCLUDED') + defineParser = re.compile( r'\s*#define\s+(TWOBLUECUBES_)?CATCH_.*_INCLUDED') + ifParser = re.compile( r'\s*#ifndef (TWOBLUECUBES_)?CATCH_.*_INCLUDED') + endIfParser = re.compile( r'\s*#endif // (TWOBLUECUBES_)?CATCH_.*_INCLUDED') + ifImplParser = re.compile( r'\s*#ifdef CATCH_CONFIG_RUNNER' ) + commentParser1 = re.compile( r'^\s*/\*') + commentParser2 = re.compile( r'^ \*') + blankParser = re.compile( r'^\s*$') + + seenHeaders = set([]) + rootPath = os.path.join( catchPath, 'include/' ) + outputPath = os.path.join( catchPath, 'single_include/catch2/catch.hpp' ) + + globals = { + 'includeImpl' : True, + 'ifdefs' : 0, + 'implIfDefs' : -1 + } + + for arg in sys.argv[1:]: + arg = arg.lower() + if arg == "noimpl": + globals['includeImpl'] = False + print( "Not including impl code" ) + else: + print( "\n** Unrecognised argument: " + arg + " **\n" ) + exit(1) + + + # ensure that the output directory exists (hopefully no races) + outDir = os.path.dirname(outputPath) + if not os.path.exists(outDir): + os.makedirs(outDir) + out = io.open( outputPath, 'w', newline='\n', encoding='utf-8') + + def write( line ): + if globals['includeImpl'] or globals['implIfDefs'] == -1: + out.write( line ) + + def insertCpps |