News for hackers. Stuff that matters.
Re:Counting Bugs in Windows Calculator by lifthrasiir on Wednesday March 13, 2019 @01:17AM (#19375937)
Yet another example of "suspicious" test code which intention is very clear:

    TEST_METHOD(TestSwitchAndReselectCurrentlyActiveValueDoesNothing)
    {
      // *snip*
      vm.Value2Active = true;
      // Establish base condition
      VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount);
      VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount);
      VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount);
      vm.Value2Active = true;
      VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount);
      VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount);
      VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount);
    }
> [...] The analyzer has detected two identical code fragments executing immediately one after the other. It looks like this code was written using the copy-paste technique and the programmer forgot to modify the copies.

Here Value2Active is a C++/CX property rigged to a PropertyChanged event [1] with a macro:

    public ref class UnitConverterViewModel sealed: public Windows::UI::Xaml::Data::INotifyPropertyChanged
    {
        // other members omitted
        OBSERVABLE_OBJECT();
        OBSERVABLE_PROPERTY_RW(bool, Value2Active);
    };
Can you be sure that this actually does not have a side effect? I bet not. Indeed, the intention of the original test is clear: a property, once set ("Switch") to a particular value, should not update other states even when set ("Reselect") to that same value---as it will really trigger a side effect! This idempotency guarantee is an important interface contract worth testing, no matter what a linter and clueless blog author says.

[1] https://github.com/Microsoft/calculator/blob/master/docs/App...

Re:Counting Bugs in Windows Calculator by amedvednikov on Wednesday March 13, 2019 @01:39AM (#19376040)
Wow, I can imagine how much fun it is to debug such properties.