Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

panc: Deprecated should always return boolean true #271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions panc-docs/source/standard-functions/standard-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,14 @@ deprecated -- print deprecation warning to console
Synopsis
--------

string **deprecated** (long *level*, string *msg*)
boolean **deprecated** (long *level*, string *msg*)

Description
-----------

This function will print the given string to the console (on stderr) and
return the message as the result, if ``level`` is less than or equal to
the deprecation level given as a compiler option. If the message is not
printed, the function returns undef. The value of ``level`` must be
non-negative.
This function will print the given string to the console (on stderr), if
``level`` is less than or equal to the deprecation level given as a compiler
option and always returns true. The value of ``level`` must be non-negative.

.. _dict:

Expand Down
11 changes: 5 additions & 6 deletions panc/src/main/java/org/quattor/pan/dml/functions/Deprecated.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ Centre National de la Recherche Scientifique (CNRS).
import org.quattor.pan.dml.data.Element;
import org.quattor.pan.dml.data.LongProperty;
import org.quattor.pan.dml.data.StringProperty;
import org.quattor.pan.dml.data.Undef;
import org.quattor.pan.dml.data.BooleanProperty;
import org.quattor.pan.exceptions.EvaluationException;
import org.quattor.pan.exceptions.SyntaxException;
import org.quattor.pan.ttemplate.Context;
import org.quattor.pan.ttemplate.SourceRange;

/**
* Prints the argument to the standard error stream if the given level is less
* than or equal to the deprecation level option. The returned value is the
* message, if the message is printed; undef, otherwise.
*
* than or equal to the deprecation level option. The returned value is always true.
*
* @author loomis
*
*
*/
// FIXME: This method should really only accept one argument now.
final public class Deprecated extends BuiltInFunction {
Expand Down Expand Up @@ -91,7 +90,7 @@ public Element execute(Context context) {

assert (ops.length == 2);

Element value = Undef.VALUE;
Element value = BooleanProperty.TRUE;

if (!context.isCompileTimeContext()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Centre National de la Recherche Scientifique (CNRS).

import org.junit.Test;
import org.quattor.pan.dml.Operation;
import org.quattor.pan.dml.data.BooleanProperty;
import org.quattor.pan.dml.data.LongProperty;
import org.quattor.pan.dml.data.StringProperty;
import org.quattor.pan.exceptions.SyntaxException;
Expand All @@ -42,6 +43,14 @@ public void testInstanceType() throws SyntaxException {
assertTrue(op instanceof Deprecated);
}

@Test
public void testReturnTrue() throws SyntaxException {
Operation r1 = runDml(
Deprecated.getInstance(null, LongProperty.getInstance(1L), StringProperty.getInstance("message"))
);
assertTrue(r1 == BooleanProperty.TRUE);
}

@Test(expected = SyntaxException.class)
public void testInvalidFirstArgument() throws SyntaxException {
Deprecated.getInstance(null, StringProperty.getInstance("message"),
Expand Down
Loading