debug_test.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package interpreter
  11. import (
  12. "encoding/json"
  13. "fmt"
  14. "strconv"
  15. "strings"
  16. "sync"
  17. "testing"
  18. "time"
  19. "devt.de/krotik/common/errorutil"
  20. "devt.de/krotik/ecal/scope"
  21. "devt.de/krotik/ecal/util"
  22. )
  23. func TestSimpleDebugging(t *testing.T) {
  24. var err error
  25. defer func() {
  26. testDebugger = nil
  27. }()
  28. testDebugger = NewECALDebugger(nil)
  29. if _, err = testDebugger.HandleInput("break ECALEvalTest:3"); err != nil {
  30. t.Error("Unexpected result:", err)
  31. return
  32. }
  33. if _, err = testDebugger.HandleInput("break ECALEvalTest:4"); err != nil {
  34. t.Error("Unexpected result:", err)
  35. return
  36. }
  37. if _, err = testDebugger.HandleInput("disablebreak ECALEvalTest:4"); err != nil {
  38. t.Error("Unexpected result:", err)
  39. return
  40. }
  41. wg := &sync.WaitGroup{}
  42. wg.Add(1)
  43. var tid uint64
  44. go func() {
  45. _, err = UnitTestEval(`
  46. log("test1")
  47. log("test2")
  48. log("test3")
  49. `, nil)
  50. if err != nil {
  51. t.Error(err)
  52. }
  53. testDebugger.RecordThreadFinished(tid)
  54. wg.Done()
  55. }()
  56. tid = waitForThreadSuspension(t)
  57. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  58. outBytes, _ := json.MarshalIndent(out, "", " ")
  59. outString := string(outBytes)
  60. if err != nil || outString != `{
  61. "breakonstart": false,
  62. "breakpoints": {
  63. "ECALEvalTest:3": true,
  64. "ECALEvalTest:4": false
  65. },
  66. "sources": [
  67. "ECALEvalTest"
  68. ],
  69. "threads": {
  70. "1": {
  71. "callStack": [],
  72. "error": null,
  73. "threadRunning": false
  74. }
  75. }
  76. }` {
  77. t.Error("Unexpected result:", outString, err)
  78. return
  79. }
  80. out, err = testDebugger.HandleInput(fmt.Sprintf("describe %v", tid))
  81. outBytes, _ = json.MarshalIndent(out, "", " ")
  82. outString = string(outBytes)
  83. if err != nil || outString != `{
  84. "callStack": [],
  85. "callStackNode": [],
  86. "callStackVsSnapshot": [],
  87. "callStackVsSnapshotGlobal": [],
  88. "code": "log(\"test2\")",
  89. "error": null,
  90. "node": {
  91. "allowescapes": false,
  92. "children": [
  93. {
  94. "children": [
  95. {
  96. "allowescapes": true,
  97. "id": 5,
  98. "identifier": false,
  99. "line": 3,
  100. "linepos": 5,
  101. "name": "string",
  102. "pos": 18,
  103. "source": "ECALEvalTest",
  104. "value": "test2"
  105. }
  106. ],
  107. "name": "funccall"
  108. }
  109. ],
  110. "id": 7,
  111. "identifier": true,
  112. "line": 3,
  113. "linepos": 1,
  114. "name": "identifier",
  115. "pos": 14,
  116. "source": "ECALEvalTest",
  117. "value": "log"
  118. },
  119. "threadRunning": false,
  120. "vs": {},
  121. "vsGlobal": {}
  122. }` {
  123. t.Error("Unexpected result:", outString, err)
  124. return
  125. }
  126. // Continue until the end
  127. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v Resume", tid)); err != nil {
  128. t.Error("Unexpected result:", err)
  129. return
  130. }
  131. wg.Wait()
  132. if err != nil || testlogger.String() != `
  133. test1
  134. test2
  135. test3`[1:] {
  136. t.Error("Unexpected result:", testlogger.String(), err)
  137. return
  138. }
  139. if _, err = testDebugger.HandleInput("rmbreak ECALEvalTest:4"); err != nil {
  140. t.Error("Unexpected result:", err)
  141. return
  142. }
  143. out, err = testDebugger.HandleInput(fmt.Sprintf("status"))
  144. outBytes, _ = json.MarshalIndent(out, "", " ")
  145. outString = string(outBytes)
  146. if err != nil || outString != `{
  147. "breakonstart": false,
  148. "breakpoints": {
  149. "ECALEvalTest:3": true
  150. },
  151. "sources": [
  152. "ECALEvalTest"
  153. ],
  154. "threads": {}
  155. }` {
  156. t.Error("Unexpected result:", outString, err)
  157. return
  158. }
  159. if _, err = testDebugger.HandleInput("break ECALEvalTest:4"); err != nil {
  160. t.Error("Unexpected result:", err)
  161. return
  162. }
  163. if _, err = testDebugger.HandleInput("rmbreak ECALEvalTest"); err != nil {
  164. t.Error("Unexpected result:", err)
  165. return
  166. }
  167. out, err = testDebugger.HandleInput(fmt.Sprintf("status"))
  168. outBytes, _ = json.MarshalIndent(out, "", " ")
  169. outString = string(outBytes)
  170. if err != nil || outString != `{
  171. "breakonstart": false,
  172. "breakpoints": {},
  173. "sources": [
  174. "ECALEvalTest"
  175. ],
  176. "threads": {}
  177. }` {
  178. t.Error("Unexpected result:", outString, err)
  179. return
  180. }
  181. }
  182. func TestDebugReset(t *testing.T) {
  183. var err error
  184. defer func() {
  185. testDebugger = nil
  186. }()
  187. testDebugger = NewECALDebugger(nil)
  188. if _, err = testDebugger.HandleInput("break ECALEvalTest:3"); err != nil {
  189. t.Error("Unexpected result:", err)
  190. return
  191. }
  192. wg := &sync.WaitGroup{}
  193. wg.Add(1)
  194. go func() {
  195. defer wg.Done()
  196. _, err = UnitTestEval(`
  197. log("test1")
  198. log("test2")
  199. log("test3")
  200. `, nil)
  201. if err != nil {
  202. t.Error(err)
  203. }
  204. }()
  205. waitForThreadSuspension(t)
  206. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  207. outBytes, _ := json.MarshalIndent(out, "", " ")
  208. outString := string(outBytes)
  209. if err != nil || outString != `{
  210. "breakonstart": false,
  211. "breakpoints": {
  212. "ECALEvalTest:3": true
  213. },
  214. "sources": [
  215. "ECALEvalTest"
  216. ],
  217. "threads": {
  218. "1": {
  219. "callStack": [],
  220. "error": null,
  221. "threadRunning": false
  222. }
  223. }
  224. }` {
  225. t.Error("Unexpected result:", outString, err)
  226. return
  227. }
  228. testDebugger.StopThreads(100 * time.Millisecond)
  229. wg.Wait()
  230. if err != nil || testlogger.String() != `
  231. test1
  232. test2`[1:] {
  233. t.Error("Unexpected result:", testlogger.String(), err)
  234. return
  235. }
  236. }
  237. func TestErrorStop(t *testing.T) {
  238. var err, evalError error
  239. defer func() {
  240. testDebugger = nil
  241. }()
  242. testDebugger = NewECALDebugger(nil)
  243. testDebugger.BreakOnError(true)
  244. if _, err = testDebugger.HandleInput("break ECALEvalTest:8"); err != nil {
  245. t.Error("Unexpected result:", err)
  246. return
  247. }
  248. wg := &sync.WaitGroup{}
  249. wg.Add(1)
  250. go func() {
  251. defer wg.Done()
  252. _, evalError = UnitTestEval(`
  253. func err () {
  254. raise("foo")
  255. }
  256. log("test1")
  257. log("test2")
  258. err()
  259. log("test3")
  260. `, nil)
  261. }()
  262. waitForThreadSuspension(t)
  263. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  264. outBytes, _ := json.MarshalIndent(out, "", " ")
  265. outString := string(outBytes)
  266. if err != nil || outString != `{
  267. "breakonstart": false,
  268. "breakpoints": {
  269. "ECALEvalTest:8": true
  270. },
  271. "sources": [
  272. "ECALEvalTest"
  273. ],
  274. "threads": {
  275. "1": {
  276. "callStack": [
  277. "err() (ECALEvalTest:7)"
  278. ],
  279. "error": {
  280. "Data": null,
  281. "Detail": "",
  282. "Environment": {},
  283. "Node": {
  284. "Name": "identifier",
  285. "Token": {
  286. "ID": 7,
  287. "Pos": 16,
  288. "Val": "raise",
  289. "Identifier": true,
  290. "AllowEscapes": false,
  291. "Lsource": "ECALEvalTest",
  292. "Lline": 3,
  293. "Lpos": 2
  294. },
  295. "Meta": null,
  296. "Children": [
  297. {
  298. "Name": "funccall",
  299. "Token": null,
  300. "Meta": null,
  301. "Children": [
  302. {
  303. "Name": "string",
  304. "Token": {
  305. "ID": 5,
  306. "Pos": 22,
  307. "Val": "foo",
  308. "Identifier": false,
  309. "AllowEscapes": true,
  310. "Lsource": "ECALEvalTest",
  311. "Lline": 3,
  312. "Lpos": 8
  313. },
  314. "Meta": null,
  315. "Children": [],
  316. "Runtime": {}
  317. }
  318. ],
  319. "Runtime": {}
  320. }
  321. ],
  322. "Runtime": {}
  323. },
  324. "Source": "ECALTestRuntime",
  325. "Trace": null,
  326. "Type": "foo"
  327. },
  328. "threadRunning": false
  329. }
  330. }
  331. }` {
  332. t.Error("Unexpected result:", outString, err)
  333. return
  334. }
  335. if _, err = testDebugger.HandleInput(fmt.Sprintf("cont 1 Resume")); err != nil {
  336. t.Error("Unexpected result:", err)
  337. return
  338. }
  339. wg.Wait()
  340. if evalError == nil || testlogger.String() != `
  341. test1
  342. test2`[1:] || evalError.Error() != "ECAL error in ECALTestRuntime: foo () (Line:3 Pos:2)" {
  343. t.Error("Unexpected result:", testlogger.String(), err)
  344. return
  345. }
  346. }
  347. func TestConcurrentDebugging(t *testing.T) {
  348. var err error
  349. defer func() {
  350. testDebugger = nil
  351. }()
  352. testDebugger = NewECALDebugger(nil)
  353. if _, err = testDebugger.HandleInput("break ECALEvalTest:5"); err != nil {
  354. t.Error("Unexpected result:", err)
  355. return
  356. }
  357. wg := &sync.WaitGroup{}
  358. wg.Add(2)
  359. erp := NewECALRuntimeProvider("ECALTestRuntime", nil, nil)
  360. vs := scope.NewScope(scope.GlobalScope)
  361. go func() {
  362. _, err = UnitTestEvalWithRuntimeProvider(`
  363. a := 1
  364. b := 1
  365. func test1() {
  366. log("test3")
  367. b := a + 1
  368. }
  369. log("test1")
  370. log("test2")
  371. test1()
  372. log("test4")
  373. `, vs, erp)
  374. if err != nil {
  375. t.Error(err)
  376. }
  377. wg.Done()
  378. }()
  379. go func() {
  380. _, err = UnitTestEvalWithRuntimeProvider(`
  381. a := 1
  382. c := 1
  383. func test2() {
  384. log("test3")
  385. c := a + 1
  386. }
  387. log("test1")
  388. log("test2")
  389. test2()
  390. log("test4")
  391. `, vs, erp)
  392. if err != nil {
  393. t.Error(err)
  394. }
  395. wg.Done()
  396. }()
  397. waitForAllThreadSuspension(t)
  398. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  399. outBytes, _ := json.MarshalIndent(out, "", " ")
  400. outString := string(outBytes)
  401. if err != nil || (outString != `{
  402. "breakonstart": false,
  403. "breakpoints": {
  404. "ECALEvalTest:5": true
  405. },
  406. "sources": [
  407. "ECALEvalTest"
  408. ],
  409. "threads": {
  410. "1": {
  411. "callStack": [
  412. "test1() (ECALEvalTest:10)"
  413. ],
  414. "error": null,
  415. "threadRunning": false
  416. },
  417. "2": {
  418. "callStack": [
  419. "test2() (ECALEvalTest:10)"
  420. ],
  421. "error": null,
  422. "threadRunning": false
  423. }
  424. }
  425. }` && outString != `{
  426. "breakonstart": false,
  427. "breakpoints": {
  428. "ECALEvalTest:5": true
  429. },
  430. "sources": [
  431. "ECALEvalTest"
  432. ],
  433. "threads": {
  434. "1": {
  435. "callStack": [
  436. "test2() (ECALEvalTest:10)"
  437. ],
  438. "error": null,
  439. "threadRunning": false
  440. },
  441. "2": {
  442. "callStack": [
  443. "test1() (ECALEvalTest:10)"
  444. ],
  445. "error": null,
  446. "threadRunning": false
  447. }
  448. }
  449. }`) {
  450. t.Error("Unexpected result:", outString, err)
  451. return
  452. }
  453. // Continue until the end
  454. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont 1 Resume")); err != nil {
  455. t.Error("Unexpected result:", err)
  456. return
  457. }
  458. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont 2 Resume")); err != nil {
  459. t.Error("Unexpected result:", err)
  460. return
  461. }
  462. wg.Wait()
  463. if vs.String() != `GlobalScope {
  464. a (float64) : 1
  465. b (float64) : 2
  466. c (float64) : 2
  467. test1 (*interpreter.function) : ecal.function: test1 (Line 4, Pos 1)
  468. test2 (*interpreter.function) : ecal.function: test2 (Line 4, Pos 1)
  469. }` {
  470. t.Error("Unexpected result:", vs)
  471. return
  472. }
  473. }
  474. func waitForThreadSuspension(t *testing.T) uint64 {
  475. var tid uint64
  476. for i := 0; i < 100; i += 1 {
  477. state, err := testDebugger.HandleInput("status")
  478. errorutil.AssertOk(err)
  479. threads := state.(map[string]interface{})["threads"].(map[string]map[string]interface{})
  480. if len(threads) > 0 {
  481. for threadId, status := range threads {
  482. if r, ok := status["threadRunning"]; ok && !r.(bool) {
  483. threadIdNum, _ := strconv.ParseInt(threadId, 10, 0)
  484. tid = uint64(threadIdNum)
  485. return tid
  486. }
  487. }
  488. }
  489. time.Sleep(1 * time.Millisecond)
  490. }
  491. panic("No suspended thread")
  492. }
  493. func waitForAllThreadSuspension(t *testing.T) uint64 {
  494. var tid uint64
  495. for i := 0; i < 100; i += 1 {
  496. state, err := testDebugger.HandleInput("status")
  497. errorutil.AssertOk(err)
  498. threads := state.(map[string]interface{})["threads"].(map[string]map[string]interface{})
  499. if len(threads) > 0 {
  500. allSuspended := true
  501. for _, status := range threads {
  502. if r, ok := status["threadRunning"]; ok && !r.(bool) {
  503. allSuspended = false
  504. break
  505. }
  506. }
  507. if allSuspended {
  508. break
  509. }
  510. }
  511. time.Sleep(1 * time.Millisecond)
  512. }
  513. return tid
  514. }
  515. func TestStepDebugging(t *testing.T) {
  516. var err error
  517. defer func() {
  518. testDebugger = nil
  519. }()
  520. testDebugger = NewECALDebugger(nil)
  521. code := `
  522. log("start")
  523. func fa(x) {
  524. a := 1
  525. log("a enter")
  526. fb(x)
  527. log("a exit")
  528. }
  529. func fb(x) {
  530. b := 2
  531. log("b enter")
  532. fc()
  533. fc(fc())
  534. log("b exit")
  535. }
  536. func fc() {
  537. c := 3
  538. log("c enter")
  539. log("c exit")
  540. }
  541. fa(1)
  542. func e() {
  543. log("e()")
  544. }
  545. func d() {
  546. e()
  547. }
  548. d(d())
  549. log("finish")
  550. `
  551. if _, err = testDebugger.HandleInput("break ECALEvalTest:10"); err != nil {
  552. t.Error("Unexpected result:", err)
  553. return
  554. }
  555. if _, err = testDebugger.HandleInput("breakonstart true"); err != nil {
  556. t.Error("Unexpected result:", err)
  557. return
  558. }
  559. wg := &sync.WaitGroup{}
  560. wg.Add(1)
  561. go func() {
  562. _, err = UnitTestEval(code, nil)
  563. if err != nil {
  564. t.Error(err)
  565. }
  566. wg.Done()
  567. }()
  568. tid := waitForThreadSuspension(t)
  569. if state := getDebuggerState(tid, t); state != `{
  570. "breakpoints": {
  571. "ECALEvalTest:10": true
  572. },
  573. "code": "log(\"start\")",
  574. "threads": {
  575. "1": {
  576. "callStack": [],
  577. "error": null,
  578. "threadRunning": false
  579. }
  580. },
  581. "vs": {}
  582. }` {
  583. t.Error("Unexpected state:", state)
  584. return
  585. }
  586. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v resume", tid)); err != nil {
  587. t.Error("Unexpected result:", err)
  588. return
  589. }
  590. tid = waitForThreadSuspension(t)
  591. if state := getDebuggerState(tid, t); state != `{
  592. "breakpoints": {
  593. "ECALEvalTest:10": true
  594. },
  595. "code": "b := 2",
  596. "threads": {
  597. "1": {
  598. "callStack": [
  599. "fa(1) (ECALEvalTest:21)",
  600. "fb(x) (ECALEvalTest:6)"
  601. ],
  602. "error": null,
  603. "threadRunning": false
  604. }
  605. },
  606. "vs": {
  607. "x": 1
  608. }
  609. }` {
  610. t.Error("Unexpected state:", state)
  611. return
  612. }
  613. // Step in without a function
  614. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepin", tid)); err != nil {
  615. t.Error("Unexpected result:", err)
  616. return
  617. }
  618. tid = waitForThreadSuspension(t)
  619. if state := getDebuggerState(tid, t); state != `{
  620. "breakpoints": {
  621. "ECALEvalTest:10": true
  622. },
  623. "code": "log(\"b enter\")",
  624. "threads": {
  625. "1": {
  626. "callStack": [
  627. "fa(1) (ECALEvalTest:21)",
  628. "fb(x) (ECALEvalTest:6)"
  629. ],
  630. "error": null,
  631. "threadRunning": false
  632. }
  633. },
  634. "vs": {
  635. "b": 2,
  636. "x": 1
  637. }
  638. }` {
  639. t.Error("Unexpected state:", state)
  640. return
  641. }
  642. // Normal step over
  643. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepover", tid)); err != nil {
  644. t.Error("Unexpected result:", err)
  645. return
  646. }
  647. tid = waitForThreadSuspension(t)
  648. if state := getDebuggerState(tid, t); state != `{
  649. "breakpoints": {
  650. "ECALEvalTest:10": true
  651. },
  652. "code": "fc()",
  653. "threads": {
  654. "1": {
  655. "callStack": [
  656. "fa(1) (ECALEvalTest:21)",
  657. "fb(x) (ECALEvalTest:6)"
  658. ],
  659. "error": null,
  660. "threadRunning": false
  661. }
  662. },
  663. "vs": {
  664. "b": 2,
  665. "x": 1
  666. }
  667. }` {
  668. t.Error("Unexpected state:", state)
  669. return
  670. }
  671. // Normal step in
  672. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepin", tid)); err != nil {
  673. t.Error("Unexpected result:", err)
  674. return
  675. }
  676. tid = waitForThreadSuspension(t)
  677. if state := getDebuggerState(tid, t); state != `{
  678. "breakpoints": {
  679. "ECALEvalTest:10": true
  680. },
  681. "code": "c := 3",
  682. "threads": {
  683. "1": {
  684. "callStack": [
  685. "fa(1) (ECALEvalTest:21)",
  686. "fb(x) (ECALEvalTest:6)",
  687. "fc() (ECALEvalTest:12)"
  688. ],
  689. "error": null,
  690. "threadRunning": false
  691. }
  692. },
  693. "vs": {}
  694. }` {
  695. t.Error("Unexpected state:", state)
  696. return
  697. }
  698. // Normal step out
  699. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepout", tid)); err != nil {
  700. t.Error("Unexpected result:", err)
  701. return
  702. }
  703. tid = waitForThreadSuspension(t)
  704. if state := getDebuggerState(tid, t); state != `{
  705. "breakpoints": {
  706. "ECALEvalTest:10": true
  707. },
  708. "code": "fc(fc())",
  709. "threads": {
  710. "1": {
  711. "callStack": [
  712. "fa(1) (ECALEvalTest:21)",
  713. "fb(x) (ECALEvalTest:6)"
  714. ],
  715. "error": null,
  716. "threadRunning": false
  717. }
  718. },
  719. "vs": {
  720. "b": 2,
  721. "x": 1
  722. }
  723. }` {
  724. t.Error("Unexpected state:", state)
  725. return
  726. }
  727. // Step in and step out - we should end up on the same line as before
  728. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepin", tid)); err != nil {
  729. t.Error("Unexpected result:", err)
  730. return
  731. }
  732. tid = waitForThreadSuspension(t)
  733. if state := getDebuggerState(tid, t); state != `{
  734. "breakpoints": {
  735. "ECALEvalTest:10": true
  736. },
  737. "code": "c := 3",
  738. "threads": {
  739. "1": {
  740. "callStack": [
  741. "fa(1) (ECALEvalTest:21)",
  742. "fb(x) (ECALEvalTest:6)",
  743. "fc() (ECALEvalTest:13)"
  744. ],
  745. "error": null,
  746. "threadRunning": false
  747. }
  748. },
  749. "vs": {}
  750. }` {
  751. t.Error("Unexpected state:", state)
  752. return
  753. }
  754. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepout", tid)); err != nil {
  755. t.Error("Unexpected result:", err)
  756. return
  757. }
  758. tid = waitForThreadSuspension(t)
  759. if state := getDebuggerState(tid, t); state != `{
  760. "breakpoints": {
  761. "ECALEvalTest:10": true
  762. },
  763. "code": "fc(fc())",
  764. "threads": {
  765. "1": {
  766. "callStack": [
  767. "fa(1) (ECALEvalTest:21)",
  768. "fb(x) (ECALEvalTest:6)"
  769. ],
  770. "error": null,
  771. "threadRunning": false
  772. }
  773. },
  774. "vs": {
  775. "b": 2,
  776. "x": 1
  777. }
  778. }` {
  779. t.Error("Unexpected state:", state)
  780. return
  781. }
  782. // Normal step out
  783. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepout", tid)); err != nil {
  784. t.Error("Unexpected result:", err)
  785. return
  786. }
  787. tid = waitForThreadSuspension(t)
  788. if state := getDebuggerState(tid, t); state != `{
  789. "breakpoints": {
  790. "ECALEvalTest:10": true
  791. },
  792. "code": "log(\"a exit\")",
  793. "threads": {
  794. "1": {
  795. "callStack": [
  796. "fa(1) (ECALEvalTest:21)"
  797. ],
  798. "error": null,
  799. "threadRunning": false
  800. }
  801. },
  802. "vs": {
  803. "a": 1,
  804. "x": 1
  805. }
  806. }` {
  807. t.Error("Unexpected state:", state)
  808. return
  809. }
  810. // Set a new breakpoint
  811. if _, err = testDebugger.HandleInput("break ECALEvalTest:28"); err != nil {
  812. t.Error("Unexpected result:", err)
  813. return
  814. }
  815. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v Resume", tid)); err != nil {
  816. t.Error("Unexpected result:", err)
  817. return
  818. }
  819. tid = waitForThreadSuspension(t)
  820. if state := getDebuggerState(tid, t); state != `{
  821. "breakpoints": {
  822. "ECALEvalTest:10": true,
  823. "ECALEvalTest:28": true
  824. },
  825. "code": "d(d())",
  826. "threads": {
  827. "1": {
  828. "callStack": [],
  829. "error": null,
  830. "threadRunning": false
  831. }
  832. },
  833. "vs": {
  834. "d": "ecal.function: d (Line 25, Pos 1)",
  835. "e": "ecal.function: e (Line 22, Pos 1)",
  836. "fa": "ecal.function: fa (Line 3, Pos 1)",
  837. "fb": "ecal.function: fb (Line 9, Pos 1)",
  838. "fc": "ecal.function: fc (Line 16, Pos 1)"
  839. }
  840. }` {
  841. t.Error("Unexpected state:", state)
  842. return
  843. }
  844. // Normal step over
  845. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepover", tid)); err != nil {
  846. t.Error("Unexpected result:", err)
  847. return
  848. }
  849. tid = waitForThreadSuspension(t)
  850. if state := getDebuggerState(tid, t); state != `{
  851. "breakpoints": {
  852. "ECALEvalTest:10": true,
  853. "ECALEvalTest:28": true
  854. },
  855. "code": "d(d())",
  856. "threads": {
  857. "1": {
  858. "callStack": [],
  859. "error": null,
  860. "threadRunning": false
  861. }
  862. },
  863. "vs": {
  864. "d": "ecal.function: d (Line 25, Pos 1)",
  865. "e": "ecal.function: e (Line 22, Pos 1)",
  866. "fa": "ecal.function: fa (Line 3, Pos 1)",
  867. "fb": "ecal.function: fb (Line 9, Pos 1)",
  868. "fc": "ecal.function: fc (Line 16, Pos 1)"
  869. }
  870. }` {
  871. t.Error("Unexpected state:", state)
  872. return
  873. }
  874. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v stepover", tid)); err != nil {
  875. t.Error("Unexpected result:", err)
  876. return
  877. }
  878. tid = waitForThreadSuspension(t)
  879. if state := getDebuggerState(tid, t); state != `{
  880. "breakpoints": {
  881. "ECALEvalTest:10": true,
  882. "ECALEvalTest:28": true
  883. },
  884. "code": "log(\"finish\")",
  885. "threads": {
  886. "1": {
  887. "callStack": [],
  888. "error": null,
  889. "threadRunning": false
  890. }
  891. },
  892. "vs": {
  893. "d": "ecal.function: d (Line 25, Pos 1)",
  894. "e": "ecal.function: e (Line 22, Pos 1)",
  895. "fa": "ecal.function: fa (Line 3, Pos 1)",
  896. "fb": "ecal.function: fb (Line 9, Pos 1)",
  897. "fc": "ecal.function: fc (Line 16, Pos 1)"
  898. }
  899. }` {
  900. t.Error("Unexpected state:", state)
  901. return
  902. }
  903. // Continue until the end
  904. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v Resume", tid)); err != nil {
  905. t.Error("Unexpected result:", err)
  906. return
  907. }
  908. wg.Wait()
  909. if err != nil || testlogger.String() != `
  910. start
  911. a enter
  912. b enter
  913. c enter
  914. c exit
  915. c enter
  916. c exit
  917. c enter
  918. c exit
  919. b exit
  920. a exit
  921. e()
  922. e()
  923. finish`[1:] {
  924. t.Error("Unexpected result:", testlogger.String(), err)
  925. return
  926. }
  927. }
  928. func TestStepDebuggingWithImport(t *testing.T) {
  929. var err error
  930. defer func() {
  931. testDebugger = nil
  932. }()
  933. testDebugger = NewECALDebugger(nil)
  934. il := &util.MemoryImportLocator{Files: make(map[string]string)}
  935. il.Files["foo/bar"] = `
  936. func myfunc(n) {
  937. if (n <= 1) {
  938. return n
  939. }
  940. n := n + 1
  941. return n
  942. }
  943. `
  944. code := `
  945. a := 1
  946. import "foo/bar" as foobar
  947. log("start")
  948. a := foobar.myfunc(a)
  949. log("finish: ", a)
  950. `
  951. if _, err = testDebugger.HandleInput("break ECALEvalTest:4"); err != nil {
  952. t.Error("Unexpected result:", err)
  953. return
  954. }
  955. if _, err = testDebugger.HandleInput("break foo/bar:4"); err != nil {
  956. t.Error("Unexpected result:", err)
  957. return
  958. }
  959. wg := &sync.WaitGroup{}
  960. wg.Add(1)
  961. go func() {
  962. _, err = UnitTestEvalAndASTAndImport(code, nil, "", il)
  963. if err != nil {
  964. t.Error(err)
  965. }
  966. wg.Done()
  967. }()
  968. tid := waitForThreadSuspension(t)
  969. if state := getDebuggerState(tid, t); state != `{
  970. "breakpoints": {
  971. "ECALEvalTest:4": true,
  972. "foo/bar:4": true
  973. },
  974. "code": "log(\"start\")",
  975. "threads": {
  976. "1": {
  977. "callStack": [],
  978. "error": null,
  979. "threadRunning": false
  980. }
  981. },
  982. "vs": {
  983. "a": 1,
  984. "foobar": {
  985. "myfunc": "ecal.function: myfunc (Line 2, Pos 1)"
  986. }
  987. }
  988. }` {
  989. t.Error("Unexpected state:", state)
  990. return
  991. }
  992. // Resume execution
  993. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v resume", tid)); err != nil {
  994. t.Error("Unexpected result:", err)
  995. return
  996. }
  997. tid = waitForThreadSuspension(t)
  998. if state := getDebuggerState(tid, t); state != `{
  999. "breakpoints": {
  1000. "ECALEvalTest:4": true,
  1001. "foo/bar:4": true
  1002. },
  1003. "code": "return n",
  1004. "threads": {
  1005. "1": {
  1006. "callStack": [
  1007. "myfunc(a) (ECALEvalTest:5)"
  1008. ],
  1009. "error": null,
  1010. "threadRunning": false
  1011. }
  1012. },
  1013. "vs": {
  1014. "n": 1
  1015. }
  1016. }` {
  1017. t.Error("Unexpected state:", state)
  1018. return
  1019. }
  1020. // Continue until the end
  1021. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v Resume", tid)); err != nil {
  1022. t.Error("Unexpected result:", err)
  1023. return
  1024. }
  1025. wg.Wait()
  1026. if err != nil || testlogger.String() != `
  1027. start
  1028. finish: 1`[1:] {
  1029. t.Error("Unexpected result:", testlogger.String(), err)
  1030. return
  1031. }
  1032. }
  1033. func getDebuggerState(tid uint64, t *testing.T) string {
  1034. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  1035. if err != nil {
  1036. t.Error(err)
  1037. return ""
  1038. }
  1039. outMap := out.(map[string]interface{})
  1040. out, err = testDebugger.HandleInput(fmt.Sprintf("describe %v", tid))
  1041. if err != nil {
  1042. t.Error(err)
  1043. return ""
  1044. }
  1045. outMap2 := out.(map[string]interface{})
  1046. outMap["vs"] = outMap2["vs"]
  1047. outMap["code"] = outMap2["code"]
  1048. delete(outMap, "breakonstart")
  1049. delete(outMap, "sources")
  1050. outBytes, _ := json.MarshalIndent(outMap, "", " ")
  1051. return string(outBytes)
  1052. }
  1053. func TestInjectAndExtractDebugging(t *testing.T) {
  1054. var err error
  1055. defer func() {
  1056. testDebugger = nil
  1057. }()
  1058. vs := scope.NewScope(scope.GlobalScope)
  1059. testDebugger = NewECALDebugger(vs)
  1060. if _, err = testDebugger.HandleInput("break ECALEvalTest:5"); err != nil {
  1061. t.Error("Unexpected result:", err)
  1062. return
  1063. }
  1064. wg := &sync.WaitGroup{}
  1065. wg.Add(1)
  1066. go func() {
  1067. _, err = UnitTestEval(`
  1068. b := 49
  1069. func myfunc() {
  1070. a := 56
  1071. log("test2 a=", a)
  1072. }
  1073. log("test1")
  1074. myfunc()
  1075. log("test3 b=", b)
  1076. `, vs)
  1077. if err != nil {
  1078. t.Error(err)
  1079. }
  1080. wg.Done()
  1081. }()
  1082. tid := waitForThreadSuspension(t)
  1083. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  1084. outBytes, _ := json.MarshalIndent(out, "", " ")
  1085. outString := string(outBytes)
  1086. if err != nil || outString != `{
  1087. "breakonstart": false,
  1088. "breakpoints": {
  1089. "ECALEvalTest:5": true
  1090. },
  1091. "sources": [
  1092. "ECALEvalTest"
  1093. ],
  1094. "threads": {
  1095. "1": {
  1096. "callStack": [
  1097. "myfunc() (ECALEvalTest:8)"
  1098. ],
  1099. "error": null,
  1100. "threadRunning": false
  1101. }
  1102. }
  1103. }` {
  1104. t.Error("Unexpected result:", outString, err)
  1105. return
  1106. }
  1107. out, err = testDebugger.HandleInput(fmt.Sprintf("describe %v", tid))
  1108. outBytes, _ = json.MarshalIndent(out, "", " ")
  1109. outString = string(outBytes)
  1110. if err != nil || outString != `{
  1111. "callStack": [
  1112. "myfunc() (ECALEvalTest:8)"
  1113. ],
  1114. "callStackNode": [
  1115. {
  1116. "allowescapes": false,
  1117. "children": [
  1118. {
  1119. "name": "funccall"
  1120. }
  1121. ],
  1122. "id": 7,
  1123. "identifier": true,
  1124. "line": 8,
  1125. "linepos": 1,
  1126. "name": "identifier",
  1127. "pos": 69,
  1128. "source": "ECALEvalTest",
  1129. "value": "myfunc"
  1130. }
  1131. ],
  1132. "callStackVsSnapshot": [
  1133. {
  1134. "b": 49,
  1135. "myfunc": "ecal.function: myfunc (Line 3, Pos 1)"
  1136. }
  1137. ],
  1138. "callStackVsSnapshotGlobal": [
  1139. {
  1140. "b": 49,
  1141. "myfunc": "ecal.function: myfunc (Line 3, Pos 1)"
  1142. }
  1143. ],
  1144. "code": "log(\"test2 a=\", a)",
  1145. "error": null,
  1146. "node": {
  1147. "allowescapes": false,
  1148. "children": [
  1149. {
  1150. "children": [
  1151. {
  1152. "allowescapes": true,
  1153. "id": 5,
  1154. "identifier": false,
  1155. "line": 5,
  1156. "linepos": 6,
  1157. "name": "string",
  1158. "pos": 39,
  1159. "source": "ECALEvalTest",
  1160. "value": "test2 a="
  1161. },
  1162. {
  1163. "allowescapes": false,
  1164. "id": 7,
  1165. "identifier": true,
  1166. "line": 5,
  1167. "linepos": 18,
  1168. "name": "identifier",
  1169. "pos": 51,
  1170. "source": "ECALEvalTest",
  1171. "value": "a"
  1172. }
  1173. ],
  1174. "name": "funccall"
  1175. }
  1176. ],
  1177. "id": 7,
  1178. "identifier": true,
  1179. "line": 5,
  1180. "linepos": 2,
  1181. "name": "identifier",
  1182. "pos": 35,
  1183. "source": "ECALEvalTest",
  1184. "value": "log"
  1185. },
  1186. "threadRunning": false,
  1187. "vs": {
  1188. "a": 56
  1189. },
  1190. "vsGlobal": {
  1191. "b": 49,
  1192. "myfunc": "ecal.function: myfunc (Line 3, Pos 1)"
  1193. }
  1194. }` {
  1195. t.Error("Unexpected result:", outString, err)
  1196. return
  1197. }
  1198. if _, err := testDebugger.HandleInput(fmt.Sprintf("extract %v a foo", tid)); err != nil {
  1199. t.Error("Unexpected result:", err)
  1200. return
  1201. }
  1202. if _, err := testDebugger.HandleInput(fmt.Sprintf("inject %v a x := b + 1; x", tid)); err != nil {
  1203. t.Error("Unexpected result:", err)
  1204. return
  1205. }
  1206. // Continue until the end
  1207. if _, err := testDebugger.HandleInput(fmt.Sprintf("cont %v Resume", tid)); err != nil {
  1208. t.Error("Unexpected result:", err)
  1209. return
  1210. }
  1211. wg.Wait()
  1212. if vs.String() != `
  1213. GlobalScope {
  1214. b (float64) : 49
  1215. foo (float64) : 56
  1216. myfunc (*interpreter.function) : ecal.function: myfunc (Line 3, Pos 1)
  1217. }`[1:] {
  1218. t.Error("Unexpected result:", vs.String(), err)
  1219. return
  1220. }
  1221. if testlogger.String() != `
  1222. test1
  1223. test2 a=50
  1224. test3 b=49`[1:] {
  1225. t.Error("Unexpected result:", testlogger.String(), err)
  1226. return
  1227. }
  1228. }
  1229. func TestSimpleStacktrace(t *testing.T) {
  1230. res, err := UnitTestEval(`
  1231. func a() {
  1232. b()
  1233. }
  1234. func b() {
  1235. c()
  1236. }
  1237. func c() {
  1238. raise("testerror")
  1239. }
  1240. a()
  1241. `, nil)
  1242. if err == nil {
  1243. t.Error("Unexpected result: ", res, err)
  1244. return
  1245. }
  1246. ss := err.(util.TraceableRuntimeError)
  1247. if out := fmt.Sprintf("%v\n %v", err.Error(), strings.Join(ss.GetTraceString(), "\n ")); out != `
  1248. ECAL error in ECALTestRuntime: testerror () (Line:9 Pos:2)
  1249. raise("testerror") (ECALEvalTest:9)
  1250. c() (ECALEvalTest:6)
  1251. b() (ECALEvalTest:3)
  1252. a() (ECALEvalTest:11)`[1:] {
  1253. t.Error("Unexpected output:", out)
  1254. return
  1255. }
  1256. }
  1257. func TestDebugDocstrings(t *testing.T) {
  1258. for k, v := range DebugCommandsMap {
  1259. if res := v.DocString(); res == "" {
  1260. t.Error("Docstring missing for ", k)
  1261. return
  1262. }
  1263. }
  1264. }
  1265. func TestDebuggingErrorInput(t *testing.T) {
  1266. var err error
  1267. defer func() {
  1268. testDebugger = nil
  1269. }()
  1270. vs := scope.NewScope(scope.GlobalScope)
  1271. testDebugger = NewECALDebugger(vs)
  1272. if _, err = testDebugger.HandleInput("uuu"); err == nil ||
  1273. err.Error() != `Unknown command: uuu` {
  1274. t.Error("Unexpected result:", err)
  1275. return
  1276. }
  1277. if _, err = testDebugger.HandleInput("break"); err == nil ||
  1278. err.Error() != `Need a break target (<source>:<line>) as first parameter` {
  1279. t.Error("Unexpected result:", err)
  1280. return
  1281. }
  1282. if _, err = testDebugger.HandleInput("break foo"); err == nil ||
  1283. err.Error() != `Invalid break target - should be <source>:<line>` {
  1284. t.Error("Unexpected result:", err)
  1285. return
  1286. }
  1287. if _, err = testDebugger.HandleInput("rmbreak"); err == nil ||
  1288. err.Error() != `Need a break target (<source>[:<line>]) as first parameter` {
  1289. t.Error("Unexpected result:", err)
  1290. return
  1291. }
  1292. if _, err = testDebugger.HandleInput("disablebreak"); err == nil ||
  1293. err.Error() != `Need a break target (<source>:<line>) as first parameter` {
  1294. t.Error("Unexpected result:", err)
  1295. return
  1296. }
  1297. if _, err = testDebugger.HandleInput("disablebreak foo"); err == nil ||
  1298. err.Error() != `Invalid break target - should be <source>:<line>` {
  1299. t.Error("Unexpected result:", err)
  1300. return
  1301. }
  1302. if _, err = testDebugger.HandleInput("break ECALEvalTest:3"); err != nil {
  1303. t.Error("Unexpected result:", err)
  1304. return
  1305. }
  1306. wg := &sync.WaitGroup{}
  1307. wg.Add(1)
  1308. go func() {
  1309. _, err = UnitTestEval(`
  1310. a:=1
  1311. log("test1")
  1312. log("test2")
  1313. log("test3")
  1314. `, vs)
  1315. if err != nil {
  1316. t.Error(err)
  1317. }
  1318. wg.Done()
  1319. }()
  1320. tid := waitForThreadSuspension(t)
  1321. out, err := testDebugger.HandleInput(fmt.Sprintf("status"))
  1322. outBytes, _ := json.MarshalIndent(out, "", " ")
  1323. outString := string(outBytes)
  1324. if err != nil || outString != `{
  1325. "breakonstart": false,
  1326. "breakpoints": {
  1327. "ECALEvalTest:3": true
  1328. },
  1329. "sources": [
  1330. "ECALEvalTest"
  1331. ],
  1332. "threads": {
  1333. "1": {
  1334. "callStack": [],
  1335. "error": null,
  1336. "threadRunning": false
  1337. }
  1338. }
  1339. }` {
  1340. t.Error("Unexpected result:", outString, err)
  1341. return
  1342. }
  1343. if _, err = testDebugger.HandleInput("cont foo"); err == nil ||
  1344. err.Error() != `Need a thread ID and a command Resume, StepIn, StepOver or StepOut` {
  1345. t.Error("Unexpected result:", err)
  1346. return
  1347. }
  1348. if _, err = testDebugger.HandleInput("cont foo bar"); err == nil ||
  1349. err.Error() != `Parameter 1 should be a number` {
  1350. t.Error("Unexpected result:", err)
  1351. return
  1352. }
  1353. if _, err = testDebugger.HandleInput("cont 99 bar"); err == nil ||
  1354. err.Error() != `Invalid command bar - must be resume, stepin, stepover or stepout` {
  1355. t.Error("Unexpected result:", err)
  1356. return
  1357. }
  1358. if _, err = testDebugger.HandleInput("describe"); err == nil ||
  1359. err.Error() != `Need a thread ID` {
  1360. t.Error("Unexpected result:", err)
  1361. return
  1362. }
  1363. if _, err = testDebugger.HandleInput(fmt.Sprintf("extract %v foo", tid)); err == nil ||
  1364. err.Error() != `Need a thread ID, a variable name and a destination variable name` {
  1365. t.Error("Unexpected result:", err)
  1366. return
  1367. }
  1368. if _, err = testDebugger.HandleInput(fmt.Sprintf("extract %v _foo foo", tid)); err == nil ||
  1369. err.Error() != `Variable names may only contain [a-zA-Z] and [a-zA-Z0-9] from the second character` {
  1370. t.Error("Unexpected result:", err)
  1371. return
  1372. }
  1373. if _, err = testDebugger.HandleInput(fmt.Sprintf("extract %v foo foo", tid)); err == nil ||
  1374. err.Error() != `No such value foo` {
  1375. t.Error("Unexpected result:", err)
  1376. return
  1377. }
  1378. if _, err = testDebugger.HandleInput(fmt.Sprintf("inject %v", tid)); err == nil ||
  1379. err.Error() != `Need a thread ID, a variable name and an expression` {
  1380. t.Error("Unexpected result:", err)
  1381. return
  1382. }
  1383. testDebugger.(*ecalDebugger).globalScope = nil
  1384. if _, err = testDebugger.HandleInput(fmt.Sprintf("extract %v foo foo", tid)); err == nil ||
  1385. err.Error() != `Cannot access global scope` {
  1386. t.Error("Unexpected result:", err)
  1387. return
  1388. }
  1389. if _, err = testDebugger.HandleInput(fmt.Sprintf("inject %v foo foo", tid)); err == nil ||
  1390. err.Error() != `Cannot access global scope` {
  1391. t.Error("Unexpected result:", err)
  1392. return
  1393. }
  1394. }