diff --git a/pkgs/tools/text/sgrep/default.nix b/pkgs/tools/text/sgrep/default.nix
index d7dc04645c33..f3d23d166696 100644
--- a/pkgs/tools/text/sgrep/default.nix
+++ b/pkgs/tools/text/sgrep/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, lib, m4, makeWrapper }:
+{ stdenv, sgrep, fetchurl, runCommand, lib, m4, makeWrapper }:
stdenv.mkDerivation rec {
pname = "sgrep";
@@ -16,6 +16,14 @@ stdenv.mkDerivation rec {
--prefix PATH : ${lib.makeBinPath [ m4 ]}
'';
+ passthru.tests.smokeTest = runCommand "test-sgrep" { } ''
+ expr='"" __ ""'
+ data="12"
+ ${sgrep}/bin/sgrep "$expr" <<<$data >$out
+ read result <$out
+ [[ $result = 1 ]]
+ '';
+
meta = with lib; {
homepage = "https://www.cs.helsinki.fi/u/jjaakkol/sgrep.html";
description = "A grep for structured text formats such as XML";