summaryrefslogtreecommitdiff
path: root/test/shellB.test
blob: 8f76a92ad893e64284a4feb46ea73d6ed4b6b783 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 2025-11-12
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# TESTRUNNER: shell
#
# Test cases for the command-line shell using the newly renovated
# ".testcase" and ".check" commands.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set CLI [test_cli_invocation]

# Run an instance of the CLI on the file $name.
# Capture the number of test cases and the number of
# errors and increment the counts.
#
proc do_clitest {name args} {
  set mapping [list <NAME> $::testdir/$name <CLI> $::CLI <ARGS> $args]
  set script [string map $mapping {
    catch {exec <CLI> <ARGS> :memory: <NAME> 2>@stdout} res
    set ntest 0
    set nerr 999
    regexp {(\d+) tests? run with (\d+) errors?} $res all ntest nerr
    set_test_counter count [expr {[set_test_counter count]+$ntest-1}]
    set_test_counter errors [expr {[set_test_counter errors]+$nerr}]
    if {$nerr==0} {set res "error count: 0"}
    set res
  }]
  # puts $script
  do_test shellB-$name $script {error count: 0}
}

# Attempt to build a loadable extension named $ext from source
# file $srcfile.  Return true on success.
#
proc build_loadable {ext srcfile} {
  if {$::tcl_platform(os) eq "Windows NT"} {
    set ext [file root $ext].dll
    set cmd [list exec gcc -shared -fPIC -I. -I.. -o $ext $srcfile]
  } elseif {$::tcl_platform(os) eq "Darwin"} {
    set ext [file root $ext].dylib
    set cmd [list exec clang -dynamiclib -I. -I.. -o $ext $srcfile]
  } else {
    set ext [file root $ext].so
    set cmd [list exec gcc -shared -fPIC -I. -I.. -o $ext $srcfile]
  }
  if {[catch $cmd msg]} {
    # puts "Unable to build $ext, $msg"
    return 0
  } else {
    return 1
  }
}

set probe $testdir/probe.txt
forcedelete $probe
set f [open $probe wb]
puts -nonewline $f xyzzy
close $f
do_clitest safemode.clitest --safe
do_clitest shell-parse.clitest --test-parse
do_clitest fpdigits.clitest --unsafe-testing
unset -nocomplain ::env(SQLITE_PS1)
unset -nocomplain ::env(SQLITE_PS2)
do_clitest shell-prompt.clitest
ifcapable vtab&load_ext {
  set srcfile [file dir $testdir]/ext/misc/fossildelta.c
  if {[build_loadable fossildelta $srcfile]} {
    do_clitest fossildelta.clitest
  }
}

finish_test