From 8a8715af89c0223e441772d38be6363b86452705 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Sat, 9 Mar 2024 23:59:50 -0800 Subject: [PATCH] Add regression tests for #9917, #9918 Change-Id: Ib0591e1499c5dba5e5a83ee75a899c9d16986827 --- .../data/regression_9917.nix | 9 +++++++++ .../data/regression_9917.test | 14 ++++++++++++++ .../data/regression_9918.nix | 5 +++++ .../data/regression_9918.test | 16 ++++++++++++++++ .../repl_characterization.cc | 11 +++++++++++ 5 files changed, 55 insertions(+) create mode 100644 tests/functional/repl_characterization/data/regression_9917.nix create mode 100644 tests/functional/repl_characterization/data/regression_9917.test create mode 100644 tests/functional/repl_characterization/data/regression_9918.nix create mode 100644 tests/functional/repl_characterization/data/regression_9918.test diff --git a/tests/functional/repl_characterization/data/regression_9917.nix b/tests/functional/repl_characterization/data/regression_9917.nix new file mode 100644 index 000000000..ab49ce3a2 --- /dev/null +++ b/tests/functional/repl_characterization/data/regression_9917.nix @@ -0,0 +1,9 @@ +let + a = builtins.trace "before inner break" ( + builtins.break { msg = "hello"; } + ); + b = builtins.trace "before outer break" ( + builtins.break a + ); +in + b diff --git a/tests/functional/repl_characterization/data/regression_9917.test b/tests/functional/repl_characterization/data/regression_9917.test new file mode 100644 index 000000000..a37ea5805 --- /dev/null +++ b/tests/functional/repl_characterization/data/regression_9917.test @@ -0,0 +1,14 @@ +https://github.com/NixOS/nix/pull/9917 (Enter debugger more reliably in let expressions and function calls) + +This test ensures that continues don't skip opportunities to enter the debugger. + trace: before outer break + info: breakpoint reached + + nix-repl> :c + trace: before inner break + info: breakpoint reached + + nix-repl> :c + + nix-repl> msg + "hello" diff --git a/tests/functional/repl_characterization/data/regression_9918.nix b/tests/functional/repl_characterization/data/regression_9918.nix new file mode 100644 index 000000000..3860ce70e --- /dev/null +++ b/tests/functional/repl_characterization/data/regression_9918.nix @@ -0,0 +1,5 @@ +let + r = []; + x = builtins.throw r; +in + x diff --git a/tests/functional/repl_characterization/data/regression_9918.test b/tests/functional/repl_characterization/data/regression_9918.test new file mode 100644 index 000000000..4a1931122 --- /dev/null +++ b/tests/functional/repl_characterization/data/regression_9918.test @@ -0,0 +1,16 @@ + error: + … while evaluating the error message passed to builtin.throw + + error: cannot coerce a list to a string: [ ] + +We expect to be able to see locals like r in the debugger: + + nix-repl> r + [ ] + + nix-repl> :env + Env level 0 + static: x r + + Env level 1 + builtins true false null scopedImport import isNull break abort throw derivationStrict placeholder baseNameOf dirOf removeAttrs map toString fetchMercurial fetchTree fetchTarball fetchGit fromTOML derivation diff --git a/tests/functional/repl_characterization/repl_characterization.cc b/tests/functional/repl_characterization/repl_characterization.cc index 993c30232..200eda1ee 100644 --- a/tests/functional/repl_characterization/repl_characterization.cc +++ b/tests/functional/repl_characterization/repl_characterization.cc @@ -97,4 +97,15 @@ TEST_F(ReplSessionTest, repl_basic) readTest("basic_repl.test", [this](std::string input) { runReplTest(input); }); } +#define DEBUGGER_TEST(name) \ + TEST_F(ReplSessionTest, name) \ + { \ + readTest(#name ".test", [this](std::string input) { \ + runReplTest(input, {"--debugger", "-f", goldenMaster(#name ".nix")}); \ + }); \ + } + +DEBUGGER_TEST(regression_9918); +DEBUGGER_TEST(regression_9917); + };