def test_detectExactSpecifiedCompilerCommand(): """Using -c option, check that lines are recognized correctly""" inputFileName = 'dummy' parsedArgs = ccj_make.mkccj_parse_args( ['progname', inputFileName, '-c', 'mastadon']) if not parsedArgs: assert False if ccj_make.mkccj_process_line( parsedArgs, {}, [], "mastadons are not bluefish -Itheentireseas"): assert False if not ccj_make.mkccj_process_line( parsedArgs, {}, [], "mastadon are not bluefish -Itheentireseas"): assert False if ccj_make.mkccj_process_line( parsedArgs, {}, [], "mastadon-gcc mastadon.c -D_THIS_ -D_THAT_ -fno-dependent-clauses-or-santa-clauses-either" ): assert False bigString = "/opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-g++ -DCONFIG_ARCH_BOARD_PX4_FMU_V5 -D__CUSTOM_FILE_IO__ -D__DF_NUTTX -D__PX4_NUTTX -D__STDC_FORMAT_MACROS -isystem ../../platforms/nuttx/NuttX/include/cxx -isystem NuttX/nuttx/include/cxx -isystem NuttX/nuttx/include -I../../boards/px4/fmu-v5/src -I../../platforms/nuttx/src/px4/common/include -I. -Isrc -Isrc/lib -Isrc/modules -I../../platforms/nuttx/src/px4/stm/stm32f7/include -I../../platforms/common/include -I../../src -I../../src/include -I../../src/lib -I../../src/lib/DriverFramework/framework/include -I../../src/lib/matrix -I../../src/modules -I../../src/platforms -INuttX/nuttx/arch/arm/src/armv7-m -INuttX/nuttx/arch/arm/src/chip -INuttX/nuttx/arch/arm/src/common -INuttX/apps/include -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -Os -DNDEBUG -g -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -include visibility.h -Wall -Wextra -Werror -Warray-bounds -Wcast-align -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -fdiagnostics-color=always -fno-builtin-printf -fno-strength-reduce -Wformat=1 -Wunused-but-set-variable -Wno-format-truncation -fcheck-new -fno-exceptions -fno-rtti -fno-threadsafe-statics -Wreorder -Wno-overloaded-virtual -nostdinc++ -std=gnu++11 -o msg/CMakeFiles/uorb_msgs.dir/topics_sources/uORBTopics.cpp.obj -c /home/langrind/Firmware/build/px4_fmu-v5_multicopter/msg/topics_sources/uORBTopics.cpp" if ccj_make.mkccj_process_line(parsedArgs, {}, [], bigString): assert False assert True
def test_detectExactSpecifiedCompilerCommandWord(): """Using -c option, check that the exact word is recognized""" inputFileName = 'dummy' parsedArgs = ccj_make.mkccj_parse_args( ['progname', inputFileName, '-c', 'mastadon']) if not parsedArgs: assert False # Note that we are basically testing "strcmp()" here. A different test is used # to check a whole line of input if not ccj_make.mkccj_is_compiler_command(parsedArgs, "mastadon"): assert False if ccj_make.mkccj_is_compiler_command(parsedArgs, "Mastadon"): assert False if ccj_make.mkccj_is_compiler_command(parsedArgs, "Mastadon"): assert False if ccj_make.mkccj_is_compiler_command(parsedArgs, "mastadon++"): assert False if ccj_make.mkccj_is_compiler_command(parsedArgs, "astadon"): assert False assert True
def test_detectCompilerWord(): """Not using -c option, check that plausible compiler commands are recognized""" inputFileName = 'dummy' parsedArgs = ccj_make.mkccj_parse_args(['progname', inputFileName]) if not parsedArgs: assert False # Note that we are basically testing a regexp single-word match. A different test # is used to check a whole line of input if not ccj_make.mkccj_is_compiler_command(parsedArgs, "gcc"): assert False if not ccj_make.mkccj_is_compiler_command(parsedArgs, "mastadon-gcc"): assert False if not ccj_make.mkccj_is_compiler_command(parsedArgs, "Mastadon-c++"): assert False if not ccj_make.mkccj_is_compiler_command(parsedArgs, "gcc"): assert False if not ccj_make.mkccj_is_compiler_command(parsedArgs, "c++"): assert False if not ccj_make.mkccj_is_compiler_command(parsedArgs, "g++"): assert False if ccj_make.mkccj_is_compiler_command(parsedArgs, "mastadon++"): assert False if ccj_make.mkccj_is_compiler_command(parsedArgs, "mastadon"): assert False assert True
def test_parseArgs(): """provide one positional argument, succeeds""" input_file = 'foo.txt' parsedArgs = ccj_make.mkccj_parse_args(['progname', input_file]) if not parsedArgs: assert False if parsedArgs.input_file != input_file: assert False assert True
def test_parseNoArgs(): """If you don't provide one positional argument, parsing fails""" parsedArgs = None try: parsedArgs = ccj_make.mkccj_parse_args(['progname']) except: pass if parsedArgs: assert False assert True
def test_parseOptionalArgs(): """Check optional parameters""" input_file = 'foo.txt' parsedArgs = ccj_make.mkccj_parse_args(['progname', '-e', 'compile_commands.json', '-o', 'compile_commands.json', input_file]) if not parsedArgs: assert False if parsedArgs.existing != 'compile_commands.json': assert False if parsedArgs.output != 'compile_commands.json': assert False assert True
def test_readInput(): """read an empty file, get nothing""" inputFileName = 'tests/emptyBuild.txt' parsedArgs = ccj_make.mkccj_parse_args(['progname', inputFileName]) if not parsedArgs: assert False jsonList, xrefDict = ccj_make.mkccj_convert_input_file(parsedArgs) if jsonList: assert False if xrefDict: assert False assert True
def test_readExistingAndEmptyInput(): """read an empty file, but produce a dictionary because we start with an existing dict""" inputFileName = 'tests/emptyBuild.txt' parsedArgs = ccj_make.mkccj_parse_args( ['progname', inputFileName, '-e', 'tests/existing.json']) if not parsedArgs: assert False outputList, crossRefDict = ccj_make.mkccj_read_existing_json(parsedArgs) if not outputList: assert False if not crossRefDict: assert False record = outputList[0] if not record: assert False outputFile = 'tests/out.json' if os.path.exists(outputFile): os.remove(outputFile) if (os.path.exists(outputFile)): assert False with open(outputFile, "w") as outfile: print(json.dumps(record, indent=2), file=outfile) if os.path.exists(outputFile): os.remove(outputFile) if (os.path.exists(outputFile)): assert False # Check that the crossRefDictionary and the List are coherent for record in outputList: if record is not crossRefDict[record['file']]: assert False assert True