*** Running test-EvalExpr-calls ===== CASE: -c json write (len(42)) ===== json write (len(42)) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c = len(42) ===== = len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c call len(42) ===== call len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c echo $[len(42)] ===== echo $[len(42)] ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c echo $[len(z = 42)] ===== echo $[len(z = 42)] ^ [ -c flag ]:1: fatal: Expected at least 1 typed args, but only got 0 ===== CASE: -c echo @[len(42)] ===== echo @[len(42)] ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c echo @[len(z = 42)] ===== echo @[len(z = 42)] ^ [ -c flag ]:1: fatal: Expected at least 1 typed args, but only got 0 ===== CASE: -c const x = len(42) ===== const x = len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c setvar x += len(42) ===== setvar x += len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c var d = {} setvar d[len(42)] = "foo" ===== setvar d[len(42)] = "foo" ^~ [ -c flag ]:3: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c var d = {} setvar len(42).z = "foo" ===== setvar len(42).z = "foo" ^ [ -c flag ]:3: Subscript/Attribute not allowed on this LHS expression ===== CASE: -c hay define Package Package foo { x = len(42) } ===== x = len(42) ^~ [ -c flag ]:4: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c if (len(42)) { echo hi } ===== if (len(42)) { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c while (len(42)) { echo hi } ===== while (len(42)) { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c for x in (len(42)) { echo $x } ===== for x in (len(42)) { echo $x } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int OK test-EvalExpr-calls *** Running test-append-usage-error ===== CASE: -c append x ([]) ===== ===== CASE: -c append ===== append ^~~~~~ [ -c flag ]:1: fatal: Expected at least 1 typed args, but only got 0 ===== CASE: -c append x ===== append x ^~~~~~ [ -c flag ]:1: fatal: Expected at least 1 typed args, but only got 0 ===== CASE: -c append x ([], []) ===== append x ([], []) ^ [ -c flag ]:1: fatal: Expected 1 typed args, but got 2 OK test-append-usage-error *** Running test-const-decl ===== CASE: -c const x = {}; const x = {}; ===== const x = {}; const x = {}; ^ [ -c flag ]:1: fatal: Can't assign to readonly value 'x' ===== CASE: -c const x; const x; ===== const x; const x; ^ [ -c flag ]:1: fatal: Can't assign to readonly value 'x' OK test-const-decl *** Running test-dict-convert ===== CASE: -c = dict(1) ===== = dict(1) ^ [ -c flag ]:1: fatal: dict() expected Dict or BashAssoc, got Int ===== CASE: -c = dict("foo") ===== = dict("foo") ^ [ -c flag ]:1: fatal: dict() expected Dict or BashAssoc, got Str ===== CASE: -c = dict(len) ===== = dict(len) ^~~ [ -c flag ]:1: fatal: dict() expected Dict or BashAssoc, got BuiltinFunc ===== CASE: -c = dict("foo"->startswith) ===== = dict("foo"->startswith) ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str ===== CASE: -c = dict([["too", "many", "parts"]]) ===== = dict([["too", "many", "parts"]]) ^ [ -c flag ]:1: fatal: dict() expected Dict or BashAssoc, got List OK test-dict-convert *** Running test-eggex ===== CASE: -c = / [ \x00 \xff ] / ===== (Eggex) ===== CASE: -c = / [ \x00-\xff ] / ===== (Eggex) ===== CASE: -c = / [ $'\x00 \xff' ] / ===== = / [ $'\x00 \xff' ] / ^~ [ -c flag ]:1: fatal: Use unquoted char literal for byte 255, which is >= 128 (avoid confusing a set of bytes with a sequence) ===== CASE: -c = / [ \u{0} ] / ===== (Eggex) ===== CASE: -c = / [ \u{0}-\u{1} ] / ===== (Eggex) ===== CASE: -c var x =/ [ \u{80} ] /; echo $x ===== var x =/ [ \u{80} ] /; echo $x ^~~~~~ [ -c flag ]:1: fatal: ERE can't express char code 128 ===== CASE: -c var x = / [ \u{7f}-\u{80} ] /; echo $x ===== var x = / [ \u{7f}-\u{80} ] /; echo $x ^~~~~~ [ -c flag ]:1: fatal: ERE can't express char code 128 ===== CASE: -c = / [ \\ '^-]' 'abc' ] / ===== (Eggex) ===== CASE: -c var x = / [ a-'^' ] /; echo $x ===== var x = / [ a-'^' ] /; echo $x ^ [ -c flag ]:1: fatal: Can't use char 94 as end of range in ERE syntax ===== CASE: -c var x = / [ '-'-z ] /; echo $x ===== var x = / [ '-'-z ] /; echo $x ^ [ -c flag ]:1: fatal: Can't use char 45 as start of range in ERE syntax ===== CASE: -c var x = / [ ']'-z ] /; echo $x ===== var x = / [ ']'-z ] /; echo $x ^ [ -c flag ]:1: fatal: Can't use char 93 as start of range in ERE syntax ===== CASE: -c var x = / ['^'] /; echo $x ===== [^] ===== CASE: -c var i = 42 = / @i / # splice object of wrong type ===== = / @i / # splice object of wrong type ^ [ -c flag ]:3: fatal: Eggex splice expected Str or Eggex, got Int ===== CASE: -c var i = 42 = / [a @i] / # char class splice object of wrong type ===== = / [a @i] / # char class splice object of wrong type ^ [ -c flag ]:3: fatal: Eggex char class splice expected Str, got Int OK test-eggex *** Running test-eggex-2 ===== CASE: -c var sq = / 'foo'+ / ===== ===== CASE: -c var sq = / ('foo')+ / echo $sq var sq2 = / + / echo $sq2 ===== (foo)+ (foo)+ ===== CASE: -c var literal = "foo" var svs = / @literal+ / echo $svs ===== var svs = / @literal+ / ^ [ -c flag ]:3: fatal: POSIX EREs don't have groups without capture, so this node needs () around it. OK test-eggex-2 *** Running test-eggex-api ===== CASE: -c = _group(0) ===== = _group(0) ^ [ -c flag ]:1: fatal: No regex capture groups ===== CASE: -c if ("foo" ~ /[a-z]/) { echo $[_group(1)] } ===== if ("foo" ~ /[a-z]/) { echo $[_group(1)] } ^ [ -c flag ]:1: fatal: Expected capture group less than 1, got 1 ===== CASE: -c if ("foo" ~ /[a-z]/) { echo $[_group("name")] } ===== if ("foo" ~ /[a-z]/) { echo $[_group("name")] } ^ [ -c flag ]:1: fatal: No such group 'name' ===== CASE: -c if ("foo" ~ "[a-z]") { echo $[_group(1)] } ===== if ("foo" ~ "[a-z]") { echo $[_group(1)] } ^ [ -c flag ]:1: fatal: Expected capture group less than 1, got 1 ===== CASE: -c if ("foo" ~ "[a-z]") { echo $[_group("name")] } ===== if ("foo" ~ "[a-z]") { echo $[_group("name")] } ^ [ -c flag ]:1: fatal: ERE captures don't have names ('name') ===== CASE: -c = _group("foo") ===== = _group("foo") ^ [ -c flag ]:1: fatal: No regex capture groups OK test-eggex-api *** Running test-eggex-convert-func ===== CASE: -c = / / ===== (Eggex) ===== CASE: -c = / / ===== (Eggex) ===== CASE: -c = / / ===== (Eggex) ===== CASE: -c = / / ===== = / / ^~~ [ -c flag ]:1: fatal: Expected 'BAD' to be a func, got Undef ===== CASE: -c = / / ===== = / / ^~~ [ -c flag ]:1: fatal: Expected 'BAD' to be a func, got Undef ===== CASE: -c var pat = / /; var m = "10" => search(pat) => group(1) ===== var pat = / /; var m = "10" => search(pat) => group(1) ^ [ -c flag ]:1: Fatal error calling Eggex conversion func 'evalExpr' from this Match accessor var pat = / /; var m = "10" => search(pat) => group(1) ^~~~~~~~ [ -c flag ]:1: fatal: Arg 1 should be a Expr, got Str OK test-eggex-convert-func *** Running test-equality ===== CASE: -c = ^[42] === ^[43] ===== = ^[42] === ^[43] ^~~ [ -c flag ]:2: fatal: Can't compare two values of type Expr ===== CASE: -c = ^(echo hi) === ^(echo yo) ===== = ^(echo hi) === ^(echo yo) ^~~ [ -c flag ]:2: fatal: Can't compare two values of type Command OK test-equality *** Running test-error-builtin ===== CASE: -c error ===== error ^~~~~ [ -c flag ]:1: 'error' expected a message to display error ^~~~~ [ -c flag ]:1: errexit PID 7651: command.Simple failed with status 2 ===== CASE: -c error -- ===== error -- ^~~~~ [ -c flag ]:1: 'error' expected a message to display error -- ^~~~~ [ -c flag ]:1: errexit PID 7654: command.Simple failed with status 2 ===== CASE: -c error -- oops ===== error -- oops ^~~~~ [ -c flag ]:1: fatal: oops ===== CASE: -c error oops ===== error oops ^~~~~ [ -c flag ]:1: fatal: oops ===== CASE: -c error oops (code=99) ===== error oops (code=99) ^~~~~ [ -c flag ]:1: fatal: oops OK test-error-builtin *** Running test-fallback-locations ===== CASE: -c if (len(42)) { echo hi } ===== if (len(42)) { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c if (1 + len(42)) { echo hi } ===== if (1 + len(42)) { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c const f = 42; func f() { echo hi } ===== const f = 42; func f() { echo hi } ^ [ -c flag ]:1: fatal: Can't assign to readonly value 'f' ===== CASE: -c for x in $[2 + len(42)] { echo hi } ===== for x in $[2 + len(42)] { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c for x in (len(42)) { echo hi } ===== for x in (len(42)) { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c while (len(42)) { echo hi } ===== while (len(42)) { echo hi } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c case (len(42)) { pat { echo argument } } ===== case (len(42)) { pat { echo argument } } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c case (42) { (len(42)) { echo arm } } ===== case (42) { (len(42)) { echo arm } } ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c case "$[len(42)]" in pat) echo hi ;; esac ===== case "$[len(42)]" in pat) echo hi ;; esac ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c var x = 3 + len(42) ===== var x = 3 + len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c const x = 3 + len(42) ===== const x = 3 + len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c setvar x = 3 + len(42) ===== setvar x = 3 + len(42) ^~ [ -c flag ]:1: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c setvar x = "s" + 5 ===== setvar x = "s" + 5 ^ [ -c flag ]:1: fatal: Binary operator expected numbers, got Str and Int (OILS-ERR-201) ===== CASE: -c while ("s" + 5) { echo yes } ===== while ("s" + 5) { echo yes } ^ [ -c flag ]:1: fatal: Binary operator expected numbers, got Str and Int (OILS-ERR-201) ===== CASE: -c func f(x) { return (x) }; var x = f([1,2])[1](3); echo $x ===== func f(x) { return (x) }; var x = f([1,2])[1](3); echo $x ^ [ -c flag ]:1: fatal: Expected a function or method, got Int OK test-fallback-locations *** Running test-fat-arrow ===== CASE: -c = "str" => upper() ===== (Str) "STR" ===== CASE: -c = "str" -> bad() ===== = "str" -> bad() ^~~ [ -c flag ]:1: fatal: Method 'bad' does not exist on type Str ===== CASE: -c = "str" => bad() ===== = "str" => bad() ^~~ [ -c flag ]:1: fatal: Undefined variable 'bad' ===== CASE: -c = ["3", "4"] => join("/") ===== (Str) "3/4" ===== CASE: -c = "badstring" => join("/") ===== = "badstring" => join("/") ^ [ -c flag ]:1: fatal: Arg 1 should be a List, got Str ===== CASE: -c = [1.0, 2.0] => indexOf(3.14) ===== = [1.0, 2.0] => indexOf(3.14) ^ [ -c flag ]:1: fatal: Equality isn't defined on Float ===== CASE: -c var myint = 42 = "badstring" => myint("/") ===== = "badstring" => myint("/") ^~~~~ [ -c flag ]:3: fatal: Fat arrow => expects method or function, got Int OK test-fat-arrow *** Running test-float-convert ===== CASE: -c = float({}) ===== = float({}) ^ [ -c flag ]:1: fatal: float() expected Int, Float, or Str, got Dict ===== CASE: -c = float([]) ===== = float([]) ^ [ -c flag ]:1: fatal: float() expected Int, Float, or Str, got List ===== CASE: -c = float("foo") ===== = float("foo") ^ [ -c flag ]:1: fatal: Cannot convert foo to Float ===== CASE: -c = float(len) ===== = float(len) ^~~ [ -c flag ]:1: fatal: float() expected Int, Float, or Str, got BuiltinFunc ===== CASE: -c = float("foo"->startswith) ===== = float("foo"->startswith) ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str OK test-float-convert *** Running test-func-defaults ===== CASE: -c func f(a=ZZ) { echo } ===== func f(a=ZZ) { echo } ^~ [ -c flag ]:1: fatal: Undefined variable 'ZZ' ===== CASE: -c func f(a; named=YY) { echo } ===== func f(a; named=YY) { echo } ^~ [ -c flag ]:1: fatal: Undefined variable 'YY' ===== CASE: -c func f(a=[]) { echo } ===== func f(a=[]) { echo } ^ [ -c flag ]:1: fatal: Default values can't be mutable, got List ===== CASE: -c func f(; d={a:3}) { echo } ===== func f(; d={a:3}) { echo } ^ [ -c flag ]:1: fatal: Default values can't be mutable, got Dict OK test-func-defaults *** Running test-func-error-locs ===== CASE: -c = join(["foo", "bar"], " ", 99) ===== = join(["foo", "bar"], " ", 99) ^~ [ -c flag ]:1: fatal: Expected 2 typed args, but got 3 ===== CASE: -c = int() ===== = int() ^ [ -c flag ]:1: fatal: Expected at least 1 typed args, but only got 0 ===== CASE: -c = str({}) ===== = str({}) ^ [ -c flag ]:1: fatal: str() expected Str, Int, or Float, got Dict ===== CASE: -c = "foo"->startswith("f", "o") ===== = "foo"->startswith("f", "o") ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str ===== CASE: -c = "foo"->startswith() ===== = "foo"->startswith() ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str ===== CASE: -c = "foo"->startswith(1) ===== = "foo"->startswith(1) ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str ===== CASE: -c func f(x) { return (x) } = f() ===== = f() ^ [ -c flag ]:5: fatal: 'f' wasn't passed typed param 'x' OK test-func-error-locs *** Running test-func-extra ===== CASE: -c func f() { echo "$x $y" } call f(42) # extra pos ===== call f(42) # extra pos ^ [ -c flag ]:5: fatal: Func 'f' takes no positional args, but got 1 ===== CASE: -c func f() { echo "$x $y" } call f(; x=32) # extra named ===== call f(; x=32) # extra named ^ [ -c flag ]:5: fatal: Func 'f' takes no named args, but got 1 OK test-func-extra *** Running test-func-missing ===== CASE: -c func f(x, y) { echo "$x $y" } call f(1) ===== call f(1) ^ [ -c flag ]:5: fatal: 'f' wasn't passed typed param 'y' ===== CASE: -c func f(x, y; z) { echo "$x $y" } call f(3, 4) ===== call f(3, 4) ^ [ -c flag ]:5: fatal: 'f' wasn't passed named param 'z' OK test-func-missing *** Running test-func-passing ===== CASE: -c func f(...rest=3) { return (42) } ===== func f(...rest=3) { ^ [ -c flag ]:2: Syntax error in expression (near Id.Arith_Equal) ===== CASE: -c func f(a, b) { echo "$a -- $b" } = f() ===== = f() ^ [ -c flag ]:5: fatal: 'f' wasn't passed typed param 'a' ===== CASE: -c func f(a, b) { echo "$a -- $b" } = f(...[1, 2]) = f(...3) ===== 1 -- 2 (Null) null = f(...3) ^~~ [ -c flag ]:6: fatal: Spread expected a List, got Int ===== CASE: -c func f(a, ...b) { echo $a - @b - } = f(1, 2, 3) var x = [4, 5, 6] = f(...x) ===== 1 - 2 3 - (Null) null 4 - 5 6 - (Null) null ===== CASE: -c func f(p ; a, b) { echo "$p ; $a $b" } var kwargs = {a: 42, b: 43, c: 44} = f(99; ...kwargs) ===== 99 ; 42 43 (Null) null OK test-func-passing *** Running test-hay ===== CASE: -c hay define package user TASK hay eval :result { package foo { # commands can be run while evaluating oops } bad 2 } ===== oops ^~~~ [ -c flag ]:7: Unknown command 'oops' while running hay [ -c flag ]:7: errexit PID 7834: command.Simple failed with status 127 OK test-hay *** Running test-hay-osh ===== CASE: -c hay define package TASK package foo { version = 1 } ===== version = 1 ^~~~~~~ [ -c flag ]:5: 'version' not found (OILS-ERR-100) } ^ [ -c flag ]:6: Unexpected right brace ===== CASE: -c shopt --set parse_brace hay define package TASK hay eval :result { package foo { version = 1 } } ===== version = 1 ^~~~~~~ [ -c flag ]:8: Unknown command 'version' while running hay OK test-hay-osh *** Running test-int-convert ===== CASE: -c = int({}) ===== = int({}) ^ [ -c flag ]:1: fatal: int() expected Bool, Int, Float, or Str, got Dict ===== CASE: -c = int([]) ===== = int([]) ^ [ -c flag ]:1: fatal: int() expected Bool, Int, Float, or Str, got List ===== CASE: -c = int("foo") ===== = int("foo") ^ [ -c flag ]:1: fatal: Cannot convert foo to Int ===== CASE: -c = int(len) ===== = int(len) ^~~ [ -c flag ]:1: fatal: int() expected Bool, Int, Float, or Str, got BuiltinFunc ===== CASE: -c = int("foo"->startswith) ===== = int("foo"->startswith) ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str OK test-int-convert *** Running test-json ===== CASE: -c json write ===== json write ^~~~ [ -c flag ]:1: fatal: Expected at least 1 typed args, but only got 0 ===== CASE: -c json write (42, 43) ===== json write (42, 43) ^~ [ -c flag ]:1: fatal: Expected 1 typed args, but got 2 ===== CASE: -c json read zz ===== json read zz ^~ [ -c flag ]:1: 'json' read got too many args json read zz ^~~~ [ -c flag ]:1: errexit PID 7873: command.Simple failed with status 2 ===== CASE: -c json read yy zz ===== json read yy zz ^~ [ -c flag ]:1: 'json' read got too many args json read yy zz ^~~~ [ -c flag ]:1: errexit PID 7876: command.Simple failed with status 2 ===== CASE: -c json read (&x, 43) ===== json read (&x, 43) ^~ [ -c flag ]:1: fatal: Expected 1 typed args, but got 2 OK test-json *** Running test-list-convert ===== CASE: -c = list(1) ===== = list(1) ^ [ -c flag ]:1: fatal: list() expected Dict, List, or Range, got Int ===== CASE: -c = list(len) ===== = list(len) ^~~ [ -c flag ]:1: fatal: list() expected Dict, List, or Range, got BuiltinFunc ===== CASE: -c = list("foo"->startswith) ===== = list("foo"->startswith) ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str OK test-list-convert *** Running test-method-type-errors ===== CASE: -c = "hi" => search(42) ===== = "hi" => search(42) ^ [ -c flag ]:1: fatal: expected Eggex or Str, got Int ===== CASE: -c = "hi" => leftMatch(42) ===== = "hi" => leftMatch(42) ^ [ -c flag ]:1: fatal: expected Eggex or Str, got Int ===== CASE: -c var m = 'hi' => leftMatch(/'hi'/); = m => group(3.14) ===== var m = 'hi' => leftMatch(/'hi'/); = m => group(3.14) ^ [ -c flag ]:1: fatal: expected Int or Str, got Float OK test-method-type-errors *** Running test-no-typed-args ===== CASE: -c true (42) ===== true (42) ^ [ -c flag ]:1: 'true' got unexpected typed args true (42) ^~~~ [ -c flag ]:1: errexit PID 7909: command.Simple failed with status 2 ===== CASE: -c false { echo hi } ===== false { echo hi } ^ [ -c flag ]:1: 'false' got unexpected typed args false { echo hi } ^~~~~ [ -c flag ]:1: errexit PID 7912: command.Simple failed with status 2 OK test-no-typed-args *** Running test-place ===== CASE: -c var a = null var p = &a call p->setValue() # 1 arg ===== call p->setValue() # 1 arg ^ [ -c flag ]:4: fatal: Expected at least 2 typed args, but only got 1 ===== CASE: -c var a = null var p = &a call p->setValue(3, 4) ===== call p->setValue(3, 4) ^ [ -c flag ]:4: fatal: Expected 1 typed args, but got 2 ===== CASE: -c func f() { var s = "foo" return (&s) } var p = f() call p->setValue(3) ===== call p->setValue(3) ^ [ -c flag ]:8: fatal: Can't assign to place that's no longer on the call stack. OK test-place *** Running test-proc-defaults ===== CASE: -c proc p(word=42) { echo } ===== proc p(word=42) { echo } ^~~~ [ -c flag ]:1: fatal: Default val for word param must be Str, got Int ===== CASE: -c proc p(word=null) { echo } ===== proc p(word=null) { echo } ^~~~ [ -c flag ]:1: fatal: Default val for word param must be Str, got Null ===== CASE: -c proc p( ; ; ; block="str") { echo } ===== proc p( ; ; ; block="str") { echo } ^~~~~ [ -c flag ]:1: fatal: Default value for block should be Command or Null, got Str ===== CASE: -c proc p( ; ; ; block=[]) { echo } ===== proc p( ; ; ; block=[]) { echo } ^~~~~ [ -c flag ]:1: fatal: Default value for block should be Command or Null, got List ===== CASE: -c proc p( ; ; ; block=^(echo hi)) { true } ===== ===== CASE: -c proc p( ; ; ; block=null) { true } ===== ===== CASE: -c proc p(word; t=42/0) { echo } ===== proc p(word; t=42/0) { echo } ^ [ -c flag ]:1: fatal: Divide by zero ===== CASE: -c proc p(word; t=f()) { echo } ===== proc p(word; t=f()) { echo } ^ [ -c flag ]:1: fatal: Undefined variable 'f' ===== CASE: -c proc p(word; t=42; named=undef) { echo } ===== proc p(word; t=42; named=undef) { echo } ^~~~~ [ -c flag ]:1: fatal: Undefined variable 'undef' ===== CASE: -c proc p(word; t=42; named=43; block=ZZ) { echo } ===== proc p(word; t=42; named=43; block=ZZ) { echo } ^~ [ -c flag ]:1: fatal: Undefined variable 'ZZ' ===== CASE: -c proc p(word="yo"; t=42; named=43; block=null) { #echo $word $t $named $block echo $word $t $block } p ===== yo 42 null OK test-proc-defaults *** Running test-proc-error-locs ===== CASE: -c var d = [1] func f(a=1, x=d[2]) { echo hi } ===== func f(a=1, x=d[2]) { ^ [ -c flag ]:4: fatal: List index out of range: 2 ===== CASE: -c var d = [1] func f(; n=1, m=d[2]) { echo hi } ===== func f(; n=1, m=d[2]) { ^ [ -c flag ]:4: fatal: List index out of range: 2 OK test-proc-error-locs *** Running test-proc-extra ===== CASE: -c proc myproc () { echo hi } myproc foo ===== myproc foo ^~~~~~ [ -c flag ]:5: fatal: Proc 'myproc' takes no word args, but got 1 ===== CASE: -c proc myproc (w) { echo hi } myproc foo (42) ===== myproc foo (42) ^ [ -c flag ]:5: fatal: Proc 'myproc' takes no typed args, but got 1 ===== CASE: -c proc myproc (w; p) { echo hi } myproc foo (42; named=1) ===== myproc foo (42; named=1) ^ [ -c flag ]:5: fatal: Proc 'myproc' takes no named args, but got 1 ===== CASE: -c proc myproc (w; p; n) { echo hi } myproc foo (42; n=1) { echo hi } ===== myproc foo (42; n=1) { echo hi } ^ [ -c flag ]:5: fatal: Proc 'myproc' doesn't accept a block argument OK test-proc-extra *** Running test-proc-missing ===== CASE: -c proc myproc (w) { = w } myproc ===== myproc ^~~~~~ [ -c flag ]:5: fatal: proc 'myproc' wasn't passed word param 'w' ===== CASE: -c proc myproc (w; t1, t2) { = w = t } myproc foo (42) ===== myproc foo (42) ^ [ -c flag ]:6: fatal: 'myproc' wasn't passed typed param 't2' ===== CASE: -c proc myproc (; p ; a, b) { echo "$p ; $a $b" } myproc (99, b=3) ===== myproc (99, b=3) ^ [ -c flag ]:5: fatal: 'myproc' wasn't passed named param 'a' ===== CASE: -c proc myproc (; p ; a, b) { echo "$p ; $a $b" } myproc (99; b=3) ===== myproc (99; b=3) ^ [ -c flag ]:5: fatal: 'myproc' wasn't passed named param 'a' ===== CASE: -c proc myproc (w; p ; a, b; block) { = block } myproc foo (99, a=1, b=2) ===== myproc foo (99, a=1, b=2) ^ [ -c flag ]:5: fatal: 'myproc' wasn't passed block param 'block' OK test-proc-missing *** Running test-proc-passing ===== CASE: -c proc p(a, b) { echo } p a ===== p a ^ [ -c flag ]:3: fatal: proc 'p' wasn't passed word param 'b' ===== CASE: -c proc p(a, b) { echo } p AA b c DD ===== p AA b c DD ^ [ -c flag ]:3: fatal: proc 'p' takes 2 words, but got 4 ===== CASE: -c proc p( ; a, b) { echo } p (42) ===== p (42) ^ [ -c flag ]:3: fatal: 'p' wasn't passed typed param 'b' ===== CASE: -c proc p( ; a, b) { echo } p (42, 43, 44, 45) ===== p (42, 43, 44, 45) ^ [ -c flag ]:3: fatal: 'p' takes 2 typed args, but got 4 ===== CASE: -c proc p(; a, b) { echo $a - $b - } p (...[1, 2]) p (...3) ===== 1 - 2 - p (...3) ^~~ [ -c flag ]:6: fatal: Spread expected a List, got Int ===== CASE: -c proc p(; a, ...b) { echo $a - @b - } p (1, 2, 3) var x = [4, 5, 6] p (...x) ===== 1 - 2 3 - 4 - 5 6 - ===== CASE: -c proc myproc (; p ; a, b) { echo "$p ; $a $b" } var kwargs = {a: 42, b: 43} myproc (99; ...kwargs) ===== 99 ; 42 43 ===== CASE: -c proc myproc (; p ; a, b, ...named) { = p = a = b = named } var kwargs = {a: 42, b: 43, c:44} myproc (99; ...kwargs) ===== (Int) 99 (Int) 42 (Int) 43 (Dict) {c: 44} OK test-proc-passing *** Running test-read-builtin ===== CASE: -c echo hi | read (&x) ===== echo hi | read (&x) ^ [ -c flag ]:1: 'read' doesn't accept typed args without --all, or --num-bytes echo hi | read (&x) ^~~~ [ -c flag ]:1: errexit PID 8035: command.Simple failed with status 2 echo hi | read (&x) ^~~~ [ -c flag ]:1: errexit PID 8035: command.Pipeline failed with status 2 ===== CASE: -c echo hi | read --all x y ===== echo hi | read --all x y ^ [ -c flag ]:1: 'read' got extra argument echo hi | read --all x y ^~~~ [ -c flag ]:1: errexit PID 8039: command.Simple failed with status 2 echo hi | read --all x y ^~~~ [ -c flag ]:1: errexit PID 8039: command.Pipeline failed with status 2 ===== CASE: -c echo hi | read --line x y ===== echo hi | read --line x y ^~~~~~ [ -c flag ]:1: 'read' got invalid flag '--line' echo hi | read --line x y ^~~~ [ -c flag ]:1: errexit PID 8043: command.Simple failed with status 2 echo hi | read --line x y ^~~~ [ -c flag ]:1: errexit PID 8043: command.Pipeline failed with status 2 OK test-read-builtin *** Running test-remainder ===== CASE: -c = 5 % -3 ===== = 5 % -3 ^ [ -c flag ]:1: fatal: Divisor can't be negative ===== CASE: -c var x = 5; setvar x %= -3 ===== var x = 5; setvar x %= -3 ^~ [ -c flag ]:1: fatal: Divisor can't be negative OK test-remainder *** Running test-setglobal ===== CASE: -c var a = [0] setglobal a[1-1] = 42 pp line (a) ===== (List) [42] ===== CASE: -c var a = [0] setglobal a[a.bad] = 42 pp line (a) ===== setglobal a[a.bad] = 42 ^ [ -c flag ]:3: fatal: Dot operator expected Dict, got List ===== CASE: -c var d = {e:{f:0}} setglobal d.e.f = 42 pp line (d) setglobal d.e.f += 1 pp line (d) ===== (Dict) {"e":{"f":42}} (Dict) {"e":{"f":43}} OK test-setglobal *** Running test-str-convert ===== CASE: -c = str({}) ===== = str({}) ^ [ -c flag ]:1: fatal: str() expected Str, Int, or Float, got Dict ===== CASE: -c = str([]) ===== = str([]) ^ [ -c flag ]:1: fatal: str() expected Str, Int, or Float, got List ===== CASE: -c = str(len) ===== = str(len) ^~~ [ -c flag ]:1: fatal: str() expected Str, Int, or Float, got BuiltinFunc ===== CASE: -c = str("foo"->startswith) ===== = str("foo"->startswith) ^~~~~~~~~~ [ -c flag ]:1: fatal: Method 'startswith' does not exist on type Str OK test-str-convert *** Running test-str-replace ===== CASE: -c = "foo" => replace("", "-") ===== (Str) "-f-o-o-" ===== CASE: -c = "foo" => replace("", "-", count=2) ===== (Str) "-f-oo" ===== CASE: -c = "foo" => replace("o", ^"-") ===== (Str) "f--" ===== CASE: -c = "foo" => replace("o", ^"-$0") ===== (Str) "f-o-o" ===== CASE: -c = "foo" => replace(/[o]/, ^"-$0") ===== (Str) "f-o-o" ===== CASE: -c = "foo" => replace(//, ^"-$1") ===== (Str) "f-o-o" ===== CASE: -c = "foo" => replace(//, ^"-$letter") ===== (Str) "f-o-o" ===== CASE: -c = "foo" => replace(42, "x") ===== = "foo" => replace(42, "x") ^ [ -c flag ]:1: fatal: expected pattern to be Eggex or Str, got Int ===== CASE: -c = "foo" => replace("x", 42) ===== = "foo" => replace("x", 42) ^ [ -c flag ]:1: fatal: expected substitution to be Str or Expr, got Int ===== CASE: -c = "foo" => replace("x", ^[42]) ===== = "foo" => replace("x", ^[42]) ^ [ -c flag ]:1: fatal: expected expr to eval to a Str, got Int OK test-str-replace *** Running test-trim-utf8-error ===== CASE: -c var badUtf = b'\yF9' # error is missed call " a$[badUtf]b " => trim() echo status=$_status # error is found call "$[badUtf]b " => trim() ===== status=0 call "$[badUtf]b " => trim() ^~ [ -c flag ]:8: fatal: UTF-8 decode: Bad encoding at offset 0 in string of 3 bytes OK test-trim-utf8-error *** Running test-try-usage-error ===== CASE: -c var s = "README" case (s) { README { echo hi } } echo hi try myproc if (_status !== 0) { echo failed } ===== hi hi try myproc ^~~ [ -c flag ]:8: fatal: Expected a block arg OK test-try-usage-error *** Running test-undefined-vars ===== CASE: -c echo hi; const y = 2 + x + 3 ===== hi echo hi; const y = 2 + x + 3 ^ [ -c flag ]:1: fatal: Undefined variable 'x' ===== CASE: -c if (x) { echo hello } ===== if (x) { echo hello } ^ [ -c flag ]:1: fatal: Undefined variable 'x' ===== CASE: -c if (${x}) { echo hi } ===== if (${x}) { echo hi } ^ [ -c flag ]:1: fatal: Undefined variable 'x' ===== CASE: -c const x = / @undef /; echo hi ===== const x = / @undef /; echo hi ^ [ -c flag ]:1: fatal: Undefined variable 'undef' ===== CASE: -c var x = undef; echo $x ===== var x = undef; echo $x ^~~~~ [ -c flag ]:1: fatal: Undefined variable 'undef' ===== CASE: -c setvar a = undef ===== setvar a = undef ^~~~~ [ -c flag ]:1: fatal: Undefined variable 'undef' OK test-undefined-vars *** Running test-user-reported ===== CASE: -c var snippets = [{status: 42}] for snippet in (snippets) { if (len(42)) { echo hi } } ===== if (len(42)) { ^~ [ -c flag ]:4: fatal: len() expected Str, List, or Dict, got Int ===== CASE: -c var count = 0 # The $ causes a weird error while (count < len(count)) { setvar count += 1 } ===== while (count < len(count)) { ^~~~~ [ -c flag ]:5: fatal: len() expected Str, List, or Dict, got Int OK test-user-reported *** Running test-var-decl ===== CASE: -c var x, y = 1, 2, 3 ===== var x, y = 1, 2, 3 ^~~ [ -c flag ]:1: fatal: Got 2 places on the left, but 3 values on right ===== CASE: -c setvar x, y = 1, 2, 3 ===== setvar x, y = 1, 2, 3 ^~~~~~ [ -c flag ]:1: fatal: Got 2 places on the left, but 3 values on the right OK test-var-decl *** Running test-word-eval-with-ysh-data ===== CASE: -c var d = {}; echo ${d:-} ===== var d = {}; echo ${d:-} ^~ [ -c flag ]:1: fatal: Can't substitute into word, got Dict ===== CASE: -c var d = {}; echo ${#d} ===== var d = {}; echo ${#d} ^ [ -c flag ]:1: fatal: Length op expected Str, BashArray, BashAssoc, got Dict ===== CASE: -c var d = {}; echo ${d[0]} ===== var d = {}; echo ${d[0]} ^~ [ -c flag ]:1: fatal: Index op expected BashArray, BashAssoc, got Dict ===== CASE: -c var d = {}; echo ${d[@]:1:3} ===== var d = {}; echo ${d[@]:1:3} ^~ [ -c flag ]:1: fatal: Slice op expected Str or BashArray, got Dict ===== CASE: -c var d = {}; echo ${!d} ===== var d = {}; echo ${!d} ^ [ -c flag ]:1: fatal: Var Ref op expected Str, got Dict ===== CASE: -c var d = {}; echo ${!d[@]} ===== var d = {}; echo ${!d[@]} ^ [ -c flag ]:1: fatal: Keys op expected Str, got Dict ===== CASE: -c var d = {}; echo ${d#prefix} ===== var d = {}; echo ${d#prefix} ^ [ -c flag ]:1: fatal: Unary op expected Str, BashArray, BashAssoc, got Dict ===== CASE: -c var d = {}; echo ${d//a/b} ===== var d = {}; echo ${d//a/b} ^ [ -c flag ]:1: fatal: Pat Sub op expected Str, BashArray, BashAssoc, got Dict OK test-word-eval-with-ysh-data *** Running test-ysh-expr-eval ===== CASE: -c echo $[42 / 0 ] ===== echo $[42 / 0 ] ^ [ -c flag ]:1: fatal: Divide by zero ===== CASE: -c var d = {}; var item = d->nonexistent ===== var d = {}; var item = d->nonexistent ^~~~~~~~~~~ [ -c flag ]:1: fatal: Method 'nonexistent' does not exist on type Dict ===== CASE: -c var d = {}; var item = d["nonexistent"] ===== var d = {}; var item = d["nonexistent"] ^~~~ [ -c flag ]:1: fatal: Dict entry not found: 'nonexistent' ===== CASE: -c var a = []; setvar item = a[1] ===== var a = []; setvar item = a[1] ^~~~~~ [ -c flag ]:1: fatal: List index out of range: 1 ===== CASE: -c const x = 42 / 0 ===== const x = 42 / 0 ^ [ -c flag ]:1: fatal: Divide by zero ===== CASE: -c var x = "z" ++ $(false) ===== var x = "z" ++ $(false) ^~~~~ [ -c flag ]:1: errexit PID 8216: command.Simple failed with status 1 [ -c flag ]:1: errexit PID 8213: Command Sub exited with status 1 ===== CASE: -c case (42 / 0) { * { echo hi } }; echo OK ===== case (42 / 0) { * { echo hi } }; echo OK ^ [ -c flag ]:1: fatal: Divide by zero ===== CASE: -c var d = {}; for x in $[d->zzz] { echo hi } ===== var d = {}; for x in $[d->zzz] { echo hi } ^~~ [ -c flag ]:1: fatal: Method 'zzz' does not exist on type Dict ===== CASE: -c var d = {}; setvar d[42] = 3 ===== var d = {}; setvar d[42] = 3 ^~~~~~ [ -c flag ]:1: fatal: Dict index should be Str, got Int ===== CASE: -c var L = []; setvar L["key"] = 3 ===== var L = []; setvar L["key"] = 3 ^~~~~~ [ -c flag ]:1: fatal: List index should be Int, got Str OK test-ysh-expr-eval *** Running test-ysh-expr-eval-2 ===== CASE: -c var L = []; var slice = L["foo": "bar"] ===== var L = []; var slice = L["foo": "bar"] ^~~~~ [ -c flag ]:1: fatal: Slice begin should be Int, got Str ===== CASE: -c = 3 < true ===== = 3 < true ^ [ -c flag ]:1: fatal: Comparison operator expected numbers, got Int and Bool ===== CASE: -c = "a" < "b" ===== = "a" < "b" ^ [ -c flag ]:1: fatal: Comparison operator expected numbers, got Str and Str ===== CASE: -c var key = 42; var d = {[key]: 3} ===== var key = 42; var d = {[key]: 3} ^ [ -c flag ]:1: fatal: Dict keys must be strings, got Int ===== CASE: -c var d = {}; var a = d.a ===== var d = {}; var a = d.a ^ [ -c flag ]:1: fatal: Dict entry 'a' not found ===== CASE: -c var d = []; var a = d.a ===== var d = []; var a = d.a ^ [ -c flag ]:1: fatal: Dot operator expected Dict, got List ===== CASE: -c = 3 ** -2 ===== = 3 ** -2 ^~ [ -c flag ]:1: fatal: Exponent can't be a negative number ===== CASE: -c = 3.2 ** 2 ===== = 3.2 ** 2 ^~ [ -c flag ]:1: fatal: Left operand should be Int, got Float ===== CASE: -c = - "foo" ===== = - "foo" ^ [ -c flag ]:1: fatal: Negation expected Int or Float, got Str OK test-ysh-expr-eval-2 *** Running test-ysh-word-eval ===== CASE: -c echo $[maybe("foo")] ===== echo $[maybe("foo")] ^~ [ -c flag ]:1: fatal: got a List, which can't be stringified. Perhaps use @ instead of $, or use join() ===== CASE: -c source --builtin funcs.ysh; echo $[identity({key: "val"})] ===== source --builtin funcs.ysh; echo $[identity({key: "val"})] ^~ [ -c flag ]:1: fatal: expected Null, Bool, Int, Float, Eggex, got Dict ===== CASE: -c source --builtin funcs.ysh; write -- @[identity([{key: "val"}])] ===== source --builtin funcs.ysh; write -- @[identity([{key: "val"}])] ^~ [ -c flag ]:1: fatal: Expr splice expected Null, Bool, Int, Float, Eggex, got Dict ===== CASE: -c const x = [1, 2]; echo $x ===== const x = [1, 2]; echo $x ^~~~ [ -c flag ]:1: fatal: got a List, which can't be stringified. Perhaps use @ instead of $, or use join() ===== CASE: -c var x = [1, 2]; write @x ===== 1 2 ===== CASE: -c var x = [3, {}]; write @x ===== var x = [3, {}]; write @x ^~ [ -c flag ]:1: fatal: Splice expected Null, Bool, Int, Float, Eggex, got Dict ===== CASE: -c var x = [3, {}]; write @[x] ===== var x = [3, {}]; write @[x] ^~ [ -c flag ]:1: fatal: Expr splice expected Null, Bool, Int, Float, Eggex, got Dict ===== CASE: -c var x = /d+/; write @x ===== var x = /d+/; write @x ^~ [ -c flag ]:1: fatal: Splice expected List, got Eggex ===== CASE: -c var x = /d+/; write @[x] ===== var x = /d+/; write @[x] ^~ [ -c flag ]:1: fatal: Expr splice expected List, got Eggex OK test-ysh-word-eval test/ysh-runtime-errors.sh: 45 tests passed.