Fossil SCM

Minor style and comment cleanup. Add verify_all_options() to several TH1 test commands. Add 'test-th-source' test command, with test.

mistachkin 2016-01-28 05:37 trunk
Commit f141fbeac5d923217477673b04e3ac9ba5f7d61e
2 files changed +48 -3 +17
+48 -3
--- src/th_main.c
+++ src/th_main.c
@@ -2291,11 +2291,11 @@
22912291
** --http Include an HTTP response header in the output
22922292
** --open-config Open the configuration database
22932293
** --th-trace Trace TH1 execution (for debugging purposes)
22942294
*/
22952295
void test_th_render(void){
2296
- int forceCgi = 0, fullHttpReply = 0;
2296
+ int forceCgi, fullHttpReply;
22972297
Blob in;
22982298
Th_InitTraceLog();
22992299
forceCgi = find_option("cgi", 0, 0)!=0;
23002300
fullHttpReply = find_option("http", 0, 0)!=0;
23012301
if( fullHttpReply ) forceCgi = 1;
@@ -2318,11 +2318,11 @@
23182318
** COMMAND: test-th-eval
23192319
**
23202320
** Usage: %fossil test-th-eval SCRIPT
23212321
**
23222322
** 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.
23242324
**
23252325
** Options:
23262326
**
23272327
** --cgi Include a CGI response header in the output
23282328
** --http Include an HTTP response header in the output
@@ -2339,15 +2339,59 @@
23392339
if( fullHttpReply ) forceCgi = 1;
23402340
if( forceCgi ) Th_ForceCgi(fullHttpReply);
23412341
if( find_option("open-config", 0, 0)!=0 ){
23422342
Th_OpenConfig(1);
23432343
}
2344
+ verify_all_options();
23442345
if( g.argc!=3 ){
23452346
usage("script");
23462347
}
23472348
Th_FossilInit(TH_INIT_DEFAULT);
23482349
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);
23492393
zRc = Th_ReturnCodeName(rc, 1);
23502394
fossil_print("%s%s%s\n", zRc, zRc ? ": " : "", Th_GetResult(g.interp, 0));
23512395
Th_PrintTraceLog();
23522396
if( forceCgi ) cgi_reply();
23532397
}
@@ -2356,11 +2400,11 @@
23562400
/*
23572401
** COMMAND: test-th-hook
23582402
**
23592403
** Usage: %fossil test-th-hook TYPE NAME FLAGS
23602404
**
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
23622406
** or web page) "hook" or post-operation "notification". The results of the
23632407
** script evaluation, if any, will be printed to the standard output channel.
23642408
** The NAME argument must be the name of a command or web page; however, it
23652409
** does not necessarily have to be a command or web page that is normally
23662410
** recognized by Fossil. The FLAGS argument will be used to set the value
@@ -2397,10 +2441,11 @@
23972441
Th_InitTraceLog();
23982442
forceCgi = find_option("cgi", 0, 0)!=0;
23992443
fullHttpReply = find_option("http", 0, 0)!=0;
24002444
if( fullHttpReply ) forceCgi = 1;
24012445
if( forceCgi ) Th_ForceCgi(fullHttpReply);
2446
+ verify_all_options();
24022447
if( g.argc<5 ){
24032448
usage("TYPE NAME FLAGS");
24042449
}
24052450
if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){
24062451
rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4]));
24072452
--- 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
--- test/th1.test
+++ test/th1.test
@@ -1436,5 +1436,22 @@
14361436
14371437
###############################################################################
14381438
14391439
fossil test-th-eval {set tcl_platform(platform)}
14401440
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
14411458
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button