Many routers, Pi-hole installs and small servers run dnsmasq for DNS and DHCP. Restarting it with a broken config can leave a network without DNS for a while, and a dry check avoids that.
The flag is in the dnsmasq man page:
dnsmasq --test
It reads and syntax-checks the configuration files, exits with code 0 if everything is fine or a non-zero code otherwise, and does not start dnsmasq. Without other options it checks the default configuration, normally /etc/dnsmasq.conf. To check a different file, add --conf-file, or -C for short:
dnsmasq --test --conf-file=/etc/dnsmasq.d/my-test.conf
The man page says that option stops dnsmasq from reading the default configuration file, so you test exactly that file and nothing else. When your real setup spreads over a directory of snippets, pass the same options your service uses.
A restart that depends on the result looks like this:
dnsmasq --test && sudo systemctl restart dnsmasq
If the check fails, the command exits with a non-zero code and the restart never happens.
The caveat is the word syntax. A rule that is valid but wrong, like an address= line that points a name at the wrong IP, passes happily. Software that bundles its own dnsmasq may call it by another binary name or start it with extra options, so make sure you test the same program and the same options as the one that runs.
Further reading: dnsmasq manual