A sweat chloride test is used to diagnose cystic fibrosis, a disease that causes mucus to build up in the lungs and other organs.