Skip to content

Commit

Permalink
Double slash comments are silently breaking script execution #388
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Jul 4, 2023
1 parent 3904e0e commit 84e9a61
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/aem/core/src/main/antlr/ApmLang.g4
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ grammar ApmLang;
*/

apm
: command+
: command+ EOF
;

name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package com.cognifide.apm.core.grammar
import com.cognifide.apm.api.scripts.Script
import com.cognifide.apm.api.services.ScriptFinder
import com.cognifide.apm.api.status.Status
import com.cognifide.apm.core.grammar.argument.Arguments
import com.cognifide.apm.core.progress.ProgressImpl
import org.apache.commons.io.IOUtils
import org.apache.sling.api.resource.ResourceResolver
Expand Down Expand Up @@ -104,7 +103,7 @@ class ScriptRunnerTest extends Specification {
def result = scriptExecutor.execute(script, new ProgressImpl(""))

then:
result.entries.size() == 3
result.entries.size() == 7
result.entries[0].messages ==
["Import from script /import-define.apm. Notice, only DEFINE actions were processed!",
"Imported variable: var=\"imported val\""]
Expand All @@ -116,6 +115,11 @@ class ScriptRunnerTest extends Specification {
result.entries[2].messages ==
["Import from script /import-deep-define.apm. Notice, only DEFINE actions were processed!",
"Imported variable: deepNamespace={deeperNamespace: {var: \"imported val\"}, deepVar: \"imported val + imported val\"}"]

result.entries[3].command == "Executing command SHOW \"imported val\""
result.entries[4].command == "Executing command SHOW \"imported val\""
result.entries[5].command == "Executing command SHOW \"imported val\""
result.entries[6].command == "Executing command SHOW \"imported val + imported val\""
}

def "run script filename.apm"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ class ParsedScriptTest extends Specification {
error == output

where:
file | output
"/invalid1.apm" | ["Invalid line [20:7]: DEFINE \$ nana", "Invalid sequence: \$"]
"/invalid2.apm" | ["Invalid line [20:7]: DEFINE / nana"]
"/invalid3.apm" | ["Invalid line [20:0]: // define variable", "Invalid sequence: //"]
"/invalid4.apm" | ["Invalid line [20:0]: / define variable"]
"/invalid5.apm" | ["Invalid line [20:0]: /x define variable", "Invalid sequence: /x"]
"/invalid6.apm" | ["Invalid line [20:0]: /* define variable", "Invalid sequence: /*"]
"/invalid7.apm" | ["Invalid line [20:0]: <!-- define variable"]
file | output
"/invalid/invalid1.apm" | ["Invalid line [20:7]: DEFINE \$ nana", "Invalid sequence: \$"]
"/invalid/invalid2.apm" | ["Invalid line [20:7]: DEFINE / nana"]
"/invalid/invalid3.apm" | ["Invalid line [20:0]: // define variable", "Invalid sequence: //"]
"/invalid/invalid4.apm" | ["Invalid line [20:0]: / define variable"]
"/invalid/invalid5.apm" | ["Invalid line [20:0]: /x define variable", "Invalid sequence: /x"]
"/invalid/invalid6.apm" | ["Invalid line [20:0]: /* define variable", "Invalid sequence: /*"]
"/invalid/invalid7.apm" | ["Invalid line [20:0]: <!-- define variable"]
"/invalid/invalid8.apm" | ["Invalid line [21:0]: // define variable", "Invalid sequence: //"]
"/invalid/invalid9.apm" | ["Invalid line [21:0]: / define variable"]
"/invalid/invalid10.apm" | ["Invalid line [21:0]: /x define variable", "Invalid sequence: /x"]
"/invalid/invalid11.apm" | ["Invalid line [21:0]: /* define variable", "Invalid sequence: /*"]
"/invalid/invalid12.apm" | ["Invalid line [21:0]: <!-- define variable"]
"/invalid/invalid13.apm" | ["Invalid line [20:0]: \"define variable\"", "Invalid sequence: \"define variable\""]
"/invalid/invalid14.apm" | ["Invalid line [21:0]: \"define variable\"", "Invalid sequence: \"define variable\""]
}
}
2 changes: 1 addition & 1 deletion app/aem/core/src/test/resources/import-and-run2.apm
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
# =========================LICENSE_END==================================
RUN '/includes/cycle-a.apm'

RUN '/includes/run-a.apm' AS namespace
RUN '/includes/run-a.apm'
7 changes: 6 additions & 1 deletion app/aem/core/src/test/resources/import.apm
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
# =========================LICENSE_END==================================
IMPORT /import-define.apm
IMPORT '/import-define.apm' AS namespace
IMPORT '/import-deep-define.apm' AS deepNamespace
IMPORT '/import-deep-define.apm' AS deepNamespace

SHOW $var
SHOW $namespace.var
SHOW $deepNamespace.deeperNamespace.var
SHOW $deepNamespace.deepVar
21 changes: 21 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid10.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

DEFINE nana "nana"
/x define variable
22 changes: 22 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid11.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

DEFINE nana "nana"
/* define variable
*/
22 changes: 22 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid12.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

DEFINE nana "nana"
<!-- define variable
-->
21 changes: 21 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid13.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

"define variable"
DEFINE nana "nana"
21 changes: 21 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid14.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

DEFINE nana "nana"
"define variable"
21 changes: 21 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid8.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

DEFINE nana "nana"
// define variable
21 changes: 21 additions & 0 deletions app/aem/core/src/test/resources/invalid/invalid9.apm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ========================LICENSE_START=================================
# AEM Permission Management
# %%
# Copyright (C) 2013 Wunderman Thompson Technology
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========================LICENSE_END==================================

DEFINE nana "nana"
/ define variable

0 comments on commit 84e9a61

Please sign in to comment.