Fossil SCM
Minor style and comment cleanup. Add verify_all_options() to several TH1 test commands. Add 'test-th-source' test command, with test.
Commit
f141fbeac5d923217477673b04e3ac9ba5f7d61e
Parent
8e9cdd242c60ecd…
2 files changed
+48
-3
+17
+48
-3
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -2291,11 +2291,11 @@ | ||
| 2291 | 2291 | ** --http Include an HTTP response header in the output |
| 2292 | 2292 | ** --open-config Open the configuration database |
| 2293 | 2293 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2294 | 2294 | */ |
| 2295 | 2295 | void test_th_render(void){ |
| 2296 | - int forceCgi = 0, fullHttpReply = 0; | |
| 2296 | + int forceCgi, fullHttpReply; | |
| 2297 | 2297 | Blob in; |
| 2298 | 2298 | Th_InitTraceLog(); |
| 2299 | 2299 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2300 | 2300 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2301 | 2301 | if( fullHttpReply ) forceCgi = 1; |
| @@ -2318,11 +2318,11 @@ | ||
| 2318 | 2318 | ** COMMAND: test-th-eval |
| 2319 | 2319 | ** |
| 2320 | 2320 | ** Usage: %fossil test-th-eval SCRIPT |
| 2321 | 2321 | ** |
| 2322 | 2322 | ** Evaluate SCRIPT as if it were a header or footer or ticket rendering |
| 2323 | -** script, evaluate it, and show the results on standard output. | |
| 2323 | +** script and show the results on standard output. | |
| 2324 | 2324 | ** |
| 2325 | 2325 | ** Options: |
| 2326 | 2326 | ** |
| 2327 | 2327 | ** --cgi Include a CGI response header in the output |
| 2328 | 2328 | ** --http Include an HTTP response header in the output |
| @@ -2339,15 +2339,59 @@ | ||
| 2339 | 2339 | if( fullHttpReply ) forceCgi = 1; |
| 2340 | 2340 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2341 | 2341 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2342 | 2342 | Th_OpenConfig(1); |
| 2343 | 2343 | } |
| 2344 | + verify_all_options(); | |
| 2344 | 2345 | if( g.argc!=3 ){ |
| 2345 | 2346 | usage("script"); |
| 2346 | 2347 | } |
| 2347 | 2348 | Th_FossilInit(TH_INIT_DEFAULT); |
| 2348 | 2349 | rc = Th_Eval(g.interp, 0, g.argv[2], -1); |
| 2350 | + zRc = Th_ReturnCodeName(rc, 1); | |
| 2351 | + fossil_print("%s%s%s\n", zRc, zRc ? ": " : "", Th_GetResult(g.interp, 0)); | |
| 2352 | + Th_PrintTraceLog(); | |
| 2353 | + if( forceCgi ) cgi_reply(); | |
| 2354 | +} | |
| 2355 | + | |
| 2356 | +/* | |
| 2357 | +** COMMAND: test-th-source | |
| 2358 | +** | |
| 2359 | +** Usage: %fossil test-th-source FILE | |
| 2360 | +** | |
| 2361 | +** Evaluate the contents of the file named "FILE" as if it were a header | |
| 2362 | +** or footer or ticket rendering script and show the results on standard | |
| 2363 | +** output. | |
| 2364 | +** | |
| 2365 | +** Options: | |
| 2366 | +** | |
| 2367 | +** --cgi Include a CGI response header in the output | |
| 2368 | +** --http Include an HTTP response header in the output | |
| 2369 | +** --open-config Open the configuration database | |
| 2370 | +** --th-trace Trace TH1 execution (for debugging purposes) | |
| 2371 | +*/ | |
| 2372 | +void test_th_source(void){ | |
| 2373 | + int rc; | |
| 2374 | + const char *zRc; | |
| 2375 | + int forceCgi, fullHttpReply; | |
| 2376 | + Blob in; | |
| 2377 | + Th_InitTraceLog(); | |
| 2378 | + forceCgi = find_option("cgi", 0, 0)!=0; | |
| 2379 | + fullHttpReply = find_option("http", 0, 0)!=0; | |
| 2380 | + if( fullHttpReply ) forceCgi = 1; | |
| 2381 | + if( forceCgi ) Th_ForceCgi(fullHttpReply); | |
| 2382 | + if( find_option("open-config", 0, 0)!=0 ){ | |
| 2383 | + Th_OpenConfig(1); | |
| 2384 | + } | |
| 2385 | + verify_all_options(); | |
| 2386 | + if( g.argc!=3 ){ | |
| 2387 | + usage("file"); | |
| 2388 | + } | |
| 2389 | + blob_zero(&in); | |
| 2390 | + blob_read_from_file(&in, g.argv[2]); | |
| 2391 | + Th_FossilInit(TH_INIT_DEFAULT); | |
| 2392 | + rc = Th_Eval(g.interp, 0, blob_str(&in), -1); | |
| 2349 | 2393 | zRc = Th_ReturnCodeName(rc, 1); |
| 2350 | 2394 | fossil_print("%s%s%s\n", zRc, zRc ? ": " : "", Th_GetResult(g.interp, 0)); |
| 2351 | 2395 | Th_PrintTraceLog(); |
| 2352 | 2396 | if( forceCgi ) cgi_reply(); |
| 2353 | 2397 | } |
| @@ -2356,11 +2400,11 @@ | ||
| 2356 | 2400 | /* |
| 2357 | 2401 | ** COMMAND: test-th-hook |
| 2358 | 2402 | ** |
| 2359 | 2403 | ** Usage: %fossil test-th-hook TYPE NAME FLAGS |
| 2360 | 2404 | ** |
| 2361 | -** Executes the TH1 script configured for the pre-operation (i.e. a command | |
| 2405 | +** Evaluates the TH1 script configured for the pre-operation (i.e. a command | |
| 2362 | 2406 | ** or web page) "hook" or post-operation "notification". The results of the |
| 2363 | 2407 | ** script evaluation, if any, will be printed to the standard output channel. |
| 2364 | 2408 | ** The NAME argument must be the name of a command or web page; however, it |
| 2365 | 2409 | ** does not necessarily have to be a command or web page that is normally |
| 2366 | 2410 | ** recognized by Fossil. The FLAGS argument will be used to set the value |
| @@ -2397,10 +2441,11 @@ | ||
| 2397 | 2441 | Th_InitTraceLog(); |
| 2398 | 2442 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2399 | 2443 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2400 | 2444 | if( fullHttpReply ) forceCgi = 1; |
| 2401 | 2445 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2446 | + verify_all_options(); | |
| 2402 | 2447 | if( g.argc<5 ){ |
| 2403 | 2448 | usage("TYPE NAME FLAGS"); |
| 2404 | 2449 | } |
| 2405 | 2450 | if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){ |
| 2406 | 2451 | rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4])); |
| 2407 | 2452 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2291,11 +2291,11 @@ | |
| 2291 | ** --http Include an HTTP response header in the output |
| 2292 | ** --open-config Open the configuration database |
| 2293 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2294 | */ |
| 2295 | void test_th_render(void){ |
| 2296 | int forceCgi = 0, fullHttpReply = 0; |
| 2297 | Blob in; |
| 2298 | Th_InitTraceLog(); |
| 2299 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2300 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2301 | if( fullHttpReply ) forceCgi = 1; |
| @@ -2318,11 +2318,11 @@ | |
| 2318 | ** COMMAND: test-th-eval |
| 2319 | ** |
| 2320 | ** Usage: %fossil test-th-eval SCRIPT |
| 2321 | ** |
| 2322 | ** Evaluate SCRIPT as if it were a header or footer or ticket rendering |
| 2323 | ** script, evaluate it, and show the results on standard output. |
| 2324 | ** |
| 2325 | ** Options: |
| 2326 | ** |
| 2327 | ** --cgi Include a CGI response header in the output |
| 2328 | ** --http Include an HTTP response header in the output |
| @@ -2339,15 +2339,59 @@ | |
| 2339 | if( fullHttpReply ) forceCgi = 1; |
| 2340 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2341 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2342 | Th_OpenConfig(1); |
| 2343 | } |
| 2344 | if( g.argc!=3 ){ |
| 2345 | usage("script"); |
| 2346 | } |
| 2347 | Th_FossilInit(TH_INIT_DEFAULT); |
| 2348 | rc = Th_Eval(g.interp, 0, g.argv[2], -1); |
| 2349 | zRc = Th_ReturnCodeName(rc, 1); |
| 2350 | fossil_print("%s%s%s\n", zRc, zRc ? ": " : "", Th_GetResult(g.interp, 0)); |
| 2351 | Th_PrintTraceLog(); |
| 2352 | if( forceCgi ) cgi_reply(); |
| 2353 | } |
| @@ -2356,11 +2400,11 @@ | |
| 2356 | /* |
| 2357 | ** COMMAND: test-th-hook |
| 2358 | ** |
| 2359 | ** Usage: %fossil test-th-hook TYPE NAME FLAGS |
| 2360 | ** |
| 2361 | ** Executes the TH1 script configured for the pre-operation (i.e. a command |
| 2362 | ** or web page) "hook" or post-operation "notification". The results of the |
| 2363 | ** script evaluation, if any, will be printed to the standard output channel. |
| 2364 | ** The NAME argument must be the name of a command or web page; however, it |
| 2365 | ** does not necessarily have to be a command or web page that is normally |
| 2366 | ** recognized by Fossil. The FLAGS argument will be used to set the value |
| @@ -2397,10 +2441,11 @@ | |
| 2397 | Th_InitTraceLog(); |
| 2398 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2399 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2400 | if( fullHttpReply ) forceCgi = 1; |
| 2401 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2402 | if( g.argc<5 ){ |
| 2403 | usage("TYPE NAME FLAGS"); |
| 2404 | } |
| 2405 | if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){ |
| 2406 | rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4])); |
| 2407 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2291,11 +2291,11 @@ | |
| 2291 | ** --http Include an HTTP response header in the output |
| 2292 | ** --open-config Open the configuration database |
| 2293 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2294 | */ |
| 2295 | void test_th_render(void){ |
| 2296 | int forceCgi, fullHttpReply; |
| 2297 | Blob in; |
| 2298 | Th_InitTraceLog(); |
| 2299 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2300 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2301 | if( fullHttpReply ) forceCgi = 1; |
| @@ -2318,11 +2318,11 @@ | |
| 2318 | ** COMMAND: test-th-eval |
| 2319 | ** |
| 2320 | ** Usage: %fossil test-th-eval SCRIPT |
| 2321 | ** |
| 2322 | ** Evaluate SCRIPT as if it were a header or footer or ticket rendering |
| 2323 | ** script and show the results on standard output. |
| 2324 | ** |
| 2325 | ** Options: |
| 2326 | ** |
| 2327 | ** --cgi Include a CGI response header in the output |
| 2328 | ** --http Include an HTTP response header in the output |
| @@ -2339,15 +2339,59 @@ | |
| 2339 | if( fullHttpReply ) forceCgi = 1; |
| 2340 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2341 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2342 | Th_OpenConfig(1); |
| 2343 | } |
| 2344 | verify_all_options(); |
| 2345 | if( g.argc!=3 ){ |
| 2346 | usage("script"); |
| 2347 | } |
| 2348 | Th_FossilInit(TH_INIT_DEFAULT); |
| 2349 | rc = Th_Eval(g.interp, 0, g.argv[2], -1); |
| 2350 | zRc = Th_ReturnCodeName(rc, 1); |
| 2351 | fossil_print("%s%s%s\n", zRc, zRc ? ": " : "", Th_GetResult(g.interp, 0)); |
| 2352 | Th_PrintTraceLog(); |
| 2353 | if( forceCgi ) cgi_reply(); |
| 2354 | } |
| 2355 | |
| 2356 | /* |
| 2357 | ** COMMAND: test-th-source |
| 2358 | ** |
| 2359 | ** Usage: %fossil test-th-source FILE |
| 2360 | ** |
| 2361 | ** Evaluate the contents of the file named "FILE" as if it were a header |
| 2362 | ** or footer or ticket rendering script and show the results on standard |
| 2363 | ** output. |
| 2364 | ** |
| 2365 | ** Options: |
| 2366 | ** |
| 2367 | ** --cgi Include a CGI response header in the output |
| 2368 | ** --http Include an HTTP response header in the output |
| 2369 | ** --open-config Open the configuration database |
| 2370 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2371 | */ |
| 2372 | void test_th_source(void){ |
| 2373 | int rc; |
| 2374 | const char *zRc; |
| 2375 | int forceCgi, fullHttpReply; |
| 2376 | Blob in; |
| 2377 | Th_InitTraceLog(); |
| 2378 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2379 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2380 | if( fullHttpReply ) forceCgi = 1; |
| 2381 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2382 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2383 | Th_OpenConfig(1); |
| 2384 | } |
| 2385 | verify_all_options(); |
| 2386 | if( g.argc!=3 ){ |
| 2387 | usage("file"); |
| 2388 | } |
| 2389 | blob_zero(&in); |
| 2390 | blob_read_from_file(&in, g.argv[2]); |
| 2391 | Th_FossilInit(TH_INIT_DEFAULT); |
| 2392 | rc = Th_Eval(g.interp, 0, blob_str(&in), -1); |
| 2393 | zRc = Th_ReturnCodeName(rc, 1); |
| 2394 | fossil_print("%s%s%s\n", zRc, zRc ? ": " : "", Th_GetResult(g.interp, 0)); |
| 2395 | Th_PrintTraceLog(); |
| 2396 | if( forceCgi ) cgi_reply(); |
| 2397 | } |
| @@ -2356,11 +2400,11 @@ | |
| 2400 | /* |
| 2401 | ** COMMAND: test-th-hook |
| 2402 | ** |
| 2403 | ** Usage: %fossil test-th-hook TYPE NAME FLAGS |
| 2404 | ** |
| 2405 | ** Evaluates the TH1 script configured for the pre-operation (i.e. a command |
| 2406 | ** or web page) "hook" or post-operation "notification". The results of the |
| 2407 | ** script evaluation, if any, will be printed to the standard output channel. |
| 2408 | ** The NAME argument must be the name of a command or web page; however, it |
| 2409 | ** does not necessarily have to be a command or web page that is normally |
| 2410 | ** recognized by Fossil. The FLAGS argument will be used to set the value |
| @@ -2397,10 +2441,11 @@ | |
| 2441 | Th_InitTraceLog(); |
| 2442 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2443 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2444 | if( fullHttpReply ) forceCgi = 1; |
| 2445 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2446 | verify_all_options(); |
| 2447 | if( g.argc<5 ){ |
| 2448 | usage("TYPE NAME FLAGS"); |
| 2449 | } |
| 2450 | if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){ |
| 2451 | rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4])); |
| 2452 |
+17
| --- test/th1.test | ||
| +++ test/th1.test | ||
| @@ -1436,5 +1436,22 @@ | ||
| 1436 | 1436 | |
| 1437 | 1437 | ############################################################################### |
| 1438 | 1438 | |
| 1439 | 1439 | fossil test-th-eval {set tcl_platform(platform)} |
| 1440 | 1440 | test th1-platform-4 {$RESULT eq "windows" || $RESULT eq "unix"} |
| 1441 | + | |
| 1442 | +############################################################################### | |
| 1443 | + | |
| 1444 | +set th1FileName [file join $::tempPath th1-[pid].th1] | |
| 1445 | + | |
| 1446 | +write_file $th1FileName { | |
| 1447 | + set x "" | |
| 1448 | + for {set i 0} {$i < 10} {set i [expr {$i + 1}]} { | |
| 1449 | + set x "$x $i" | |
| 1450 | + } | |
| 1451 | + return [string trim $x] | |
| 1452 | + set y; # NOTE: Never hit. | |
| 1453 | +} | |
| 1454 | + | |
| 1455 | +fossil test-th-source $th1FileName | |
| 1456 | +test th1-source-1 {$RESULT eq {TH_RETURN: 0 1 2 3 4 5 6 7 8 9}} | |
| 1457 | +file delete $th1FileName | |
| 1441 | 1458 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -1436,5 +1436,22 @@ | |
| 1436 | |
| 1437 | ############################################################################### |
| 1438 | |
| 1439 | fossil test-th-eval {set tcl_platform(platform)} |
| 1440 | test th1-platform-4 {$RESULT eq "windows" || $RESULT eq "unix"} |
| 1441 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -1436,5 +1436,22 @@ | |
| 1436 | |
| 1437 | ############################################################################### |
| 1438 | |
| 1439 | fossil test-th-eval {set tcl_platform(platform)} |
| 1440 | test th1-platform-4 {$RESULT eq "windows" || $RESULT eq "unix"} |
| 1441 | |
| 1442 | ############################################################################### |
| 1443 | |
| 1444 | set th1FileName [file join $::tempPath th1-[pid].th1] |
| 1445 | |
| 1446 | write_file $th1FileName { |
| 1447 | set x "" |
| 1448 | for {set i 0} {$i < 10} {set i [expr {$i + 1}]} { |
| 1449 | set x "$x $i" |
| 1450 | } |
| 1451 | return [string trim $x] |
| 1452 | set y; # NOTE: Never hit. |
| 1453 | } |
| 1454 | |
| 1455 | fossil test-th-source $th1FileName |
| 1456 | test th1-source-1 {$RESULT eq {TH_RETURN: 0 1 2 3 4 5 6 7 8 9}} |
| 1457 | file delete $th1FileName |
| 1458 |