diff options
Diffstat (limited to 'NPTest.pm')
-rw-r--r-- | NPTest.pm | 53 |
1 files changed, 33 insertions, 20 deletions
@@ -44,23 +44,17 @@ default via the C<use NPTest;> statement. | |||
44 | 44 | ||
45 | =over | 45 | =over |
46 | 46 | ||
47 | =item C<getTestParameter(...)> | 47 | =item getTestParameter( "ENV_VARIABLE", $brief_description, $default ) |
48 | 48 | ||
49 | A flexible and user override-able method of collecting, storing and | 49 | This function allows the test harness |
50 | retrieving test parameters. This function allows the test harness | ||
51 | developer to interactively request test parameter information from the | 50 | developer to interactively request test parameter information from the |
52 | user, when the no means of obtaining the information automatically has | 51 | user. The user can accept the developer's default value or reply "none" |
53 | been successful. The user is provided with the option of accepting | 52 | which will then be returned as "" for the test to skip if appropriate. |
54 | test harness developer's default value for the parameter, if a suggested | 53 | |
55 | default is provided. | 54 | Responses are stored in an external, file-based |
56 | 55 | cache so subsequent test runs will use these values. The user is able | |
57 | User supplied responses are stored in an external (file-based) | 56 | to change the values by amending the values in the file /var/tmp/NPTest.pm, |
58 | cache. These values are retrieved on subsequent runs alleviating the | 57 | or by setting the appropriate environment variable before running the test. |
59 | user of reconfirming the previous entered responses. The user is able | ||
60 | to override the value of a parameter on any given run by setting the | ||
61 | associated environment variable. These environment variable based | ||
62 | overrides are not stored in the cache, allowing one-time and what-if | ||
63 | based tests on the command line without polluting the cache. | ||
64 | 58 | ||
65 | The option exists to store parameters in a scoped means, allowing a | 59 | The option exists to store parameters in a scoped means, allowing a |
66 | test harness to a localise a parameter should the need arise. This | 60 | test harness to a localise a parameter should the need arise. This |
@@ -73,7 +67,7 @@ called "check_disk.t" requesting the parameter "mountpoint_valid", the | |||
73 | cache is first searched for "check_disk"/"mountpoint_valid", if this | 67 | cache is first searched for "check_disk"/"mountpoint_valid", if this |
74 | fails, then a search is conducted for "mountpoint_valid". | 68 | fails, then a search is conducted for "mountpoint_valid". |
75 | 69 | ||
76 | The facilitate quick testing setup, it is possible to accept all the | 70 | To facilitate quick testing setup, it is possible to accept all the |
77 | developer provided defaults by setting the environment variable | 71 | developer provided defaults by setting the environment variable |
78 | "NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note | 72 | "NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note |
79 | that, such defaults are not stored in the cache, as there is currently | 73 | that, such defaults are not stored in the cache, as there is currently |
@@ -306,7 +300,16 @@ sub skipMissingCmd | |||
306 | 300 | ||
307 | sub getTestParameter | 301 | sub getTestParameter |
308 | { | 302 | { |
309 | my( $param, $envvar, $default, $brief, $scoped ) = @_; | 303 | my( $param, $envvar, $default, $brief, $scoped ); |
304 | my $new_style; | ||
305 | if (scalar @_ == 3) { | ||
306 | ($param, $brief, $default) = @_; | ||
307 | $envvar = $param; | ||
308 | $new_style = 1; | ||
309 | } else { | ||
310 | ( $param, $envvar, $default, $brief, $scoped ) = @_; | ||
311 | $new_style = 0; | ||
312 | } | ||
310 | 313 | ||
311 | # Apply default values for optional arguments | 314 | # Apply default values for optional arguments |
312 | $scoped = ( defined( $scoped ) && $scoped ); | 315 | $scoped = ( defined( $scoped ) && $scoped ); |
@@ -319,8 +322,13 @@ sub getTestParameter | |||
319 | } | 322 | } |
320 | 323 | ||
321 | my $cachedValue = SearchCache( $param, $testharness ); | 324 | my $cachedValue = SearchCache( $param, $testharness ); |
322 | if ( defined( $cachedValue ) && $cachedValue ) | 325 | if ( defined( $cachedValue ) ) |
323 | { | 326 | { |
327 | # This save required to convert to new style because the key required is | ||
328 | # changing to the environment variable | ||
329 | if ($new_style == 0) { | ||
330 | SetCacheParameter( $envvar, undef, $cachedValue ); | ||
331 | } | ||
324 | return $cachedValue; | 332 | return $cachedValue; |
325 | } | 333 | } |
326 | 334 | ||
@@ -339,9 +347,9 @@ sub getTestParameter | |||
339 | print STDERR "\n"; | 347 | print STDERR "\n"; |
340 | print STDERR "Test Harness : $testharness\n"; | 348 | print STDERR "Test Harness : $testharness\n"; |
341 | print STDERR "Test Parameter : $param\n"; | 349 | print STDERR "Test Parameter : $param\n"; |
342 | print STDERR "Environment Variable : $envvar\n"; | 350 | print STDERR "Environment Variable : $envvar\n" if ($param ne $envvar); |
343 | print STDERR "Brief Description : $brief\n"; | 351 | print STDERR "Brief Description : $brief\n"; |
344 | print STDERR "Enter value ", ($defaultValid ? "[${default}]" : "[]"), " => "; | 352 | print STDERR "Enter value (or 'none') ", ($defaultValid ? "[${default}]" : "[]"), " => "; |
345 | $userResponse = <STDIN>; | 353 | $userResponse = <STDIN>; |
346 | $userResponse = "" if ! defined( $userResponse ); # Handle EOF | 354 | $userResponse = "" if ! defined( $userResponse ); # Handle EOF |
347 | chomp( $userResponse ); | 355 | chomp( $userResponse ); |
@@ -353,6 +361,10 @@ sub getTestParameter | |||
353 | 361 | ||
354 | print STDERR "\n"; | 362 | print STDERR "\n"; |
355 | 363 | ||
364 | if ($userResponse =~ /^(na|none)$/) { | ||
365 | $userResponse = ""; | ||
366 | } | ||
367 | |||
356 | # define all user responses at global scope | 368 | # define all user responses at global scope |
357 | SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse ); | 369 | SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse ); |
358 | 370 | ||
@@ -378,6 +390,7 @@ sub SearchCache | |||
378 | { | 390 | { |
379 | return $CACHE{$param}; | 391 | return $CACHE{$param}; |
380 | } | 392 | } |
393 | return undef; # Need this to say "nothing found" | ||
381 | } | 394 | } |
382 | 395 | ||
383 | sub SetCacheParameter | 396 | sub SetCacheParameter |