From 5ac786c988bb25c2d968f0dd7b76993317fa5f43 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Fri, 3 Jan 2025 16:49:55 +0100 Subject: [PATCH] New gtest tap file list mechanism Fixes #2: - does not use makefile snippets (which were adding test execution to the build) - tap file lists are created when running the tests - 'tapfiles' target directly depends on test run in case tests have not been run yet --- gtestSup/Makefile | 2 +- gtestSup/RULES_GTEST | 25 +++++++++++++------- gtestSup/makeFromList.pl | 50 --------------------------------------- gtestSup/testSuiteList.pl | 26 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 60 deletions(-) delete mode 100644 gtestSup/makeFromList.pl create mode 100644 gtestSup/testSuiteList.pl diff --git a/gtestSup/Makefile b/gtestSup/Makefile index 3b04522..263b69b 100644 --- a/gtestSup/Makefile +++ b/gtestSup/Makefile @@ -12,7 +12,7 @@ LIBRARY_HOST += epics_gtest_main epics_gtest_main_SRCS += gtest_main.cc epics_gtest_main_LIBS += gmock gtest -PERL_SCRIPTS += makeFromList.pl +PERL_SCRIPTS += testSuiteList.pl CFG += RULES_GTEST CFG += compat.RULES_BUILD diff --git a/gtestSup/RULES_GTEST b/gtestSup/RULES_GTEST index 46f02d2..f18b88a 100644 --- a/gtestSup/RULES_GTEST +++ b/gtestSup/RULES_GTEST @@ -28,26 +28,33 @@ endif #--------------------------------------------------------------- # Automated testing using Google Test -GTESTS_MAKE = $(addsuffix .make,$(GTESTS)) GTESTS_RUN = $(addsuffix .run,$(GTESTS)) .PHONY: $(GTESTS_RUN) runtests: $(GTESTS_RUN) -$(GTESTLISTS): %.list: %$(EXE) - @$(RM) $@ - "./$<" --gtest_list_tests > $@ - -$(GTESTS_MAKE): %.make: %.list - @$(RM) $@ - @$(PERL) $(GTEST_BIN)/makeFromList.pl $* +define gtest_run_template +$$($(1)_TAPFILES) $(1)-results.xml: $(1).run + @: +$(1).run: export GTEST_TAP_FILENAME_PREFIX=$(1)- +$(1).run: $(1)$$(EXE) + @$$(ECHO) "Running test $(1)..." + @"./$$<" --gtest_list_tests | $$(PERL) $$(GTEST_BIN)/testSuiteList.pl > $(1).list + @"./$$<" --gtest_output_tap --gtest_color=yes --gtest_output=xml:$(1)-results.xml + @$$(ECHO) "test run" > $(1).run +$(1)_TAPFILES = $(addprefix $(1)-,$(addsuffix .tap,$(file < $(gtest).list))) +CLEANS += $(1).run $(1).list +endef -include $(GTESTS_MAKE) +$(foreach gtest, $(GTESTS), $(eval $(call gtest_run_template,$(gtest)))) # Can't do "undefine TAPFILES" so only define TAPFILES here if non-empty # (avoid old test-results rule breaking for TAPFILES = ) ifneq ($(strip $(foreach gtest, $(GTESTS), $($(gtest)_TAPFILES))),) TAPFILES += $(foreach gtest, $(GTESTS), $($(gtest)_TAPFILES)) +else +# If gtest TAPFILES don't exist (tests didn't run yet), run the tests +tapfiles: $(GTESTS_RUN) endif else diff --git a/gtestSup/makeFromList.pl b/gtestSup/makeFromList.pl deleted file mode 100644 index 985a1ce..0000000 --- a/gtestSup/makeFromList.pl +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env perl -#*************************************************************************\ -#* Copyright (c) 2020 ITER Organization. -#* This module is distributed subject to a Software License Agreement found -#* in file LICENSE that is included with this distribution. -#*************************************************************************/ -# -# Author: Ralph Lange -# -# makeFromList.pl -# -# called from RULES_GTEST -# -# Usage: perl makeFromList -# reads --gtest_list_tests output from file .list -# and creates Makefile snippet .make - -$gtest = $ARGV[0]; -$testlist = "$gtest.list"; -$maketestlist = "$gtest.make"; - -open IN, "< $testlist" - or die "$0: Can't open $testlist, $!\n"; - -open OUT, "> $maketestlist" - or die "$0: Can't create $maketestlist, $!\n"; -print OUT "#This Makefile created by makeFromList.pl\n\n"; - -my @taps; -while( my $line = ) { - if ($line =~ m/^[^[:space:]]*.$/) { - $line =~ s/.$//; - chomp($line); - push @taps, "$gtest-$line.tap" - } -} - -print OUT "${gtest}_TAPFILES += ", join(' ', @taps), "\n"; -print OUT "\$(${gtest}_TAPFILES) ${gtest}-results.xml: .$gtest.run\n"; -print OUT "\t\@:\n"; -print OUT "$gtest.run .$gtest.run: export GTEST_TAP_FILENAME_PREFIX=$gtest-\n"; -print OUT "$gtest.run .$gtest.run: $gtest\$(EXE)\n"; -print OUT "\t\$(ECHO) \"Running test $gtest...\"\n"; -print OUT "\t\@\"./\$<\" --gtest_output_tap --gtest_color=yes --gtest_output=xml:$gtest-results.xml\n"; -print OUT "\t\@echo \"test run\" > .$gtest.run\n"; - -close IN; -close OUT; - -# EOF makeFromList.pl diff --git a/gtestSup/testSuiteList.pl b/gtestSup/testSuiteList.pl new file mode 100644 index 0000000..ab7c3f2 --- /dev/null +++ b/gtestSup/testSuiteList.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +#*************************************************************************\ +#* Copyright (c) 2025 ITER Organization. +#* This module is distributed subject to a Software License Agreement found +#* in file LICENSE that is included with this distribution. +#*************************************************************************/ +# +# Author: Ralph Lange +# +# testSuiteList.pl +# +# called from RULES_GTEST +# +# Usage: --gtest_list_tests | perl testSuiteList.pl +# returns the names of reported test suites (lines ending in dot) +# +# Put in a minimal script as the appearance of '$' characters +# inside a 'perl -e' expression cannot be written inside a Makefile +# in a way that is portable between Windows (bash, command.com) and Linux + +while (my $line = ) { + if ($line =~ m/^[^[:space:]]*.$/) { + $line =~ s/.$//; + print $line; + } +}