diff --git a/CHANGES.markdown b/CHANGES.markdown
--- a/CHANGES.markdown
+++ b/CHANGES.markdown
@@ -1,3 +1,6 @@
+Changes in 0.22.8
+  - cabal-doctest: Fix handling of options with optional arguments
+
 Changes in 0.22.7
   - cabal-doctest: Accept component
   - cabal-doctest: Get rid of separate `cabal build` step
diff --git a/doctest.cabal b/doctest.cabal
--- a/doctest.cabal
+++ b/doctest.cabal
@@ -5,7 +5,7 @@
 -- see: https://github.com/sol/hpack
 
 name:           doctest
-version:        0.22.7
+version:        0.22.8
 synopsis:       Test interactive Haskell examples
 description:    `doctest` is a tool that checks [examples](https://www.haskell.org/haddock/doc/html/ch03s08.html#idm140354810775744)
                 and [properties](https://www.haskell.org/haddock/doc/html/ch03s08.html#idm140354810771856)
diff --git a/src/Cabal/Options.hs b/src/Cabal/Options.hs
--- a/src/Cabal/Options.hs
+++ b/src/Cabal/Options.hs
@@ -71,4 +71,8 @@
 
 discardReplOptions :: [String] -> [String]
 discardReplOptions args = case getOpt Permute options args of
-  (xs, _, _) -> concat [name : maybeToList value | Argument name value <- xs, Set.notMember name replOnlyOptions]
+  (xs, _, _) -> [renderArgument name value | Argument name value <- xs, Set.notMember name replOnlyOptions]
+  where
+    renderArgument name = \ case
+      Nothing -> name
+      Just value -> name <> "=" <> value
diff --git a/test/Cabal/OptionsSpec.hs b/test/Cabal/OptionsSpec.hs
--- a/test/Cabal/OptionsSpec.hs
+++ b/test/Cabal/OptionsSpec.hs
@@ -57,4 +57,4 @@
         , "--repl-options", "foo"
         , "--repl-options=foo"
         , "--allow-newer"
-        ] `shouldBe` ["--with-compiler", "ghc-9.10", "--disable-optimization", "--allow-newer"]
+        ] `shouldBe` ["--with-compiler=ghc-9.10", "--disable-optimization", "--allow-newer"]
