nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: unexpectedjs/unexpected
Pull request #543 (2018-12-26 17:55:49)

<object> to satisfy <object>: Do not dereference properties that aren't needed for the assertion
Fixes regression from #482


Patch:
diff --git a/lib/assertions.js b/lib/assertions.js
index de6136b4..b3d419e1 100644
--- a/lib/assertions.js
+++ b/lib/assertions.js
@@ -1827,26 +1827,23 @@ module.exports = expect => {
       const promiseByKey = {};
       let forceExhaustivelyComparison = false;
       uniqueKeys.forEach((key, index) => {
-        const subjectKey = subjectType.hasKey(subject, key)
-          ? subjectType.valueForKey(subject, key)
-          : undefined;
+        const subjectHasKey = subjectType.hasKey(subject, key);
         const valueKey = valueType.hasKey(value, key, true)
           ? valueType.valueForKey(value, key)
           : undefined;
         const valueKeyType = expect.findTypeOf(valueKey);
-        const isDefinedSubjectKey = typeof subjectKey !== 'undefined';
-        const isDefinedValueKey = typeof valueKey !== 'undefined';
         if (expect.flags.exhaustively) {
-          if (valueKeyType.is('expect.it') && !isDefinedSubjectKey) {
+          if (valueKeyType.is('expect.it') && !subjectHasKey) {
             // ensure value only expect.it key is marked missing
             forceExhaustivelyComparison = true;
           }
-        } else {
-          if (isDefinedSubjectKey && !isDefinedValueKey) {
-            // ignore subject only keys unless we are being exhaustive
-            return;
-          }
+        } else if (subjectHasKey && typeof valueKey === 'undefined') {
+          // ignore subject only keys unless we are being exhaustive
+          return;
         }
+        const subjectKey = subjectHasKey
+          ? subjectType.valueForKey(subject, key)
+          : undefined;
 
         promiseByKey[key] = expect.promise(() => {
           if (valueKeyType.is('expect.it')) {


Test patch:
diff --git a/test/assertions/to-satisfy.spec.js b/test/assertions/to-satisfy.spec.js
index a4b7bc02..a5425024 100644
--- a/test/assertions/to-satisfy.spec.js
+++ b/test/assertions/to-satisfy.spec.js
@@ -2564,4 +2564,17 @@ describe('to satisfy assertion', () => {
       });
     });
   });
+
+  it('should not dereference properties that are not being asserted on', function() {
+    expect(
+      {
+        get ohNo() {
+          throw new Error('argh');
+        },
+        foo: 123
+      },
+      'to satisfy',
+      { foo: 123 }
+    );
+  });
 });
Repository: unexpectedjs/unexpected
Pull request #547 (2018-12-28 16:07:24)

Fix unexpected messy missing diff
When running unexpected-messy against v11 we get a missing diff. This PR should fix the problem.


Patch:
diff --git a/lib/assertions.js b/lib/assertions.js
index b3d419e1..b519f19d 100644
--- a/lib/assertions.js
+++ b/lib/assertions.js
@@ -1357,7 +1357,7 @@ module.exports = expect => {
   );
 
   expect.addAssertion(
-    '<any|Error|object> to [exhaustively] satisfy <expect.it>',
+    '<any|Error> to [exhaustively] satisfy <expect.it>',
     (expect, subject, value) => expect.promise(() => value(subject))
   );
 
@@ -1410,7 +1410,7 @@ module.exports = expect => {
   );
 
   expect.addAssertion(
-    '<any> to [exhaustively] satisfy [assertion] <expect.it>',
+    '<any|object> to [exhaustively] satisfy [assertion] <expect.it>',
     (expect, subject, value) =>
       expect.withError(
         () => value(subject, expect.context),


Test patch:
diff --git a/test/assertions/to-satisfy.spec.js b/test/assertions/to-satisfy.spec.js
index 8d4ef606..7f239ce5 100644
--- a/test/assertions/to-satisfy.spec.js
+++ b/test/assertions/to-satisfy.spec.js
@@ -961,6 +961,67 @@ describe('to satisfy assertion', () => {
     });
   });
 
+  describe('with an expect.it and customised types', () => {
+    function Foo(thing) {
+      this.thing = thing;
+    }
+    const clonedExpect = expect.clone();
+
+    clonedExpect.addType({
+      name: 'Foo',
+      identify(obj) {
+        return obj instanceof Foo;
+      },
+      inspect(obj, depth, output) {
+        output.text('Foo', 'green');
+      }
+    });
+
+    clonedExpect.addAssertion(
+      '<Foo> to satisfy <object>',
+      (expect, subject, value) => {
+        return expect.withError(
+          () => expect(subject.thing, 'to satisfy', value.thing),
+          err => {
+            expect.fail({
+              diff: (output, diff, inspect, equal) => {
+                output.text('-- custom diff --', 'yellow').nl(2);
+
+                const thingDiff = err.getDiff(output);
+                if (thingDiff) {
+                  output.append(thingDiff);
+                }
+
+                return output;
+              }
+            });
+          }
+        );
+      }
+    );
+
+    it('should handle async diffs with nested parts', () =>
+      expect(
+        () =>
+          clonedExpect(new Foo({ foo: 123 }), 'to satisfy', {
+            thing: expect.it('when delayed a little bit', 'to equal', {
+              foo: 787
+            })
+          }),
+        'to error',
+        'expected Foo\n' +
+          "to satisfy { thing: expect.it('when delayed a little bit', 'to equal', { foo: 787 }) }\n" +
+          '\n' +
+          '-- custom diff --\n' +
+          '\n' +
+          'expected { foo: 123 } when delayed a little bit to equal { foo: 787 }\n' +
+          '\n' +
+          '{\n' +
+          '  foo: 123 // should equal 787\n' +
+          '}'
+      ));
+  });
+
   it('should support diffs in the error report', () => {
     expect(
       function() {
Repository: unexpectedjs/unexpected
Pull request #559 (2019-01-02 22:42:52)

Don't let changes to expect.output.preferredWidth propagate into existing clones
I'm not yet sure that this fully explains the issues we've seen in plugin test suites.


Patch:
diff --git a/lib/Unexpected.js b/lib/Unexpected.js
index bef52f2d..ef0d6b03 100644
--- a/lib/Unexpected.js
+++ b/lib/Unexpected.js
@@ -1637,6 +1637,8 @@ Unexpected.prototype.clone = function() {
   });
   // Install the hooks:
   unexpected._expect = this._expect;
+  // Make sure that changes to the parent's preferredWidth doesn't propagate:
+  unexpected.output.preferredWidth = this.output.preferredWidth;
   return makeExpectFunction(unexpected);
 };
 


Test patch:
diff --git a/test/preferredWidth.spec.js b/test/preferredWidth.spec.js
new file mode 100644
index 00000000..26d1add9
--- /dev/null
+++ b/test/preferredWidth.spec.js
@@ -0,0 +1,81 @@
+/*global unexpected*/
+
+describe('expect.output.preferredWidth', () => {
+  var expect = unexpected.clone();
+  beforeEach(() => {
+    expect = expect.clone();
+    expect.output.preferredWidth = 9999;
+  });
+
+  describe('and a clone', () => {
+    var clonedExpect;
+    beforeEach(() => {
+      clonedExpect = expect.clone();
+    });
+
+    it('should propagate into the clone', () => {
+      expect(clonedExpect.output.preferredWidth, 'to be', 9999);
+    });
+
+    describe('when the value is changed in the clone', () => {
+      beforeEach(() => {
+        clonedExpect.output.preferredWidth = 7777;
+      });
+
+      it('should not affect the original', () => {
+        expect(expect.output.preferredWidth, 'to be', 9999);
+      });
+    });
+
+    describe('when the value is changed in the original after the clone was made', () => {
+      beforeEach(() => {
+        expect.output.preferredWidth = 5555;
+      });
+
+      it('should not affect the clone', () => {
+        expect(clonedExpect.output.preferredWidth, 'to be', 9999);
+      });
+    });
+  });
+
+  describe('and a child', () => {
+    var childExpect;
+    beforeEach(() => {
+      childExpect = expect.child();
+    });
+
+    it('should propagate into the child', () => {
+      expect(childExpect.output.preferredWidth, 'to be', 9999);
+    });
+
+    describe('when the value is changed in the child', () => {
+      beforeEach(() => {
+        childExpect.output.preferredWidth = 7777;
+      });
+
+      it('should not affect the original', () => {
+        expect(expect.output.preferredWidth, 'to be', 9999);
+      });
+
+      describe('and then in the parent', () => {
+        beforeEach(() => {
+          expect.output.preferredWidth = 4444;
+        });
+
+        it('should not affect the child', () => {
+          expect(childExpect.output.preferredWidth, 'to be', 7777);
+        });
+      });
+    });
+
+    describe('when the value is changed in the original after the child was made', () => {
+      beforeEach(() => {
+        expect.output.preferredWidth = 5555;
+      });
+
+      it('should propagate the change to the child', () => {
+        expect(childExpect.output.preferredWidth, 'to be', 5555);
+      });
+    });
+  });
+});
Repository: unexpectedjs/unexpected
Pull request #595 (2019-02-24 22:13:38)

to throw an: fulfill the promise with the error
See #594


Patch:
diff --git a/documentation/assertions/function/to-throw-a.md b/documentation/assertions/function/to-throw-a.md
index ff6509d8..88b739ec 100644
--- a/documentation/assertions/function/to-throw-a.md
+++ b/documentation/assertions/function/to-throw-a.md
@@ -36,6 +36,17 @@ expected function willNotThrow() {} to throw a RangeError
     did not throw
 ```
 
+The thrown error is provided as the fulfillment value of
+the returned promise, so you can do further assertions like this:
+
+<!-- unexpected-markdown async:true -->
+
+```js
+return expect(willThrow, 'to throw a', SyntaxError).then(function(err) {
+  expect(err, 'to have message', /\bmessage/);
+});
+```
+
 To test functions that require input wrap the function invocation in an anonymous function:
 
 ```js
diff --git a/documentation/assertions/function/to-throw.md b/documentation/assertions/function/to-throw.md
index 3d43b9a0..324fc530 100644
--- a/documentation/assertions/function/to-throw.md
+++ b/documentation/assertions/function/to-throw.md
@@ -166,6 +166,17 @@ not to throw
   threw: Error('threw anyway')
 ```
 
+The thrown error is provided as the fulfillment value of
+the returned promise, so you can do further assertions like this:
+
+<!-- unexpected-markdown async:true -->
+
+```js
+return expect(somethingThatThrows, 'to throw').then(function(err) {
+  expect(err, 'to have message', /\bmessage/);
+});
+```
+
 To test functions that require input wrap the function invocation in an anonymous function:
 
 ```js
diff --git a/lib/assertions.js b/lib/assertions.js
index 3d8a21c1..e5c03821 100644
--- a/lib/assertions.js
+++ b/lib/assertions.js
@@ -1037,7 +1037,7 @@ module.exports = expect => {
         };
       }
       expect.errorMode = 'nested';
-      return expect(subject, 'to throw').then(error => {
+      return expect(subject, 'to throw').tap(error => {
         expect(error, 'to be a', value);
       });
     }


Test patch:
diff --git a/test/assertions/to-throw-a.spec.js b/test/assertions/to-throw-a.spec.js
index a0309cd1..4b34bd79 100644
--- a/test/assertions/to-throw-a.spec.js
+++ b/test/assertions/to-throw-a.spec.js
@@ -40,6 +40,17 @@ describe('to throw a/an assertion', () => {
     );
   });
 
+  it('fulfills its promise with the error that was thrown', () => {
+    const err = new SyntaxError('foo');
+    expect(
+      function() {
+        throw err;
+      },
+      'to throw a',
+      SyntaxError
+    ).then(fulfilmentValue => expect(fulfilmentValue, 'to be', err));
+  });
+
   it('fails if the function throws an instance of a different constructor', () => {
     expect(
       function() {
Repository: unexpectedjs/unexpected
Pull request #610 (2019-03-16 10:22:28)

exportStyle: Pass on the allowRedefinition parameter to the parent's addStyle
Previously you'd get this error when trying to export a style from a child expect that collides with one that's already defined in the parent:

```
Error: "fancyQuotes" style is already defined, set 3rd arg (allowRedefinition) to true to define it anyway
```

But the advice didn't work because `exportStyle` did not pass it on.


Patch:
diff --git a/lib/createTopLevelExpect.js b/lib/createTopLevelExpect.js
index 8d3d74a4..a6e0b6ab 100644
--- a/lib/createTopLevelExpect.js
+++ b/lib/createTopLevelExpect.js
@@ -1593,11 +1593,15 @@ expectPrototype.child = function() {
     parent.addType(type, childExpect);
     return this;
   };
-  childExpect.exportStyle = function(name, handler) {
-    parent.addStyle(name, function(...args) {
-      const childOutput = childExpect.createOutput(this.format);
-      this.append(handler.call(childOutput, ...args) || childOutput);
-    });
+  childExpect.exportStyle = function(name, handler, allowRedefinition) {
+    parent.addStyle(
+      name,
+      function(...args) {
+        const childOutput = childExpect.createOutput(this.format);
+        this.append(handler.call(childOutput, ...args) || childOutput);
+      },
+      allowRedefinition
+    );
     return this;
   };
   return childExpect;


Test patch:
diff --git a/test/api/exportStyle.spec.js b/test/api/exportStyle.spec.js
index 4b5683f7..a354048f 100644
--- a/test/api/exportStyle.spec.js
+++ b/test/api/exportStyle.spec.js
@@ -64,4 +64,30 @@ describe('styleType', () => {
       '>>yadda<<'
     );
   });
+
+  it('passes on the allowRedefinition parameter', function() {
+    parentExpect.addStyle('fancyQuotes', function(text) {
+      this.text('"')
+        .text(text)
+        .text('"');
+    });
+    childExpect.exportStyle(
+      'fancyQuotes',
+      function(text) {
+        this.text('>>')
+          .text(text)
+          .text('<<');
+      },
+      true
+    );
+
+    expect(
+      parentExpect
+        .createOutput()
+        .fancyQuotes('yadda')
+        .toString(),
+      'to equal',
+      '>>yadda<<'
+    );
+  });
 });
Repository: unexpectedjs/unexpected
Pull request #621 (2019-04-20 22:38:01)

Disallow .hook() on a frozen expect
:fishing_pole_and_fish: :snowflake:


Patch:
diff --git a/lib/createTopLevelExpect.js b/lib/createTopLevelExpect.js
index 8d3d74a4..d9eae9e3 100644
--- a/lib/createTopLevelExpect.js
+++ b/lib/createTopLevelExpect.js
@@ -1630,6 +1630,11 @@ expectPrototype.createOutput = function(format) {
 
 expectPrototype.hook = function(fn) {
   this._assertTopLevelExpect();
+  if (this._frozen) {
+    throw new Error(
+      'Cannot install a hook into a frozen instance, please run .clone() first'
+    );
+  }
   this._expect = fn(this._expect.bind(this));
 };
 


Test patch:
diff --git a/test/api/freeze.spec.js b/test/api/freeze.spec.js
index 2bcb4d3e..f11d7ead 100644
--- a/test/api/freeze.spec.js
+++ b/test/api/freeze.spec.js
@@ -28,6 +28,23 @@ describe('freeze', () => {
     );
   });
 
+  it('makes .hook(...) throw', () => {
+    expect(
+      function() {
+        expect
+          .clone()
+          .freeze()
+          .hook(function(next) {
+            return function(context, args) {
+              return next(context, args);
+            };
+          });
+      },
+      'to throw',
+      'Cannot install a hook into a frozen instance, please run .clone() first'
+    );
+  });
+
   it('should allow cloning, and the clone should not be frozen', () => {
     expect
       .clone()
Repository: unexpectedjs/unexpected
Pull request #627 (2019-05-01 19:53:51)

Always omit at least two lines in string diffs
I found "... 1 line omitted ..." a bit annoying because it takes up as much space as the line that got omitted :)


Patch:
diff --git a/lib/styles.js b/lib/styles.js
index b131b1b5..a45bdb84 100644
--- a/lib/styles.js
+++ b/lib/styles.js
@@ -203,9 +203,7 @@ module.exports = expect => {
   });
 
   expect.addStyle('diffLinesOmitted', function(lineCount) {
-    this.jsComment(
-      `... ${lineCount} line${lineCount === 1 ? '' : 's'} omitted ...`
-    );
+    this.jsComment(`... ${lineCount} lines omitted ...`);
   });
 
   expect.addStyle('removedHighlight', function(content) {
@@ -471,7 +469,7 @@ module.exports = expect => {
           );
         } else {
           const horizon = 3;
-          if (index === diffLines.length - 1 && part.count > horizon) {
+          if (index === diffLines.length - 1 && part.count > horizon + 1) {
             this.stringDiffFragment(
               ' ',
               value
@@ -482,7 +480,7 @@ module.exports = expect => {
             )
               .nl()
               .diffLinesOmitted(part.count - horizon);
-          } else if (index === 0 && part.count > horizon) {
+          } else if (index === 0 && part.count > horizon + 1) {
             this.diffLinesOmitted(part.count - horizon)
               .nl()
               .stringDiffFragment(
@@ -493,7 +491,7 @@ module.exports = expect => {
                   .join('\n'),
                 'text'
               );
-          } else if (part.count > 2 * horizon) {
+          } else if (part.count > 2 * horizon + 1) {
             this.stringDiffFragment(
               ' ',
               value


Test patch:
diff --git a/test/assertions/to-be.spec.js b/test/assertions/to-be.spec.js
index 8f9ae12d..de616063 100644
--- a/test/assertions/to-be.spec.js
+++ b/test/assertions/to-be.spec.js
@@ -146,6 +146,39 @@ describe('to be assertion', () => {
       );
     });
 
+    // These would be annoying to look at
+    it('does not produce ... 1 lines omitted ... lines', () => {
+      expect(
+        () =>
+          expect(
+            'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\n',
+            'to equal',
+            'a\nb\nc\nd\nf\ng\nh\ni\nj\nk\nl\nn\no\np\nq\n'
+          ),
+        'to throw',
+        "expected 'a\\nb\\nc\\nd\\ne\\nf\\ng\\nh\\ni\\nj\\nk\\nl\\nm\\nn\\no\\np\\nq\\n'\n" +
+          "to equal 'a\\nb\\nc\\nd\\nf\\ng\\nh\\ni\\nj\\nk\\nl\\nn\\no\\np\\nq\\n'\n" +
+          '\n' +
+          ' a\n' +
+          ' b\n' +
+          ' c\n' +
+          ' d\n' +
+          '-e\n' +
+          ' f\n' +
+          ' g\n' +
+          ' h\n' +
+          ' i\n' +
+          ' j\n' +
+          ' k\n' +
+          ' l\n' +
+          '-m\n' +
+          ' n\n' +
+          ' o\n' +
+          ' p\n' +
+          ' q\n'
+      );
+    });
+
     it('truncates lines in large in the start and end', () => {
       const paragraphs = `\
         Bacon ipsum dolor amet tri-tip kielbasa kevin spare ribs. Sirloin chuck jerky
Repository: unexpectedjs/unexpected
Pull request #628 (2019-05-01 21:34:31)

Fix highlighting of diffing trailing whitespace in the last line
Fixes bug introduced in #625

Before:
![before](https://user-images.githubusercontent.com/373545/57044029-87f72e00-6c69-11e9-9ee5-f29be8b21cc4.png)

After:
![after](https://user-images.githubusercontent.com/373545/57044031-87f72e00-6c69-11e9-94ea-e4de45084553.png)



Patch:
diff --git a/lib/styles.js b/lib/styles.js
index b131b1b5..5e4e64e0 100644
--- a/lib/styles.js
+++ b/lib/styles.js
@@ -459,7 +459,7 @@ module.exports = expect => {
             value,
             'diffAddedLine',
             options.markUpSpecialCharacters,
-            endsWithNewline
+            endsWithNewline || index === diffLines.length - 1
           );
         } else if (part.removed) {
           this.stringDiffFragment(
@@ -467,7 +467,7 @@ module.exports = expect => {
             value,
             'diffRemovedLine',
             options.markUpSpecialCharacters,
-            endsWithNewline
+            endsWithNewline || index === diffLines.length - 1
           );
         } else {
           const horizon = 3;


Test patch:
diff --git a/test/styles/stringDiff.spec.js b/test/styles/stringDiff.spec.js
index 83a64e18..e45d8b7b 100644
--- a/test/styles/stringDiff.spec.js
+++ b/test/styles/stringDiff.spec.js
@@ -142,6 +142,22 @@ describe('stringDiff', () => {
       );
     });
 
+    it('highlights missing trailing whitespace in the last line without newline after', () => {
+      expect(
+        expect.createOutput('ansi').stringDiff('', ' '),
+        'to equal',
+        expect.createOutput('ansi').diffAddedHighlight(' ')
+      );
+    });
+
+    it('highlights extraneous trailing whitespace in the last line without newline after', () => {
+      expect(
+        expect.createOutput('ansi').stringDiff(' ', ''),
+        'to equal',
+        expect.createOutput('ansi').diffRemovedHighlight(' ')
+      );
+    });
+
     it('does not highlight "trailing" whitespace in removed and added chunks within a line', () => {
       expect(
         expect
Repository: unexpectedjs/unexpected
Pull request #642 (2019-06-12 20:38:48)

Fix context reset for child expect's

sunesimonsen: I don't know what is up with Githubs interface, but this is a the correct commit order:

<img width="1242" alt="Screenshot 2019-06-12 at 23 30 55" src="https://user-images.githubusercontent.com/90802/59387709-2519ac00-8d6a-11e9-98b2-4b1709bab534.png">

sunesimonsen: Aha https://help.github.com/en/articles/why-are-my-commits-in-the-wrong-order

Patch:
diff --git a/lib/Context.js b/lib/Context.js
index 5726afe3..640e57c1 100644
--- a/lib/Context.js
+++ b/lib/Context.js
@@ -1,6 +1,5 @@
 class Context {
-  constructor(expect) {
-    this.expect = expect;
+  constructor() {
     this.level = 0;
   }
 
diff --git a/lib/createTopLevelExpect.js b/lib/createTopLevelExpect.js
index cbe349cd..e0e80f2c 100644
--- a/lib/createTopLevelExpect.js
+++ b/lib/createTopLevelExpect.js
@@ -178,7 +178,7 @@ function createExpectIt(expect, expectations, forwardedFlags) {
     context =
       context && typeof context === 'object' && context instanceof Context
         ? context
-        : new Context(expect);
+        : new Context();
 
     if (
       orGroups.length === 1 &&
@@ -1442,7 +1442,11 @@ expectPrototype._executeExpect = function(
   }
 
   if (assertionRule.expect && assertionRule.expect !== this._topLevelExpect) {
-    return assertionRule.expect(subject, testDescriptionString, ...args);
+    return assertionRule.expect._expect(context, [
+      subject,
+      testDescriptionString,
+      ...args
+    ]);
   }
 
   const wrappedExpect = this._createWrappedExpect(
@@ -1661,7 +1665,7 @@ expectPrototype.fail = function(...args) {
   // Cannot use this !== this._topLevelExpect due to https://github.com/unexpectedjs/unexpected/issues/631
   if (this.flags) {
     this._callInNestedContext(() => {
-      this.context.expect.fail(...args);
+      this._topLevelExpect._fail(...args);
     });
   } else {
     try {
@@ -1916,7 +1920,7 @@ function createTopLevelExpect({
   installedPlugins = []
 } = {}) {
   const expect = function(...args) {
-    return expect._expect(new Context(expect), args);
+    return expect._expect(new Context(), args);
   };
   utils.setPrototypeOfOrExtend(expect, expectPrototype);
 


Test patch:
diff --git a/test/api/exportAssertion.spec.js b/test/api/exportAssertion.spec.js
index a45975b1..358c237a 100644
--- a/test/api/exportAssertion.spec.js
+++ b/test/api/exportAssertion.spec.js
@@ -287,4 +287,29 @@ describe('exportAssertion', () => {
       );
     });
   });
+
+  it('uses the current context', () => {
+    childExpect.exportAssertion(
+      '<string> to have context value <any>',
+      function(expect, field, value) {
+        expect(expect.context[field], 'to equal', value);
+      }
+    );
+
+    parentExpect.addAssertion(
+      '<any> when set on the context as <string> <assertion>',
+      function(expect, value, field) {
+        expect.context[field] = value;
+        expect.shift(field);
+      }
+    );
+
+    parentExpect(
+      42,
+      'when set on the context as',
+      'magicNumber',
+      'to have context value',
+      42
+    );
+  });
 });