Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty strings were ignored #195

Merged
merged 3 commits into from
Dec 17, 2023
Merged

Conversation

Ryooooooga
Copy link
Contributor

@Ryooooooga Ryooooooga commented Nov 30, 2023

deno eval '' should succeed and output nothing.

await $`deno eval ''`;
// error: the following required arguments were not provided:
// ...

test

#!/bin/sh
# ./test.sh: Output the number of arguments ($#) and the value of each argument
printf '$#: %d\n' $#

for i in "$@"; do
  printf '  [%s]\n' "$i"
done
import $ from "https://deno.land/x/dax/mod.ts";
import $2 from "./mod.ts"; // this branch

Deno.env.set("X", "yyy      zzzz");

console.log("master:");
await $`./test.sh`.printCommand();
await $`./test.sh A 'B' "C"`.printCommand();
await $`./test.sh A "" ""`.printCommand();
await $`./test.sh $X"$X"'$X'`.printCommand();

console.log("\n\nPR:");
await $2`./test.sh`.printCommand();
await $2`./test.sh A 'B' "C"`.printCommand();
await $2`./test.sh A '' ""`.printCommand();
await $2`./test.sh $X"$X"'$X'`.printCommand();

console.log("\n\nBash:");

await runBash(`./test.sh`);
await runBash(`./test.sh A 'B' "C"`);
await runBash(`./test.sh A '' ""`);
await runBash(`./test.sh $X"$X"'$X'`);

async function runBash(cmd: string) {
  console.log(`> bash -c ${cmd}`);
  await new Deno.Command("bash", {
    args: ["-c", cmd],
    stdout: "inherit",
  }).spawn();
}
> ./test.sh
$#: 0
> ./test.sh A 'B' "C"
$#: 3
  [A]
  [B]
  [C]
> ./test.sh A "" ""
$#: 1
  [A]
> ./test.sh $X"$X"'$X'
$#: 2
  [yyy]
  [zzzzyyy zzzz$X]


PR:
> ./test.sh
$#: 0
> ./test.sh A 'B' "C"
$#: 3
  [A]
  [B]
  [C]
> ./test.sh A '' ""
$#: 3
  [A]
  []
  []
> ./test.sh $X"$X"'$X'
$#: 2
  [yyy]
  [zzzzyyy      zzzz$X]


Bash:
> bash -c ./test.sh
> bash -c ./test.sh A 'B' "C"
$#: 0
> bash -c ./test.sh A '' ""
$#: 3
  [A]
  [B]
  [C]
> bash -c ./test.sh $X"$X"'$X'
$#: 3
  [A]
  []
  []
$#: 2
  [yyy]
  [zzzzyyy      zzzz$X]

@@ -1245,8 +1245,11 @@ Deno.test("copy test", async () => {
"cp: target 'non-existent' is not a directory\n",
);

assertEquals(await getStdErr($`cp "" ""`), "cp: missing file operand\n");
assertStringIncludes(await getStdErr($`cp ${file1} ""`), "cp: missing destination file operand after");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cp file1 "" should try to create a file "" and fail, but it is considered a copy to cwd.
This is another issue.

$ cp file1 ""
cp: cannot create regular file '': No such file or directory

@dsherret dsherret changed the title fix empty strings being ignored fix: empty strings were ignored Dec 17, 2023
Copy link
Owner

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the PRs!

Deno.test("should support empty quoted string", async () => {
const output = await $`echo '' test ''`.text();
assertEquals(output, " test ");
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a basic test. In the future, I recommend doing this because it helps prevent against regressions.

@dsherret dsherret merged commit c987b89 into dsherret:main Dec 17, 2023
3 checks passed
@Ryooooooga Ryooooooga deleted the fix/args branch December 18, 2023 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants