Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added Procedure Tests #2576

Merged
merged 6 commits into from
Jun 26, 2019
Merged

Conversation

BeksOmega
Copy link
Collaborator

@BeksOmega BeksOmega commented Jun 13, 2019

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

I think this should cover closing #860

Proposed Changes

Adds tests to start covering procedure behavior.

[EDIT: I also removed the old jsunit tests because they were inaccurate]

Reason for Changes

Procedures were dangerously undocumented.

Test Coverage

Adds tests for:

  • isNameUsed
  • rename
  • getCallers
  • getDefinition
  • Mutator / Arguments

Additional Information

Some things are broken, those tests are skipped. Here are two particularly bad ones I took gifs of:
Procedures_WhitespaceThenText
Procedures_EmptyNew

But most things should be pretty easy to fix.

I'll create issues for the skipped tests once I get confirmation that all of them are bad.

Additional Additional Information

I'd also like to create XML tests for the procedures, would you like that in this file, the xml file, a new file, or none file (if you don't think it's useful)?

@@ -164,7 +164,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this Blockly.Block
*/
decompose: function(workspace) {
var containerBlock = workspace.newBlock('procedures_mutatorcontainer');
/*var containerBlock = workspace.newBlock('procedures_mutatorcontainer');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this because the initSvg() calls were breaking my tests.

@@ -205,11 +234,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
var varName = paramBlock.getFieldValue('NAME');
this.arguments_.push(varName);
var variable = this.workspace.getVariable(varName, '');
if (variable != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added by #2186 to fix #1958, but fields are happy now so this is unnecessary. Tests cover this change.

@BeksOmega
Copy link
Collaborator Author

Set the broken mocha test to skip because I'm not sure why the dropdownCreate function looks like this:

options.push([Blockly.Msg['RENAME_VARIABLE'], Blockly.RENAME_VARIABLE_ID]);
  if (Blockly.Msg['DELETE_VARIABLE']) {
    options.push(
        [
          Blockly.Msg['DELETE_VARIABLE'].replace('%1', name),
          Blockly.DELETE_VARIABLE_ID
        ]
    );
  }

It broke because I had to add the msg files to the mocha and it started adding the delete option.

@alschmiedt
Copy link
Contributor

XML tests would be great. If you are planning on writing more than 2 or 3 tests then I would create a xml_procedures_test.js file, otherwise I would just put them into the xml_test.js file

* @license
* Blockly Tests
*
* Copyright 2017 Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Change to 2019

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -6,6 +6,16 @@

<link href="https://unpkg.com/mocha@5.2.0/mocha.css" rel="stylesheet" />
<script src="../../blockly_uncompressed.js"></script>
<script src="../../msg/messages.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include all these blocks? If we don't could you remove the ones that you are not using?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

context.defType = types[0];
context.callType = types[1];

context.defBlock = new Blockly.Block(this.workspace, types[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use context.defType instead of types[0]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


context.defBlock = new Blockly.Block(this.workspace, types[0]);
context.defBlock.setFieldValue(startName, 'NAME');
context.callBlock = new Blockly.Block(this.workspace, types[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

var callers = Blockly.Procedures.getCallers('name1', this.workspace);
chai.assert.equal(callers.length, 1);
chai.assert.equal(callers[0], this.callBlock);
}, 'name');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you ad a bit more detailed comment here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote down a procedure for how to replicate it, does it sound good to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that is great thanks!

clearVariables.call(this);
}, 'name');
});
test('Set Arg Empty (#1958)', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add #1958 in a comment instead of in the test case name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -185,7 +185,36 @@ Blockly.Blocks['procedures_defnoreturn'] = {
paramBlock.oldLocation = i;
connection.connect(paramBlock.previousConnection);
connection = paramBlock.nextConnection;
}*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -68,7 +68,7 @@ suite('Variable Fields', function() {
sinon.restore();
});

test('Dropdown contains variables', function() {
test.skip('Dropdown contains variables', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the move here is to update the test to expect 5 instead of 4 since having the delete option is expected behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@BeksOmega BeksOmega force-pushed the fixes/ProcedureRenaming branch from c9eabf9 to b34ca2f Compare June 25, 2019 22:08
@BeksOmega
Copy link
Collaborator Author

XML tests would be great. If you are planning on writing more than 2 or 3 tests then I would create a xml_procedures_test.js file, otherwise I would just put them into the xml_test.js file

Noted, probably won't get to it today but I have put it in my task management system.

Copy link
Contributor

@alschmiedt alschmiedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@alschmiedt alschmiedt merged commit 83c5d27 into google:develop Jun 26, 2019
@BeksOmega
Copy link
Collaborator Author

@alschmiedt Did you want me to create issues for those skipped tests?

@alschmiedt
Copy link
Contributor

Yup that would be great : ) I looked over them and they all seem like valid issues.

@BeksOmega BeksOmega deleted the fixes/ProcedureRenaming branch July 1, 2019 21:45
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants