diff --git a/.vscode/launch.json b/.vscode/launch.json index 7f4572754..d6823cb8e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,12 +25,17 @@ "justMyCode": false }, { - "name": "(gdb) Launch alr at /tmp/a/xxx", + "name": "Alire: debug ./bin/alr at /tmp/a/xxx", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/alr", - "args": ["-d", "-vv", "with", "libfoo"], - "stopAtEntry": true, + "args": [ + "exec", + "--", + "echo", + "blah" + ], + "stopAtEntry": false, "cwd": "/tmp/a/xxx", "environment": [], "externalConsole": false, @@ -42,11 +47,11 @@ "ignoreFailures": true }, { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", + "description": "Disable questions on multiple matches", + "text": "set multiple-symbols cancel", "ignoreFailures": true } ] } ] -} \ No newline at end of file +} diff --git a/src/alire/alire-os_lib-subprocess.adb b/src/alire/alire-os_lib-subprocess.adb index 41f8ef52e..1aea0be22 100644 --- a/src/alire/alire-os_lib-subprocess.adb +++ b/src/alire/alire-os_lib-subprocess.adb @@ -6,6 +6,7 @@ with AnsiAda; use AnsiAda; with CLIC.TTY; +with GNAT.IO; with GNAT.OS_Lib; package body Alire.OS_Lib.Subprocess is @@ -208,7 +209,13 @@ package body Alire.OS_Lib.Subprocess is and then CLIC.TTY.Is_TTY and then CLIC.TTY.Color_Enabled then - Ada.Text_IO.Put (Style (Dim, State)); + -- We cannot use Ada.Text_IO here, as it mandates endlines, + -- and the Ada runtime flushes this with an extra '\n' on + -- finalization if this is the last output, creating an extra + -- empty line in e.g. `alr exec echo whatever`. GNAT.IO is + -- uncooked so it works as expected. + Ada.Text_IO.Flush; -- So we don't mix bufferings + GNAT.IO.Put (Style (Dim, State)); end if; end Dim; diff --git a/src/alr/alr-commands-exec.adb b/src/alr/alr-commands-exec.adb index 03952db1b..9a20ad1a0 100644 --- a/src/alr/alr-commands-exec.adb +++ b/src/alr/alr-commands-exec.adb @@ -18,7 +18,6 @@ package body Alr.Commands.Exec is use GNAT.Strings; use Ada.Containers; use AAA.Strings; - begin Cmd.Forbids_Structured_Output; diff --git a/src/alr/alr-utils-temp_file.adb b/src/alr/alr-utils-temp_file.adb index 7f29dbdaf..35b066169 100644 --- a/src/alr/alr-utils-temp_file.adb +++ b/src/alr/alr-utils-temp_file.adb @@ -12,9 +12,7 @@ package body Alr.Utils.Temp_File is begin if Exists (This.Name) then Delete_File (This.Name); - null; end if; - exception when E : others => Alire.Utils.Finalize_Exception (E); diff --git a/testsuite/tests/exec/no-extra-line/test.py b/testsuite/tests/exec/no-extra-line/test.py new file mode 100644 index 000000000..a76c7cf9e --- /dev/null +++ b/testsuite/tests/exec/no-extra-line/test.py @@ -0,0 +1,19 @@ +""" +Check that `alr exec` does not add an extra line at the end of the output. +Fix for issue #2004. This test is more or less moot, since the bug can only be +observed when running interactively with ANSI coloring, which is disabled in +the testsuite and cannot be forced on. At least, it checks that no extra line is +added in the non-interactive case. +""" + +from drivers.alr import run_alr, init_local_crate +from drivers.asserts import assert_eq + +# Initialize a crate, enter it, and run an echo through exec. Check the output. + +init_local_crate() + +p = run_alr("exec", "--", "echo", "HELLO", quiet=False) +assert_eq("HELLO\n", p.out) # Note: only one newline at the end + +print("SUCCESS") diff --git a/testsuite/tests/exec/no-extra-line/test.yaml b/testsuite/tests/exec/no-extra-line/test.yaml new file mode 100644 index 000000000..fa855459b --- /dev/null +++ b/testsuite/tests/exec/no-extra-line/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + compiler_only_index: {}