Fossil

Check-in [5ea2a4fb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests for the 'anycap', 'anoncap', and 'hascap' TH1 commands. Also, add the --set-user-caps and --set-anon-caps options to the 'test-th-eval', 'test-th-render', and 'test-th-source' test commands.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5ea2a4fb075cf024a293b756209c0fa6f39a2ce3
User & Date: mistachkin 2016-08-18 01:47:24
Context
2016-08-18
01:50
Some coding style corrections in the TH1 tests. check-in: 46e92c25 user: mistachkin tags: trunk
01:47
Add tests for the 'anycap', 'anoncap', and 'hascap' TH1 commands. Also, add the --set-user-caps and --set-anon-caps options to the 'test-th-eval', 'test-th-render', and 'test-th-source' test commands. check-in: 5ea2a4fb user: mistachkin tags: trunk
01:40
Correct checking for the new 'y' permission (write unversioned files). check-in: 1f8a667f user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th_main.c.

2383
2384
2385
2386
2387
2388
2389


2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401








2402
2403
2404
2405
2406
2407
2408
....
2420
2421
2422
2423
2424
2425
2426


2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439








2440
2441
2442
2443
2444
2445
2446
....
2460
2461
2462
2463
2464
2465
2466


2467
2468
2469
2470
2471
2472
2473
....
2474
2475
2476
2477
2478
2479
2480








2481
2482
2483
2484
2485
2486
2487
** on standard output.
**
** Options:
**
**     --cgi                Include a CGI response header in the output
**     --http               Include an HTTP response header in the output
**     --open-config        Open the configuration database


**     --th-trace           Trace TH1 execution (for debugging purposes)
*/
void test_th_render(void){
  int forceCgi, fullHttpReply;
  Blob in;
  Th_InitTraceLog();
  forceCgi = find_option("cgi", 0, 0)!=0;
  fullHttpReply = find_option("http", 0, 0)!=0;
  if( fullHttpReply ) forceCgi = 1;
  if( forceCgi ) Th_ForceCgi(fullHttpReply);
  if( find_option("open-config", 0, 0)!=0 ){
    Th_OpenConfig(1);








  }
  verify_all_options();
  if( g.argc<3 ){
    usage("FILE");
  }
  blob_zero(&in);
  blob_read_from_file(&in, g.argv[2]);
................................................................................
** script and show the results on standard output.
**
** Options:
**
**     --cgi                Include a CGI response header in the output
**     --http               Include an HTTP response header in the output
**     --open-config        Open the configuration database


**     --th-trace           Trace TH1 execution (for debugging purposes)
*/
void test_th_eval(void){
  int rc;
  const char *zRc;
  int forceCgi, fullHttpReply;
  Th_InitTraceLog();
  forceCgi = find_option("cgi", 0, 0)!=0;
  fullHttpReply = find_option("http", 0, 0)!=0;
  if( fullHttpReply ) forceCgi = 1;
  if( forceCgi ) Th_ForceCgi(fullHttpReply);
  if( find_option("open-config", 0, 0)!=0 ){
    Th_OpenConfig(1);








  }
  verify_all_options();
  if( g.argc!=3 ){
    usage("script");
  }
  Th_FossilInit(TH_INIT_DEFAULT);
  rc = Th_Eval(g.interp, 0, g.argv[2], -1);
................................................................................
** output.
**
** Options:
**
**     --cgi                Include a CGI response header in the output
**     --http               Include an HTTP response header in the output
**     --open-config        Open the configuration database


**     --th-trace           Trace TH1 execution (for debugging purposes)
*/
void test_th_source(void){
  int rc;
  const char *zRc;
  int forceCgi, fullHttpReply;
  Blob in;
................................................................................
  Th_InitTraceLog();
  forceCgi = find_option("cgi", 0, 0)!=0;
  fullHttpReply = find_option("http", 0, 0)!=0;
  if( fullHttpReply ) forceCgi = 1;
  if( forceCgi ) Th_ForceCgi(fullHttpReply);
  if( find_option("open-config", 0, 0)!=0 ){
    Th_OpenConfig(1);








  }
  verify_all_options();
  if( g.argc!=3 ){
    usage("file");
  }
  blob_zero(&in);
  blob_read_from_file(&in, g.argv[2]);







>
>












>
>
>
>
>
>
>
>







 







>
>













>
>
>
>
>
>
>
>







 







>
>







 







>
>
>
>
>
>
>
>







2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
....
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
....
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
....
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
** on standard output.
**
** Options:
**
**     --cgi                Include a CGI response header in the output
**     --http               Include an HTTP response header in the output
**     --open-config        Open the configuration database
**     --set-anon-caps      Set anonymous login capabilities
**     --set-user-caps      Set user login capabilities
**     --th-trace           Trace TH1 execution (for debugging purposes)
*/
void test_th_render(void){
  int forceCgi, fullHttpReply;
  Blob in;
  Th_InitTraceLog();
  forceCgi = find_option("cgi", 0, 0)!=0;
  fullHttpReply = find_option("http", 0, 0)!=0;
  if( fullHttpReply ) forceCgi = 1;
  if( forceCgi ) Th_ForceCgi(fullHttpReply);
  if( find_option("open-config", 0, 0)!=0 ){
    Th_OpenConfig(1);
  }
  if( find_option("set-anon-caps", 0, 0)!=0 ){
    login_set_capabilities("sx", LOGIN_ANON);
    g.useLocalauth = 1;
  }
  if( find_option("set-user-caps", 0, 0)!=0 ){
    login_set_capabilities("sx", 0);
    g.useLocalauth = 1;
  }
  verify_all_options();
  if( g.argc<3 ){
    usage("FILE");
  }
  blob_zero(&in);
  blob_read_from_file(&in, g.argv[2]);
................................................................................
** script and show the results on standard output.
**
** Options:
**
**     --cgi                Include a CGI response header in the output
**     --http               Include an HTTP response header in the output
**     --open-config        Open the configuration database
**     --set-anon-caps      Set anonymous login capabilities
**     --set-user-caps      Set user login capabilities
**     --th-trace           Trace TH1 execution (for debugging purposes)
*/
void test_th_eval(void){
  int rc;
  const char *zRc;
  int forceCgi, fullHttpReply;
  Th_InitTraceLog();
  forceCgi = find_option("cgi", 0, 0)!=0;
  fullHttpReply = find_option("http", 0, 0)!=0;
  if( fullHttpReply ) forceCgi = 1;
  if( forceCgi ) Th_ForceCgi(fullHttpReply);
  if( find_option("open-config", 0, 0)!=0 ){
    Th_OpenConfig(1);
  }
  if( find_option("set-anon-caps", 0, 0)!=0 ){
    login_set_capabilities("sx", LOGIN_ANON);
    g.useLocalauth = 1;
  }
  if( find_option("set-user-caps", 0, 0)!=0 ){
    login_set_capabilities("sx", 0);
    g.useLocalauth = 1;
  }
  verify_all_options();
  if( g.argc!=3 ){
    usage("script");
  }
  Th_FossilInit(TH_INIT_DEFAULT);
  rc = Th_Eval(g.interp, 0, g.argv[2], -1);
................................................................................
** output.
**
** Options:
**
**     --cgi                Include a CGI response header in the output
**     --http               Include an HTTP response header in the output
**     --open-config        Open the configuration database
**     --set-anon-caps      Set anonymous login capabilities
**     --set-user-caps      Set user login capabilities
**     --th-trace           Trace TH1 execution (for debugging purposes)
*/
void test_th_source(void){
  int rc;
  const char *zRc;
  int forceCgi, fullHttpReply;
  Blob in;
................................................................................
  Th_InitTraceLog();
  forceCgi = find_option("cgi", 0, 0)!=0;
  fullHttpReply = find_option("http", 0, 0)!=0;
  if( fullHttpReply ) forceCgi = 1;
  if( forceCgi ) Th_ForceCgi(fullHttpReply);
  if( find_option("open-config", 0, 0)!=0 ){
    Th_OpenConfig(1);
  }
  if( find_option("set-anon-caps", 0, 0)!=0 ){
    login_set_capabilities("sx", LOGIN_ANON);
    g.useLocalauth = 1;
  }
  if( find_option("set-user-caps", 0, 0)!=0 ){
    login_set_capabilities("sx", 0);
    g.useLocalauth = 1;
  }
  verify_all_options();
  if( g.argc!=3 ){
    usage("file");
  }
  blob_zero(&in);
  blob_read_from_file(&in, g.argv[2]);

Changes to test/th1.test.

552
553
554
555
556
557
558



























































559
560
561
562
563
564
565
...
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
###############################################################################

fossil test-th-eval "lindex list -0x"
test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}}

###############################################################################




























































run_in_checkout {
  # NOTE: The "1" here forces the checkout to be opened.
  fossil test-th-eval "checkout 1"
}

test th1-checkout-1 {[string length $RESULT] > 0}

................................................................................
fossil test-th-eval "reinitialize 1; globalState configuration"
test th1-reinitialize-2 {$RESULT ne ""}

###############################################################################

#
# NOTE: This test will fail if the command names are added to TH1, or
#       moved from Tcl builds to plain or the reverse. Sorting the 
#       command lists eliminates a dependence on order.
#
fossil test-th-eval "info commands"
set sorted_result [lsort $RESULT]
protOut "Sorted: $sorted_result"
set base_commands {anoncap anycap array artifact break breakpoint catch\
      checkout combobox continue date decorate dir enable_output encode64\







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
###############################################################################

fossil test-th-eval "lindex list -0x"
test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}}

###############################################################################

foreach perm [list a b c d e f g h i j k l m n o p q r s t u v w x y z] {
  if {$perm eq "u"} continue; # NOTE: Skip "reader" meta-permission.
  if {$perm eq "v"} continue; # NOTE: Skip "developer" meta-permission.

  fossil test-th-eval "anycap $perm"
  test th1-anycap-no-$perm {$RESULT eq {0}}

  fossil test-th-eval "hascap $perm"
  test th1-hascap-no-$perm {$RESULT eq {0}}

  fossil test-th-eval "anoncap $perm"
  test th1-anoncap-no-$perm {$RESULT eq {0}}

  run_in_checkout {
    fossil test-th-eval --set-user-caps "anycap $perm"
    test th1-anycap-yes-$perm {$RESULT eq {1}}

    fossil test-th-eval --set-user-caps "hascap $perm"
    test th1-hascap-yes-$perm {$RESULT eq {1}}

    fossil test-th-eval --set-anon-caps "anoncap $perm"
    test th1-anoncap-yes-$perm {$RESULT eq {1}}
  }
}

fossil test-th-eval "anycap oh"
test th1-anycap-no-multiple {$RESULT eq {0}}

fossil test-th-eval "hascap oh"
test th1-hascap-no-multiple1 {$RESULT eq {0}}

fossil test-th-eval "hascap o h"
test th1-hascap-no-multiple2 {$RESULT eq {0}}

fossil test-th-eval "anoncap oh"
test th1-anoncap-no-multiple1 {$RESULT eq {0}}

fossil test-th-eval "anoncap o h"
test th1-anoncap-no-multiple2 {$RESULT eq {0}}

run_in_checkout {
  fossil test-th-eval --set-user-caps "anycap oh"
  test th1-anycap-yes-multiple1 {$RESULT eq {1}}

  fossil test-th-eval --set-user-caps "hascap oh"
  test th1-hascap-yes-multiple1 {$RESULT eq {1}}

  fossil test-th-eval --set-user-caps "hascap o h"
  test th1-hascap-yes-multiple2 {$RESULT eq {1}}

  fossil test-th-eval --set-anon-caps "anoncap oh"
  test th1-anoncap-yes-multiple1 {$RESULT eq {1}}

  fossil test-th-eval --set-anon-caps "anoncap o h"
  test th1-anoncap-yes-multiple2 {$RESULT eq {1}}
}

###############################################################################

run_in_checkout {
  # NOTE: The "1" here forces the checkout to be opened.
  fossil test-th-eval "checkout 1"
}

test th1-checkout-1 {[string length $RESULT] > 0}

................................................................................
fossil test-th-eval "reinitialize 1; globalState configuration"
test th1-reinitialize-2 {$RESULT ne ""}

###############################################################################

#
# NOTE: This test will fail if the command names are added to TH1, or
#       moved from Tcl builds to plain or the reverse. Sorting the
#       command lists eliminates a dependence on order.
#
fossil test-th-eval "info commands"
set sorted_result [lsort $RESULT]
protOut "Sorted: $sorted_result"
set base_commands {anoncap anycap array artifact break breakpoint catch\
      checkout combobox continue date decorate dir enable_output encode64\