#!/bin/bash
# This test assumes gcc and gcc-c++ are already installed.
set -exo pipefail
# Verify that /usr/bin/cc points to gcc.
ls -l /etc/alternatives/cc | grep gcc
# Verify that /usr/bin/c++ points to g++
ls -l /etc/alternatives/c++ | grep g++
# Run cc and verify it invokes gcc
/usr/bin/cc --version | grep 'cc (GCC)'
# Run c++ and verify it invokes g++
/usr/bin/c++ --version | grep 'c++ (GCC)'
# Compile a C program
/usr/bin/cc -o hello-c hello.c
./hello-c | grep 'Hello world'
# Compile a C++ program
/usr/bin/c++ -o hello-cpp hello.cpp
./hello-cpp | grep 'Hello world'
# Uninstall gcc and verify that cc and c++ are gone.
dnf remove -y gcc gcc-c++
test ! -h /etc/alternatives/cc
test ! -h /etc/alternatives/c++
test ! -e /usr/bin/cc
test ! -e /usr/bin/c++