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

It appears that Issue #646 is not fixed by commit 2fc72bf #729

Closed
JLPLabs opened this issue Jan 1, 2024 · 0 comments
Closed

It appears that Issue #646 is not fixed by commit 2fc72bf #729

JLPLabs opened this issue Jan 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JLPLabs
Copy link
Contributor

JLPLabs commented Jan 1, 2024

Issue #646 pertains to hashbang on line 1 surviving through to the generated Lua script.

This note shows:

  1. Demonstration of problem
  2. How the spec ("spec/cli/gen_spec.lua") could be updated to catch the error

Demonstration of Problem

Note insertion of blank line above hashbang in the generated Lua file

tl> cat -n test_1print.tl
     1	#!/usr/bin/env lua
     2	print("hello world")
     3	

tl> tl gen --keep-hashbang test_1print.tl
Wrote: test_1print.lua

tl> cat -n test_1print.lua               
     1
     2	#!/usr/bin/env lua
     3	print("hello world")

Current and Updated Spec

Current spec compares lines, it doesn't seem to catch a blank line being inserted

CURRENT -- This test "passes"

   it("preserves hashbang with --keep-hashbang", function()
      local name = util.write_tmp_file(finally, script_with_hashbang)
      local pd = io.popen(util.tl_cmd("gen", "--keep-hashbang", name), "r")
      local output = pd:read("*a")
      util.assert_popen_close(0, pd:close())
      local lua_name = tl_to_lua(name)
      assert.match("Wrote: " .. lua_name, output, 1, true)
      util.assert_line_by_line(script_with_hashbang, util.read_file(lua_name))
   end)

change the assert and now the error (inserted blank line) is detected

PROPOSED -- This test "fails" (as it should, given the hashbang isn't on line 1)

   it("*equality test* to confirm preserves hashbang with --keep-hashbang", function()
      local name = util.write_tmp_file(finally, script_with_hashbang)
      local pd = io.popen(util.tl_cmd("gen", "--keep-hashbang", name), "r")
      local output = pd:read("*a")
      util.assert_popen_close(0, pd:close())
      local lua_name = tl_to_lua(name)
      assert.match("Wrote: " .. lua_name, output, 1, true)
      assert.equal(script_with_hashbang, util.read_file(lua_name))
   end)

The proposed spec generates this error

tl gen *equality test* to confirm preserves hashbang with --keep-hashbang
spec/cli/gen_spec.lua:262: Expected objects to be equal.
Passed in:
(string) '
#!/usr/bin/env lua
print("hello world")
'
Expected:
(string) '#!/usr/bin/env lua
print("hello world")
'
@hishamhm hishamhm added the bug Something isn't working label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants