SamirTalwar / smoke

Runs tests against anything, using command-line arguments, STDIN, STDOUT and STDERR.
MIT License
88 stars 10 forks source link

about regex test case #109

Closed ivan19871002 closed 1 year ago

ivan19871002 commented 1 year ago

example I add daytime into os-release , like OS-VERSION=GITHUB-20230320-AAAA

my test cast

command:
  - sh

tests:
  - name: bsp version check
    command: |
      day=20230320
      cat /etc/os-release
    stdout:
      matches: 
        OS-VERSION=.*${day}.*

it is failed:smoke: ParseError {errError = ICUError U_REGEX_BAD_INTERVAL, errLine = Just 1, errOffset = Just 20}

if change ${day} to 20230320, it is success

command:
  - sh

tests:
  - name: bsp version check
    command: |
      day=20230320
      cat /etc/os-release
    stdout:
      matches: 
        OS-VERSION=.*20230320.*

so , If i want use parm for day , How should I write stdout?

SamirTalwar commented 1 year ago

It looks like you want to interpolate an environment variable that's set in your command into the YAML.

I'm afraid this isn't really possible; YAML isn't designed to do string interpolation easily (there are lots of edge cases), and Smoke doesn't have enough information to do this.

I suggest you build your smoke.yaml file from a template, and then run it. You could use string interpolation or a transformation language such as jq (perhaps via yq) to construct it first.

ivan19871002 commented 1 year ago

It looks like you want to interpolate an environment variable that's set in your command into the YAML.

I'm afraid this isn't really possible; YAML isn't designed to do string interpolation easily (there are lots of edge cases), and Smoke doesn't have enough information to do this.

I suggest you build your smoke.yaml file from a template, and then run it. You could use string interpolation or a transformation language such as jq (perhaps via yq) to construct it first.

tks, I use python modify smoke.yaml before test. It is work.

ivan19871002 commented 1 year ago
def replace_string_in_file(filename, old_str, new_str):
    with open(filename, 'r') as file:
        file_content = file.read()

    file_content = file_content.replace(old_str, new_str)

    with open(filename, 'w') as file:
        file.write(file_content)