Skip to content

[FEATURE]: extract line from file_regex and regex status check #1761

@shahzebsiddiqui

Description

@shahzebsiddiqui

Please describe your feature

We should be able add support for extracting line when applying regular expression check in status check for file_regex and regex.

So take for example the following example, we have introduced linenum that can be applied to extract a line from file or stream. In this example we will extract the 1st and last line of count.txt which should evaluate to the correct expression which is 1, and 10 from the file. The regex check will pass for first test the expression 'Line\s\d+' should match any of the lines regardless of the line number we pick

In the next test, we should get a failure since we will extracting last line of stream which is ******** therefore the expression should fail.

buildspecs:
  extract_line_from_file_and_regex:
    type: script
    executor: generic.local.bash
    description: "Extract line from file and stream and apply regular expression"
    run: |
      for i in {1..10}; do      
        echo "Line $i"
      done
    status:
      file_regex:
        - file: count.txt
          exp: '^1$'
          linenum: 0
        - file: count.txt
          exp: '^10$'
          linenum: -1
      regex:
        stream: stdout
        exp: 'Line\s\d+'
  extract_line_failure:
    type: script
    executor: generic.local.bash
    description: Regular expression failure due to incorrect line
    run: |
      for i in {1..10}; do
        echo "Line $i" >> count.txt
        echo "Line $i"
      done
      echo "*********"
    status:
      regex:
        stream: stdout
        exp: 'Line\s\d+'
        linenum: -1

I ran this example without adding linenum to give you idea the 2nd test output should have ****** at end

(buildtest) ☁  general_tests [devel] ⚡  buildtest it query -o extract_line_failure 
──────────────────────────────────────────────────────────────────────────────────── extract_line_failure/5e3dbd09-4fb2-4d23-b628-b508108e04c6 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Regular expression failure due to incorrect line
State: PASS
Returncode: 0
Runtime: 0.012094 sec
Starttime: 2024/04/26 12:45:15
Endtime: 2024/04/26 12:45:15
Command: bash extract_line_failure_build.sh
Test Script: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.sh
Build Script: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure_build.sh
Output File: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.out
Error File: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.err
Log File: /Users/siddiq90/Documents/buildtest/var/logs/buildtest_t68eidr1.log
───────────────────────────────────────────── Output File: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.out ──────────────────────────────────────────────
Line 1                                                                                                                                                                                                                             
Line 2                                                                                                                                                                                                                             
Line 3                                                                                                                                                                                                                             
Line 4                                                                                                                                                                                                                             
Line 5                                                                                                                                                                                                                             
Line 6                                                                                                                                                                                                                             
Line 7                                                                                                                                                                                                                             
Line 8                                                                                                                                                                                                                             
Line 9                                                                                                                                                                                                                             
Line 10                                                                                                                                                                                                                            
*********                                 

TODO

Suggest potential solution

No response

Additional Information

No response

Post question in Slack

  • I agree that I posted my question in slack before creating this issue

Is there an existing issue

  • I confirm there is no existing issue for this issue

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions