stdlib: Implement realpath() function.
authorRichard W.M. Jones <rjones@redhat.com>
Sun, 12 Jan 2020 20:02:57 +0000 (20:02 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sun, 12 Jan 2020 20:04:29 +0000 (20:04 +0000)
docs/Goalfile.pod
stdlib/prelude.gl
tests/10-function-realpath.gl [new file with mode: 0644]
tests/10-function-realpath.sh [new file with mode: 0755]

index 9917fd0..40ca73a 100644 (file)
@@ -48,6 +48,15 @@ Concatenate C<list1> and C<list2>.  It's not usually necessary to use
 this function since goals automatically flattens lists within lists
 into simple lists in many cases.
 
 this function since goals automatically flattens lists within lists
 into simple lists in many cases.
 
+=head3 realpath (filename)
+
+For example:
+
+ realpath ("./tests") ⇒ "/home/user/tests"
+
+Run the L<realpath(1)> command to return the resolved absolute path of
+the C<filename> parameter.
+
 =head3 sort (list)
 
 For example:
 =head3 sort (list)
 
 For example:
index de2a422..183338d 100644 (file)
@@ -90,6 +90,11 @@ pure function extension (name) returning string = @{
     echo "${name##*.}"
 }
 
     echo "${name##*.}"
 }
 
+# Real path.
+function realpath (filename) returning string = @{
+    realpath -- %filename
+}
+
 # Expand a wildcard into a list of filenames.
 #
 # This function is probably not "pure" since it depends on the
 # Expand a wildcard into a list of filenames.
 #
 # This function is probably not "pure" since it depends on the
diff --git a/tests/10-function-realpath.gl b/tests/10-function-realpath.gl
new file mode 100644 (file)
index 0000000..61aba54
--- /dev/null
@@ -0,0 +1,23 @@
+# Goals test.
+# Copyright (C) 2020 Richard W.M. Jones
+# Copyright (C) 2020 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test the realpath function.
+
+let path = realpath (".")
+
+goal all = { echo %path }
diff --git a/tests/10-function-realpath.sh b/tests/10-function-realpath.sh
new file mode 100755 (executable)
index 0000000..f03b517
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+# Goals test.
+# Copyright (C) 2020 Richard W.M. Jones
+# Copyright (C) 2020 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+goals -f 10-function-realpath.gl > 10-function-realpath.out
+test "$(cat 10-function-realpath.out)" = "$PWD"
+rm 10-function-realpath.out