Skip to content

cli: Add Validate command#361

Closed
aequitas wants to merge 5 commits intopurpleidea:masterfrom
aequitas:lint
Closed

cli: Add Validate command#361
aequitas wants to merge 5 commits intopurpleidea:masterfrom
aequitas:lint

Conversation

@aequitas
Copy link
Contributor

@aequitas aequitas commented Feb 26, 2018

#313

Todo:

  • docs
  • lint on deploy
  • test-lint-mcl test for examples

@aequitas aequitas force-pushed the lint branch 3 times, most recently from bbfabcf to 03ad9d1 Compare February 26, 2018 19:20
Copy link
Owner

@purpleidea purpleidea left a comment

Choose a reason for hiding this comment

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

Patch is looking good, however we need to call this something different than lint. Ideas?

failures=''

# lint .mcl examples
for file in $(find examples/lang/ -maxdepth 3 -type f -name '*.mcl'); do
Copy link
Owner

Choose a reason for hiding this comment

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

I'm really pleased you added a test for this, because I was thinking we needed this :)

@@ -0,0 +1,4 @@
# this file generates a syntax error, used in lib/cli_test.go
file "/tmp/mgmt" {
content => "test" # missing trailing comma
Copy link
Owner

Choose a reason for hiding this comment

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

tab for indentation, unless your point was that spaces should be a compile error ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be a good point :)

lib/cli_test.go Outdated
"github.com/urfave/cli"
)

func TestLintPass(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

what's going on in these two?

lang/lang.go Outdated
}

func (obj *Lang) Lint() error {
_, err := LexParse(obj.Input)
Copy link
Owner

Choose a reason for hiding this comment

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

This is actually the part which needs the most work... You probably want all of these to run:

https://github.com/purpleidea/mgmt/blob/master/docs/language-guide.md#stages

With the exception of actually running the function engine. All of those are needed to ascertain if a compile is successful.

@aequitas aequitas force-pushed the lint branch 2 times, most recently from 4b219a4 to 6f7dbd2 Compare February 26, 2018 20:55
@purpleidea purpleidea changed the title cli: Add lint command cli: Add Validate command Feb 26, 2018
@aequitas aequitas force-pushed the lint branch 6 times, most recently from faf5def to 71436a1 Compare February 27, 2018 13:11
Copy link
Owner

@purpleidea purpleidea left a comment

Choose a reason for hiding this comment

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

Most of this patch is good. I've got to step back and think about if the refactor into compile is what we want. Please fixup these issues and I'll think about the refactor.

Thanks!

@@ -0,0 +1,3 @@
# this file generates a scope error, used in lib/cli_test.go
Copy link
Owner

Choose a reason for hiding this comment

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

all "bad" things should be in test/ dir, not easy to find in examples/

in fact, the real tests should have nothing to do with examples/

I have a test case that tests examples just to make sure the examples we submit aren't actually junk, but the real testing should happen in test/

@@ -0,0 +1,4 @@
# this file generates a syntax error, used in lib/cli_test.go
Copy link
Owner

Choose a reason for hiding this comment

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

let's not refer to a specific file like this

@@ -0,0 +1,2 @@
# this file generates a unification error, used in lib/cli_test.go
Copy link
Owner

Choose a reason for hiding this comment

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

okay, however why not write this as a test in unification_test.go instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i want to test validate is able to detect a unification error, not that this file generates a unification error per se.

lang/gapi.go Outdated
}

// validate syntax before deploying
filecontent, err := ioutil.ReadFile(s)
Copy link
Owner

Choose a reason for hiding this comment

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

fileContent

lang/gapi.go Outdated
obj := &Lang{
Input: code,
Logf: func(format string, v ...interface{}) {
log.Printf(Name+": funcs: "+format, v...)
Copy link
Owner

Choose a reason for hiding this comment

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

what? why funcs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably a copy paste error i overlooked

// read through this local path, and store it in our file system
// since our deploy should work anywhere in the cluster, let the
// engine ensure that this file system is replicated everywhere!

Copy link
Owner

Choose a reason for hiding this comment

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

why is this line missing?
if there's a reason, okay, but it sends the message you don't review your diffs before submitting.
the goal should be for me to see your patch and say "perfect, merged" :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

must have slipped past

Copy link
Owner

Choose a reason for hiding this comment

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

no worries

lib/cli_test.go Outdated
files := []struct {
path string
}{
{"../examples/lang/bad/syntaxerror.mcl"},
Copy link
Owner

Choose a reason for hiding this comment

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

no ../ paths please and no references to examples/ in our code.
we need to think of a better way to get the code in. i'd actually prefer to just inline it for now. see:

https://github.com/purpleidea/mgmt/blob/master/lang/lexparse_test.go#L93

@aequitas aequitas force-pushed the lint branch 9 times, most recently from 7294036 to 2f67d1b Compare March 5, 2018 16:19
@aequitas
Copy link
Contributor Author

#368 (comment)

@aequitas aequitas closed this Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants