Skip to content

Commit

Permalink
New gtest tap file list mechanism
Browse files Browse the repository at this point in the history
Fixes epics-modules#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
  • Loading branch information
ralphlange committed Jan 3, 2025
1 parent bfec0b6 commit 5ac786c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 60 deletions.
2 changes: 1 addition & 1 deletion gtestSup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions gtestSup/RULES_GTEST
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <space>)
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
Expand Down
50 changes: 0 additions & 50 deletions gtestSup/makeFromList.pl

This file was deleted.

26 changes: 26 additions & 0 deletions gtestSup/testSuiteList.pl
Original file line number Diff line number Diff line change
@@ -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 <ralph.lange@gmx.de>
#
# testSuiteList.pl
#
# called from RULES_GTEST
#
# Usage: <test-exe-name> --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 = <STDIN>) {
if ($line =~ m/^[^[:space:]]*.$/) {
$line =~ s/.$//;
print $line;
}
}

0 comments on commit 5ac786c

Please sign in to comment.