@@ -7,18 +7,16 @@ CLOBBER.include(File.join(VALGRIND_BUILD_PATH, '**/*'))
77task directories : [ VALGRIND_BUILD_OUTPUT_PATH ]
88
99namespace VALGRIND_SYM do
10- task source_coverage : COLLECTION_ALL_SOURCE . pathmap ( "#{ VALGRIND_BUILD_OUTPUT_PATH } /%n#{ @ceedling [ :configurator ] . extension_object } " )
11-
1210 desc 'Run Valgrind for all tests'
13- task all : [ :test_deps ] do
11+ task all : [ :prepare ] do
1412 @ceedling [ :configurator ] . replace_flattened_config ( @ceedling [ VALGRIND_SYM ] . config )
1513 COLLECTION_ALL_TESTS . each do |test |
16- executable = @ceedling [ :file_path_utils ] . form_test_executable_filepath ( test )
14+ executable = @ceedling [ :file_path_utils ] . form_test_executable_filepath ( File . join ( VALGRIND_BUILD_OUTPUT_PATH , File . basename ( test , @ceedling [ :configurator ] . extension_source ) ) , test )
1715 command = @ceedling [ :tool_executor ] . build_command_line ( TOOLS_VALGRIND , [ ] , executable )
18- @ceedling [ :streaminator ] . stdout_puts ( "\n INFO: #{ command [ :line ] } \n \n " )
19- @ceedling [ :tool_executor ] . exec ( command [ :line ] , command [ :options ] )
16+ @ceedling [ :loginator ] . log ( "\n INFO: #{ command [ :line ] } \n \n " )
17+ shell_result = @ceedling [ :tool_executor ] . exec ( command )
18+ @ceedling [ :loginator ] . log ( "#{ shell_result [ :output ] } \n " )
2019 end
21- @ceedling [ :configurator ] . restore_config
2220 end
2321
2422 desc 'Run Valgrind for a single test or executable ([*] real test or source file name, no path).'
@@ -27,23 +25,71 @@ namespace VALGRIND_SYM do
2725 "Use a real test or source file name (no path) in place of the wildcard.\n " \
2826 "Example: rake #{ VALGRIND_ROOT_NAME } :foo.c\n \n "
2927
30- @ceedling [ :streaminator ] . stdout_puts ( message )
28+ @ceedling [ :loginator ] . log ( message , Verbosity :: ERRORS )
3129 end
3230
33- # use a rule to increase efficiency for large projects
34- # valgrind test tasks by regex
35- rule ( /^#{ VALGRIND_TASK_ROOT } \S +$/ => [
31+ desc 'Run Valgrind for tests by matching regular expression pattern.'
32+ task :pattern , [ :regex ] => [ :prepare ] do |_t , args |
33+ matches = [ ]
34+
35+ COLLECTION_ALL_TESTS . each do |test |
36+ matches << test if test =~ /#{ args . regex } /
37+ end
38+
39+ if !matches . empty?
40+ @ceedling [ :configurator ] . replace_flattened_config ( @ceedling [ VALGRIND_SYM ] . config )
41+ matches . each do |test |
42+ executable = @ceedling [ :file_path_utils ] . form_test_executable_filepath ( File . join ( VALGRIND_BUILD_OUTPUT_PATH , File . basename ( test , @ceedling [ :configurator ] . extension_source ) ) , test )
43+ command = @ceedling [ :tool_executor ] . build_command_line ( TOOLS_VALGRIND , [ ] , executable )
44+ @ceedling [ :loginator ] . log ( "\n INFO: #{ command [ :line ] } \n \n " )
45+ shell_result = @ceedling [ :tool_executor ] . exec ( command )
46+ @ceedling [ :loginator ] . log ( "#{ shell_result [ :output ] } \n " )
47+ end
48+ else
49+ @ceedling [ :loginator ] . log ( "\n Found no tests matching pattern /#{ args . regex } /." )
50+ end
51+ end
52+
53+ desc 'Run Valgrind for tests whose test path contains [dir] or [dir] substring.'
54+ task :path , [ :dir ] => [ :prepare ] do |_t , args |
55+ matches = [ ]
56+
57+ COLLECTION_ALL_TESTS . each do |test |
58+ matches << test if File . dirname ( test ) . include? ( args . dir . tr ( '\\' , '/' ) )
59+ end
60+
61+ if !matches . empty?
62+ @ceedling [ :configurator ] . replace_flattened_config ( @ceedling [ VALGRIND_SYM ] . config )
63+ matches . each do |test |
64+ executable = @ceedling [ :file_path_utils ] . form_test_executable_filepath ( File . join ( VALGRIND_BUILD_OUTPUT_PATH , File . basename ( test , @ceedling [ :configurator ] . extension_source ) ) , test )
65+ command = @ceedling [ :tool_executor ] . build_command_line ( TOOLS_VALGRIND , [ ] , executable )
66+ @ceedling [ :loginator ] . log ( "\n INFO: #{ command [ :line ] } \n \n " )
67+ shell_result = @ceedling [ :tool_executor ] . exec ( command )
68+ @ceedling [ :loginator ] . log ( "#{ shell_result [ :output ] } \n " )
69+ end
70+ else
71+ @ceedling [ :loginator ] . log ( 'Found no tests including the given path or path component' , Verbosity ::ERRORS )
72+ end
73+ end
74+
75+ # Use a rule to increase efficiency for large projects
76+ rule ( /^#{ VALGRIND_TASK_ROOT } \S +$/ => [ # valgrind test tasks by regex
3677 proc do |task_name |
37- test = task_name . sub ( /#{ VALGRIND_TASK_ROOT } / , '' )
38- test = "#{ PROJECT_TEST_FILE_PREFIX } #{ test } " unless test . start_with? ( PROJECT_TEST_FILE_PREFIX )
39- @ceedling [ :file_finder ] . find_test_from_file_path ( test )
78+ # Yield clean test name => Strip the task string, remove Rake test task prefix, and remove any code file extension
79+ test = task_name . strip ( ) . sub ( /^#{ VALGRIND_TASK_ROOT } / , '' ) . chomp ( EXTENSION_SOURCE )
80+
81+ # Ensure the test name begins with a test name prefix
82+ test = PROJECT_TEST_FILE_PREFIX + test if not ( test . start_with? ( PROJECT_TEST_FILE_PREFIX ) )
83+
84+ # Provide the filepath for the target test task back to the Rake task
85+ @ceedling [ :file_finder ] . find_test_file_from_name ( test )
4086 end
41- ] ) do test
87+ ] ) do | test |
4288 @ceedling [ :configurator ] . replace_flattened_config ( @ceedling [ VALGRIND_SYM ] . config )
43- executable = @ceedling [ :file_path_utils ] . form_test_executable_filepath ( test . source )
89+ executable = @ceedling [ :file_path_utils ] . form_test_executable_filepath ( File . join ( VALGRIND_BUILD_OUTPUT_PATH , File . basename ( test . source , @ceedling [ :configurator ] . extension_source ) ) , test . source )
4490 command = @ceedling [ :tool_executor ] . build_command_line ( TOOLS_VALGRIND , [ ] , executable )
45- @ceedling [ :streaminator ] . stdout_puts ( "\n INFO: #{ command [ :line ] } \n \n " )
46- @ceedling [ :tool_executor ] . exec ( command [ :line ] , command [ :options ] )
47- @ceedling [ :configurator ] . restore_config
91+ @ceedling [ :loginator ] . log ( "\n INFO: #{ command [ :line ] } \n \n " )
92+ shell_result = @ceedling [ :tool_executor ] . exec ( command )
93+ @ceedling [ :loginator ] . log ( " #{ shell_result [ :output ] } \n " )
4894 end
49- end
95+ end
0 commit comments