DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
hiclab
hiclab

Posted on

Check messages in Problems view with RCPTT

When testing with RCPTT, it is common to check messages in Problems view to make sure that only the expected ones are shown.

The Problems view in Eclipse groups messages by severity but we can also group them by type or other criteria or not at all. In our case, we will use the default grouping that is by severity.

Alt Text

Find a message in Problems view

The following procedure basically constructs a path based on a regular expression in this format $severity "s \(.*item(s?)\)/" $message and checks whether an item with this path exists.

/* Checks whether the Problems view contains a message with a given severity. */
proc problemExists [val message] [val severity Error] {
    with [get-view Problems | get-tree] {
        if [itemExists [concat $severity "s \\(.*item(s?)\\)/" $message]] {
            bool true
        }
    } | length | gt 0
}

Notice that itemExists is a procedure we created in the past to check whether an item is visible in a tree structure. For more details, see this post.
The argument Severity is optional since it has Error as default value. This is because in most cases, we look for error messages.

Here are some examples of verifications done in Problems view.

// check an error message
problemExists -message "The local variable company may not have been initialized" | verify-true

// error message not expected
problemExists -message "The value of the field Company.name is not used" | verify-false

// check a warning message
problemExists -message "The value of the field Company.name is not used" -severity Warning | verify-true

Count messages in Problems view

Another interesting verification we can do is to count the number of messages that appear in Problems view for a particular severity.

Similarly to the procedure described above, we first check if an item exists for the provided severity then we go through its child items (messages) to count them. If we want to count the occurrences of a concrete message then we have to iterate over all those messages and consider only matches.

/* 
Counts how many times a message with a given severity appears in the Problems view.
If no message is specified then it counts all messages with the specified severity. 
*/
proc problemCount [val severity] [val message ""] {
    let [val severityNode [concat $severity "s \\(.*item(s?)\\)"]] {
        with [get-view Problems | get-tree] {
            if [itemExists $severityNode] {
                with [get-item $severityNode] {
                    expand
                    if [$message | eq ""] {
                        // count all messages of the specified severity
                        get-items | length
                    } -else {
                        // count only the specified message
                        get-items | foreach [val item] {
                            if [$item | get-property text -raw | eq $message] {
                                // message found
                                emit true
                            }
                        } | length
                    }
                }
            } -else {
                // no item is found for the specified severity
                int 0
            }
        }
    }
}

Expand ECL command is necessary to make sure that child items of severity items are visible, otherwise get-items returns nothing.

Here are some usage examples:

problemCount Error | eq 1 | verify-true

problemCount Warning | eq 2 | verify-true

problemCount Warning "The value of the field Company.name is not used" | eq 1 | verify-true

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠