github.com/jdgcs/sqlite3@v1.12.1-0.20210908114423-bc5f96e4dd51/testdata/tcl/symlink2.test (about)

     1  # 2019 November 18
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  # This file implements regression tests for SQLite library.  The
    12  # focus of this file is testing that SQLite can follow symbolic links.
    13  #
    14  
    15  set testdir [file dirname $argv0]
    16  source $testdir/tester.tcl
    17  set testprefix symlink2
    18  
    19  # This only runs on Windows.
    20  if {$::tcl_platform(platform)!="windows"} {
    21    finish_test
    22    return
    23  }
    24  
    25  proc createWin32Symlink { link target } {
    26    exec -- $::env(ComSpec) /c mklink \
    27        [file nativename $link] [file nativename $target]
    28    return ""
    29  }
    30  
    31  proc deleteWin32Symlink { link } {
    32    exec -- $::env(ComSpec) /c del [file nativename $link]
    33    return ""
    34  }
    35  
    36  proc canCreateWin32Symlink {} {
    37    set link [file join $::testdir lnk[pid].sym]
    38    if {[file exists $link]} { return 0 }
    39    set target [info nameofexecutable]
    40    if {[catch {createWin32Symlink $link $target}] == 0} {
    41      deleteWin32Symlink $link
    42      return 1
    43    }
    44    return 0
    45  }
    46  
    47  # Creating symlinks may require administrator privileges on Windows.
    48  if {![canCreateWin32Symlink]} {
    49    finish_test
    50    return
    51  }
    52  
    53  # Ensure that test.db has been created.
    54  #
    55  do_execsql_test 1.0 {
    56    CREATE TABLE t1(x, y);
    57    INSERT INTO t1 VALUES(1,9999);
    58  }
    59  
    60  do_test 2.0 {
    61    createWin32Symlink link.db test.db
    62  } {}
    63  
    64  do_test 2.1 {
    65    file exists test.db
    66  } {1}
    67  
    68  do_test 2.2 {
    69    file exists link.db
    70  } {1}
    71  
    72  do_test 3.1 {
    73    execsql { SELECT x, y FROM t1; } db
    74  } {1 9999}
    75  
    76  do_test 3.2 {
    77    sqlite3 db2 link.db
    78    execsql { SELECT x, y FROM t1; } db2
    79  } {1 9999}
    80  
    81  do_test 3.3 {
    82    sqlite3 db3 test.db -nofollow true
    83    execsql { SELECT x, y FROM t1; } db3
    84  } {1 9999}
    85  
    86  do_test 3.4 {
    87    db3 close
    88  } {}
    89  
    90  do_test 3.5 {
    91    list [catch {
    92      sqlite3 db4 link.db -nofollow true
    93      execsql { SELECT x, y FROM t1; } db4
    94    } res] $res
    95  } {1 {unable to open database file}}
    96  
    97  catch {db4 close}
    98  
    99  do_test 4.0 {
   100    db2 close
   101    deleteWin32Symlink link.db
   102  } {}
   103  
   104  do_test 4.1 {
   105    file exists test.db
   106  } {1}
   107  
   108  do_test 4.2 {
   109    file exists link.db
   110  } {0}
   111  
   112  do_test 5.1 {
   113    execsql { SELECT x, y FROM t1; } db
   114  } {1 9999}
   115  
   116  finish_test