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

_zunit_run_testfile:21: tests: assignment to invalid subscript range #100

Closed
pawamoy opened this issue May 13, 2019 · 4 comments
Closed

Comments

@pawamoy
Copy link
Contributor

pawamoy commented May 13, 2019

$ cat tests/test_cover.zunit
#!/usr/bin/env zunit

@test "cover prints help with -h option" {
  run cover -h
  assert $state equals 0
}
    

$ zunit tests/test_cover.zunit
Launching ZUnit                                            ZUnit: 0.8.2
ZSH:   zsh 5.3.1 (x86_64-debian-linux-gnu)                 
_zunit_run_testfile:21: tests: assignment to invalid subscript range
@pawamoy
Copy link
Contributor Author

pawamoy commented May 13, 2019

OK, seems to be because I used double-quotes for my test name instead of single-quotes. Is it mentioned in the README/docs?

I'm actually giving a try at zunit by migrating bats tests :)

@molovo
Copy link
Member

molovo commented May 13, 2019

@pawamoy it's not - I wasn't aware it was an issue. It should accept both so I'll look into a fix

@MichaelAquilina
Copy link
Contributor

Can confirm this also occurs on my own tests when swapping ' for "

@pawamoy
Copy link
Contributor Author

pawamoy commented Apr 13, 2020

I think it's caused by this line:

testname="${line[(( ${line[(i)[\']]}+1 )),(( ${line[(I)[\']]}-1 ))]}"

You are using \' to get the test name boundaries. When using double-quotes instead, the test name is empty, and then later at

tests[${#test_names}]=''

...you are trying to assign a value at index 0, when arrays start at 1 in Zsh, hence the error we get

_zunit_run_testfile:21: tests: assignment to invalid subscript range

Maybe a simple fix would be to use

-testname="${line[(( ${line[(i)[\']]}+1 )),(( ${line[(I)[\']]}-1 ))]}" 
+testname="${line[(( ${line[(i)[\'\"]]}+1 )),(( ${line[(I)[\'\"]]}-1 ))]}" 

instead? Not sure about the escaping, or if [] really are regex characters ranges.

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 a pull request may close this issue.

3 participants